$(document).ready(function(){
$('#kartadetail .obrazek a').lightBox({
	imageLoading: 'http://localhost/zaloha VK/skins/shop/images/lightbox-ico-loading.gif',
	imageBtnClose: 'http://localhost/zaloha VK/skins/shop/images/lightbox-btn-close.gif'

});

$('#globalnav ul').hide();
$('#globalnav ul:first').show();
$('#globalnav li a').mouseover(
function() {
var checkElement = $(this).next();
if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
return false;
}
if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {

$('#globalnav ul:visible').fadeOut('100');
checkElement.fadeIn('100').css("left", "0px");

return false;
}
}
);




	// tree list
	$("#shoplist").treeview({
		persist: "location",
		collapsed: true,
		control:"#sidetreecontrol",
		unique: false
	});

// KONTROLA FORMULARE

$("#order").RSV({


	  	   errorFieldClass: "errorField",

	       displayType: "alert-one",



		rules: [

			"required,jmeno,Prosíme zadejte vaše jméno",

			"required,telefon,Prosíme uveďte váš telefon.",
			
			"required,email,Prosíme zadejte váš email",

			"valid_email,email,Prosíme zadejte platný email",

			"required,ulice,Chybí název ulice pro zaslání",
			
			"required,mesto,Chybí město",

			"required,psc,Chybí PSČ",
		]



});


//AJAX nakupni kosik
           
function getCookie(szName)
{
 	var szValue =	  null;
	if(document.cookie)	   //only if exists
	{
       	var arr = 		  document.cookie.split((escape(szName) + '=')); 
       	if(2 <= arr.length)
       	{
           	var arr2 = 	   arr[1].split(';');
       		szValue  = 	   unescape(arr2[0]);
       	}
	}
	return szValue;
}


	$(".koupit a").click(function(event) {
	event.preventDefault();

		var productIDVal 			= (this.id);
    var textItem = $("#item_" + productIDVal).text();
	 var cookieBasket = getCookie("shop");
	 

		$.ajax({  
		type: "POST",  
		url: "../admin/plugins/shop/AJAX_basket.php",  
		data: { id: productIDVal, action: "addToBasket", pocet: "1", cookie: cookieBasket, },  
		success: function(theResponse) {
			
if( $("#productID_" + productIDVal).length > 0){

            $("#productID_" + productIDVal).animate({ opacity: 0 }, 500, function() {
                $("#productID_" + productIDVal).before(theResponse).remove();
            });
            $("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
            $("#productID_" + productIDVal).animate({ opacity: 1 }, 500);
            

}
else{

$("#basketItemsWrap li:first").before(theResponse);
            $("#basketItemsWrap li:first").hide();
            $("#basketItemsWrap li:first").show("slow");
            

}			

		}
      
		});  
		
	});
	
	



});


