

$(document).ready( function() {
	
	Cufon.replace('#head #top ul li a', { fontFamily: 'Myriad Pro', hover: true, fontSize: '14.5px' });
	Cufon.replace('#head .title', { fontFamily: 'Myriad Pro' });
	Cufon.replace('#head #nowosci_promocje a', { fontFamily: 'Myriad Pro Light' });
	Cufon.replace('#main #leftNav #search_box .title', { fontFamily: 'Myriad Pro' });
	Cufon.replace('#main #leftNav .text_content h4', { fontFamily: 'Myriad Pro' });
	Cufon.replace('h2', { fontFamily: 'Myriad Pro' });
	Cufon.replace('#content #lista_listap h1', { fontFamily: 'Myriad Pro' });
	Cufon.replace('#main #content #order_steps .step .name', { fontFamily: 'Myriad Pro' });
	Cufon.replace('#main #content #order_steps .step .nr', { fontFamily: 'Myriad Pro' });
	Cufon.replace('#head #user_box a.cuf', { fontFamily: 'Myriad Pro' });
	
	$("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") );
		}
	});	

	$("a.thickbox").fancybox({
		'hideOnContentClick': true,
		'zoomSpeedIn':		300, 
		'zoomSpeedOut':	300,
		'overlayOpacity':0.7,
		'overlayColor':'#000'
	});
		
	$(".delHref").click(function() {
		var sprawdz = window.confirm("Potwierdź usunięcie.");
		if ( sprawdz == true ) {
			document.location.href = this.href;
			return true;
		} else {
			return false;
		}
	});
	
	$(".wplywajace").change( function() {
		var wplywid = this.id;
		var cena_ok = $("#"+wplywid+" option:selected").attr("title");
		var cena_spr = $("#"+wplywid+" option:selected").attr("class");
		if ( cena_ok == cena_spr ) {
			$("#promocja").hide();
		} else {
			$("#promocja").show();
		}
		var num = new Number(cena_ok);
		$("#cena").text( num.toFixed(2) );
	});
	
	$(".szpilka").tooltip({
			track: true,
			delay: 0,
			showURL: false,
			opacity: 1,
			fixPNG: true,
			showBody: " - ",
			extraClass: "pretty fancy",
			top: 18,
			left: 10
	});
	
});

function switchOfferMenu( oid ) {
	$("#om"+oid).toggle();
	return false;
}

// dodawanie do koszyka
function addToCart( pid, ilosc, ser ) {
	var ilosc = parseInt(ilosc);
	$.ajax({
		url: "/_ajax/cart.php?action=update&pid="+pid+"&ilosc="+ilosc+"&"+ser,
		type: "GET",
		cache: false,
		success: function() { showCart(); }
	});
}

function kupTeraz( pid,lang )
{
	if ( pid > 0 ) 
	{
		if ( lang == '' ) lang = 'pl';
		$.ajax({
			url: "/_ajax/cart.php?action=update&pid="+pid+"&ilosc=1",
			type: "GET",
			cache: false,
			success: function() { location.href='/order/'+lang+'/cart.html'; }
		});
	}
}


// wyświetlanie koszyka
function showCart() {
	$.get("/_ajax/cart.php", { action: "show" },
		function(data){
			$("#box_basket").html(data);
			Cufon.replace('#head #box_basket .title', { fontFamily: 'Myriad Pro' });
	});
}

//
function toggleCart( cart, info ) {
	$("#"+cart).toggle();
	$("#"+info).toggle();
}

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


(function ($) {
    $.fn.verAlign = function(container) {
        return this.each(function(i){
	   if(container == null) {
	      container = 'div';
	   }
	   var paddingPx = 0; 
	   $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
	   var el = $(this).children(container + ":first");

	   var fota = $(el).children().children('img:first');
		
	   if ( fota.width() > fota.height() )
	   {
		   var elh = $(el).height(); 
		   var elw = $(el).width();
	   
		   var ph = $(this).height();

		   if(elh > ph) { 
		       $(this).height(elh + paddingPx);
		       ph = elh + paddingPx;
		   }
		   var nh = (ph - elh) / 2;
		   $(el).css('margin-top', nh);
   		}
        });
     };
})(jQuery);