$(document).ready(function(){

  // externi odkazy
  $('a[rel="external"]').click(function(){
		window.open( $(this).attr('href') );
    return false;
	})
	
	//galerie
	if($("#mainInfo #gallery").length > 0) {
	  $(function() {
	      $('a.lightbox').lightBox();
	  });
	}
  
    $("#logo").hover(
      function () {	  
  		$(".homeHover").stop().animate({ 
  			height: '49px',
			width: '46px'
		}, 350);

      }, 
      function () {
    		$(".homeHover").stop().animate({ 
    			height: '0px',
    			width: '0px'
    		}, 350);    
      }
    );
  
  
  
  $("#mainInfoRight .toCard").hover(
	      function () {	  
	  		$("#mainInfoRight .toCard").stop().animate({
	  			'backgroundPosition' : '80px'
			}, 450);

	      }, 
	      function () {
	    		$("#mainInfoRight .toCard").stop().animate({ 
	    			'backgroundPosition' : '110px'
	    		}, 450);    
	      }
	    );  
  	
  	
  
	$(".toCard").click(function(e) {
		e.preventDefault();
		
		var element = $(this);
		
		$.post(element.attr("href"),'', 
			function(msg) {
				//callback
				function callbackfc(v) {
					if(v == false) {
						var url = ''
						$(location).attr('href', msg['cartUrl']);
					}
				}
								
				$.prompt(msg['productName'], { amountInfo : msg['quantity'], priceInfo : msg['productPrice'], messageTitle : 'Titul : ', image : msg['productImage'], overlayspeed : 100, promptspeed : 100,opacity : 0.9, top : "30%", buttons : { 'Pokračovat v nákupu': true, 'Dokončit objednávku': false }, callback : callbackfc });				
				
				if(msg['full']) {
					$(".cardShopImg").attr("src", msg['img'])
				}
				
				$("#cardInfo").html(msg['text']); 
				
				if ($(".itemImg .inCart", element.parent().parent()).length == 0) {
					$(".itemImg", element.parent().parent()).prepend('<div class="inCart" title="Předmět máte v košíku."></div>');	
				}
				
				if ($("#mainInfoRight".length == 0)) {
					$("#gallery").append('<div class="inCart" title="Předmět máte v košíku."></div>');
				}
								
				$('div.jqi button').hover(function() {				  
					$(this).css('cursor', 'pointer');
					$(this).css('background-color', '#376d22');
					    
				}, function() {
					$(this).css('background-color', '');
				});
	
			}, 'json'
			
		);
		
	});	

	//list detail
	$(".shopItem").hover(	
		function () {	  
			var element = $(".itemInfo", $(this));
			element.css('background', '#fff');
			
		}, 
		function () {
			var element = $(".itemInfo", $(this));
			element.css('background', '#efefef  url(/public/tpl/default/images/itemListBg.gif) repeat-x'); 
		}
	); 
	
	//submit in cards hover
	$(".submitButton").hover(	
		function () {	  
			var element = $(this);
			element.css({'background-position' : '0 -30px',
						'cursor' : 'pointer'
						});
			
		}, 
		function () {
			var element = $(this);
			element.removeAttr("style");
		}
	); 
	
	$("#customer_name_sho").change(function() {
		$("#da_name_sho").val($(this).val());
		
	});
		

});	
