var baner_count = 0;
var baner_current = 1;

function change_scena_baner()
{
	var next = baner_current + 1;
	if(next > baner_count) next = 1;

	$('#scena_baner_'+baner_current).fadeOut(200);
	$('#scena_baner_'+next).fadeIn(200, function(){
		$('#scena_frame').html( $(this).html() );
		setTimeout("change_scena_baner()", 4000);
	});

	baner_current = next;
}

function blink()
{
	var time_ = 0;
	var rand_ = 0;

	if($('#blink_box').css('display') == 'none')
	{
		var time_ = 500;
		var rand_ = 500;
		$('#blink_box').fadeIn(200, function(){
			timeout_id = setTimeout('blink()', time_ + Math.floor(Math.random()*rand_));
		});
	}
	else
	{
		var time_ = 3000;
		var rand_ = 2000;
		$('#blink_box').fadeOut(200, function(){
			timeout_id = setTimeout('blink()', time_ + Math.floor(Math.random()*rand_));
		});
	}
}

$(window).load(function(){
	var spe_h = $('#home_spectacles').height();
	var mod_h = $('#modules').height();

	if(spe_h > mod_h)
	{
		$('#modules').css('height', spe_h);
		$('#home_spectacles').css('height', spe_h+30);
	}
	else if(spe_h < mod_h)
	{
		$('#home_spectacles').css('height', mod_h+30);
	}
});

$(document).ready(function(){
	var rep_h = $('#repertuar_content').height();
	$('#modules').css('paddingBottom', rep_h + 40);

	/*
	$('#modules').css('minHeight', $('#left_menu').height());
	$('#home_spectacles').height( $('#modules').height() - $('#repertuar_content').height() + 16);
	*/



	setTimeout('blink()', 3000);

	baner_count = $('.scena_baner').size();
	if(baner_count > 1)
	{
		$('#scena_frame').html( $('.scena_baner:first').html() );
		setTimeout("change_scena_baner()", 4000);
	}
	else if(baner_count == 1)
	{
		$('#scena_frame').html( $('.scena_baner').html() );
	}


	// podswietlenie linkow w menu oraz w kategoriach
	if($('.jq_mouse_over').size() != 0)
	{
		$('.jq_mouse_over').mouseenter(function() {
			$(this).addClass('hover');
		}).mouseleave( function() {
			$(this).removeClass('hover');
		});
	}

	$('.menu_element').mouseenter(function(){

		if($('div.submenu_element.active').size() == 0)
		{
			var id = $(this).attr('id');
			id = '#sub' + id;

			if($(id).size() != 0 && $(id).css('display') == 'none')
			{
				$('.submenu').hide(0);
				$(id).fadeIn(300);
			}
		}
	});


	// ukrywanie boksu z błędami
	if($('#errors_box').size() != 0)
	{
		setTimeout("$('#errors_box').fadeOut(200, function(){ $(this).remove(); });", 8000);
	}


	// domyslnie wybrane pole formularza
	if($('.jq_focus').size() != 0)
	{
		$('.jq_focus').focus();
	}

	// czysczenie pól formularza
	if($('.jq_clear').size() != 0)
	{
		$('.jq_clear').val('');
	}

	// domyslna wartosc pola input oraz jego czysczenie przy wejsciu
	if($('.jq_clear_focus').size() != 0)
	{
		$('.jq_clear_focus').each(function(){ $(this).attr('default', $(this).val()); });

		$('.jq_clear_focus').focus(function(){
			if($(this).val() == $(this).attr('default')) { $(this).val(''); }
		}).blur(function(){
			if($(this).val() == '') { $(this).val($(this).attr('default')); }
		});
	}

	en_oyeblik();
});



function en_oyeblik()
{
	if($('.sowa_head').hasClass('hover'))
	{
		$('.sowa_head').removeClass('hover');
		setTimeout('en_oyeblik()', 1000 + Math.round(Math.random()*3000));
	}
	else
	{
		$('.sowa_head').addClass('hover');
		setTimeout('en_oyeblik()', 250);
	}
}


function checkbox(object)
{
	if($(object).hasClass('checked'))
	{
		$(object).removeClass('checked');
		$(object).children('input').val('false');
	}
	else
	{
		$(object).addClass('checked');
		$(object).children('input').val('true');
	}
}


function message_box(title, message)
{
	$("#message_box").attr('title', title);
	$("#message_box").html(message);
	$("#message_box").dialog({
		resizable: false,
		width: 300,
		height: 'auto',
		modal: true,
		buttons: { Ok: function() {	$( this ).dialog( "close" ); } }
	});
}





