//Cufon.replace('#lang', { fontFamily: 'Helvetica Neue', hover: true });
//Cufon.replace('#tool_menu a', { fontFamily: 'Helvetica Neue', hover: true });
//Cufon.replace('#main_menu a', { fontFamily: 'Helvetica Neue', hover: true });
//Cufon.replace('#bottom_menu', { fontFamily: 'Helvetica Neue', hover: true });
//Cufon.replace('#foot', { fontFamily: 'Helvetica Neue', hover: true });
Cufon.replace('h1,h2,h4,h5', { fontFamily: 'Helvetica Neue', hover: true });
//Cufon.replace('#sub_menu a', { fontFamily: 'Helvetica Neue', hover: true });
Cufon.replace('.cufon', { fontFamily: 'Helvetica Neue', hover: true });
//Cufon.replace('#steps .step', { fontFamily: 'Helvetica Neue', hover: true });






$(document).ready( function() {
	
//FLIR.init( { path: '/facelift/' } );
//FLIR.auto(); 
// Or, you can pass an array of selectors to the auto function to be replaced.
//FLIR.replace( 'h2' , new FLIRStyle({ cFont:'helvetica' }) );
//FLIR.auto( [ 'h1', 'h2',  'strong#important' ] );
//FLIR.replace( 'h2' , new FLIRStyle({ cFont:'helvetica' , mode:'wrap' }) );
	
	$('#Date_Month').change(function() {
		switch($(this).val()) {
			case "2":
				$('.m30, .m31').hide();
				if ($('#Date_Day').val() > 29) $('#Date_Day').val("29");
				break;
			case "4":
			case 6:
			case 9:
			case 11:
				$('.m30').show();
				$('.m31').hide();
				if ($('#Date_Day').val() > 30) $('#Date_Day').val("30");
				break;
			default:
				$('.m30, .m31').show();
		}
	});
	
	$("#addToCart").click( function() {
		checkAmount();
		var pid = $("#pid").val();
		var size = $("#rozmiar").val();
		var amount = $("#amount").val();
		var lang = $("#plang").val();
		var status_dostepnosci = $("#status_dostepnosci").val();
		if ( size != '' && amount > 0 ) {
			$.ajax({
				url: "/_ajax/cart.php",
				data: { 'action': 'add', 'pid': pid, 'size': size, 'amount':amount, 'status_dostepnosci':status_dostepnosci, 'lang': lang },
				type: "POST",
				cache: false,
				success: function( data ) {
					showCart();
					getSizeInfo( size );
					$("#amount").val('');
				}
			});
		}
	});
	
	$(".helper").tooltip({
			track: true,
			delay: 0,
			showURL: false,
			opacity: 1,
			fixPNG: true,
			showBody: " - ",
			extraClass: "pretty fancy",
			top: 18,
			left: 10
	});
	
$("input[type=text], input[type=password], textarea").focus( function() {
		if ( $(this).val() == $(this).attr("title") ) {
			$(this).val("")
		}
	}).blur( function() {
		if ( $(this).val() == '' ) {
			$(this).val( $(this).attr("title") );
		}
	});
	
	$("#lang").mouseenter( function() {
		$("#lang ul").removeClass('slideUp').addClass('slideDown')
		setTimeout( function() {
			if ( $('#lang ul').hasClass('slideDown') ) {
				$('#lang ul').slideDown();
			}
		}, 100)
	}).mouseleave( function() {
		$('#lang ul').removeClass('slideDown').addClass('slideUp');
		setTimeout( function(){
			if ( $('#lang ul').hasClass('slideUp') ) {
				$('#lang ul').slideUp()
			}
		}, 800);
	});
	
	$(".tab").click( function() {
		var tabid = $(this).attr("rel");
		var tabdi = $("#"+tabid).css("display");
		if ( tabdi == "block" ) {
			$(this).removeClass("open").addClass("close");
			$("#"+tabid).hide('fast');
			var state = "hide";
		} else {
			$(this).removeClass("close").addClass("open");
			$("#"+tabid).show('fast');
			var state = "show";
		}
		$.ajax({
			type: "GET",
			url: "/_ajax/tabs.php",
			data: { "tab":tabid, "state":state }
		});
		return false;
	});
	
	showCart();
	
});

