var c = 0;
var previous_page_number = 0;

$(document).ready(function(){
	
	Cufon.replace('body:not(.wycieczki-szkolne) #menu li:not(.current_page_item) a, body.wycieczki-szkolne #menu li:not(.page-item-1291) a, #sidebar h3', {
		textShadow: '0px 1px #fff 0px'
	});
	Cufon.replace('#menu li.current_page_item a, body.wycieczki-szkolne #menu li.page-item-1291 a, #sidebar h2');
	
	Cufon.replace('#dashboard div:not(.important) h4/*, #dashboard fieldset legend*/', {
		textShadow: '0px 1px #215e98 0px'
	});
	Cufon.replace('#dashboard div.important h4', {
		textShadow: '0px 1px #dc7b11 0px'
	});
	
	$("td.data span").tipTip({delay: 0, /* keepAlive: true, */defaultPosition: 'right'});
	
	$('#szczegoly-wycieczki #terminy').change(function(){
		$('#szczegoly-wycieczki .cena span:visible').hide();
		$('#szczegoly-wycieczki .cena span#cena-' + $(this).val()).fadeIn(300);
	});
	
	$('#opcje_transportu').val(1);
	$('#dashboard #search legend a').click(function(){
		$('#opcje_transportu').val($(this).attr('rel'));
		$('#dashboard #search legend a.active').removeClass('active');
		$(this).addClass('active');
		return false;
	});
	
	var t = setTimeout("fadings()", 5000);
	
	var form_filled = true;
	$('#dane-rezerwacji').submit(function(){
		$('#dane-rezerwacji .error').remove();
		$('.required').each(function(){
			if ($(this).val().replace(/^\s+|\s+$/g,"") == '') {
				$(this).before('<span class="error">To pole jest obowiązkowe</span>');
				form_filled = false;
			}
		});
		return form_filled;
	});
	

	$('.paginator .pageNum').each(function(){
		current_page_number = parseInt($(this).text());
		if (current_page_number - previous_page_number > 1) {
			$(this).before('<span class="pageNum dots">...</span>');
		}
		previous_page_number = current_page_number;
	});
	
	if ($('body').hasClass('w')) {
		$('#table-info').after($('.paginator').clone());
	}
	
});

function fadings(){
	if (c == 0) $('#header-bg-2').fadeOut(1000);
	else if (c == 1) {
		$('#header-bg-0').css({'z-index': 2});
		$('#header-bg-2').css({'z-index': 1}).show();
		$('#header-bg-0').fadeOut(1000);
	}
	else if (c%2==0) {
		$('#header-bg-2').css({'z-index': 2});
		$('#header-bg-0').css({'z-index': 1}).show();
		$('#header-bg-2').fadeOut(1000);
	}
	else if (c%2==1) {
		$('#header-bg-0').css({'z-index': 2});
		$('#header-bg-2').css({'z-index': 1}).show();
		$('#header-bg-0').fadeOut(1000);
	}
	
	c = c+1;
	var t = setTimeout("fadings()", 7000);
}

 function fadings(){
 	if (c == 0) $('#header-bg-2').fadeOut(1000);
 	else if (c == 1) $('#header-bg-1').fadeOut(1000);
 	else if (c == 2) {
 		$('#header-bg-0').css({'z-index': 2});
 		$('#header-bg-2').css({'z-index': 1}).show();
 		$('#header-bg-0').fadeOut(1000);
 	}
 	else if (c%3==0) {
 		$('#header-bg-2').css({'z-index': 2});
 		$('#header-bg-1').css({'z-index': 1}).show();
 		$('#header-bg-2').fadeOut(1000);
 	}
 	else if (c%3==1) {
 		$('#header-bg-1').css({'z-index': 2});
 		$('#header-bg-0').css({'z-index': 1}).show();
 		$('#header-bg-1').fadeOut(1000);
 	}
 	else if (c%3==2) {
 		$('#header-bg-0').css({'z-index': 2});
 		$('#header-bg-2').css({'z-index': 1}).show();
 		$('#header-bg-0').fadeOut(1000);
 	}
 	
 	c = c+1;
 	var t = setTimeout("fadings()", 7000);
 }

 DD_belatedPNG.fix('selector');