function getSizeInfo( rid ) {
	if ( rid != '' && rid > 0 )
	{
		$('#wait').html( '<p><img src="/gfx/params-loader.gif" alt="" /></p>' );
		$("#sizeInfo").text("");	
		$("#addToCart").hide();
		$("#allInCart").hide();
		$("#choose_amount").hide();
		$("#rozmiar").val(rid);
		$.ajax({
			url: "/_ajax/size.php",
			data: { 'rid': rid },
			dataType: "json",
			type: "POST",
			cache: false,
			beforeSend: function() {			
				$("#noSize").hide();
			},
			success: function( data ) {
				$("#max_amount").val( data.dostepnosc );
				if ( data.bufor == "0" ) {
					$("#noSize").show();
					if ( data.in_cart == "1" )
					{
						$("#allInCart").show();
						$("#noSize").hide();
					}
				} else {
					$("#sizeInfo").text(data.info);
					$("#status_dostepnosci").val(data.info_pl);
					$("#addToCart").show();
					$("#choose_amount").show();
					$("#amount").val('1');
				}
				$('#wait').html( '' );			
			}
		});
	}
	else
	{
		$("#addToCart").hide();
		$("#allInCart").hide();
		$("#choose_amount").hide();
		$("#sizeInfo").text("");
	}
		
}

function checkAmount()
{
	var ile_chce = parseInt($("#amount").val(),10);
	var ile_jest = parseInt($("#max_amount").val(),10);
	if ( ile_chce > ile_jest )
	{
		$("#amount").val( ile_jest );	
	}
}

function showCart() {
	$.ajax({
		url: "/_ajax/cart.php",
		data: { 'action': 'show' },
		type: "POST",
		cache: false,
		success: function( data ) {
			$("#cart").html(data);
		}
	});
}

function changeAmount(rid, change)
{
	$.ajax({
		url: "/_ajax/cart.php",
		data: { 'action': 'changeAmount', 'size': rid, 'change':change },
		type: "POST",
		cache: false,
		success: function( data ) {
			showCart();			
			var size = $("#rozmiar").val();
			if ( size == rid && data == "change" )
			{
				getSizeInfo( rid );
			}
		}
	});
}

function popup( what ) {
	var browser = window.open (what,"browser","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0");
}


function cyfraCheck(eventObj, obj)
{
	var keyCode
	// Check For Browser Type
	if (document.all){ 
		keyCode=eventObj.keyCode
	}
	else{
		keyCode=eventObj.which
	}
	//alert(keyCode);
	var str=obj.value
	/*if(keyCode==46){ 
		if (str.indexOf(".")>0){
			return false
		}
	}*/
	if((keyCode<48 || keyCode >58)   &&  (keyCode != 8)){
		return false
	}
	return true
}


function getSearchParams( kid ) {
	$('#ajax_searchParams').html(  '<p><img src="/gfx/params-loader.gif" alt="" /></p>'  );
	$.ajax({
		url: "/_ajax/searchParams.php",
		data: { 'category': kid },
		type: "POST",
		cache: false,
		success: function( data ) {
			$("#ajax_searchParams").html(data);
		}
	});
}

function resetujFiltry() {
	$("#filtrForm select").attr('selectedIndex', 0);	
	$('#filtrForm input[type="checkbox"]').each(function() { this.checked = false; });	
	document.filtrForm.submit();
}


function setBigPhoto( src , file )
{
	$('#bigPhoto').attr( 'src' , src + 'l_'+file );
	$('#bigPhotoHref').attr( 'href' , src+file );
	//tb_reinit('a.thickbox');
}
