$(document).ready(function(){
	if ($("a[rel^='photo']").length >= 1) {
		$("a[rel^='photo']").prettyPhoto({
			animationSpeed: 'fast', /* fast/slow/normal */
			padding: 0, /* padding for each side of the picture */
			opacity: 0.8, /* Value betwee 0 and 1 */
			showTitle: true, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: ' ze ' /* The separator for the gallery counter 1 "of" 2 */
		});
	};
	
	$('#footerTabs').tabs({ 
		fxSlide: true, 
		fxFade: true, 
		fxSpeed: 'normal' 
	});
	
	$('#goodsTabs').tabs({
		fxSlide: true, 
		fxFade: true, 
		fxSpeed: 'normal'
	});
	
	$('#photoSliderUL').jcarousel({
        scroll: 2
    });
    
    
    $('#showCompanyInfo').click(function() {
		$('#basketCompany').toggle()
    });
    
    $('#showAddressInfo').click(function() {
		$('#basketAdress').toggle()
    });
    
    
    
    
    /**************************
		SEARCH - PO KLIKNUTI ODSTRANI TEXT
	*/
	$('#sSearchText').click(function() {			
		if ($(this).attr('value') == 'Hledaný výraz') {
			$(this).attr("value", "")
		} 
	});
    
    
    
    /**************************
		LIGHTBOX
		AJAXEM NACITANI FORMULARE PRO ZEPTAT SE PRODAVACE
	*/
	$('.goodsDetailIcoSeller').click(function() {
	
		thisHref = $(this).attr('href')
		thisGoods = thisHref.indexOf('?')
		ajaxHref = "/goods-query-ajax" + thisHref.substring(thisGoods)
		
		$.post(
			ajaxHref,
			{},
			function(data){
				
				$("#sendQueryText").html(data);
				
				$('#overlay').css('width', $(window).width())
				$('#overlay').css('height', $('#page').height())
				$('#overlay').css('display', 'block')
				$('#sendQuery').css('display', 'block')
				
				$('span#goodsName').text($('h1').text())
				$('#sendQueryContent .h1').html('Zeptat se prodavače<span></span>')
				
				$('.contactH2').css('display', 'block')
				$('.friendH2').css('display', 'none')
				
				positionLeft = (($(window).width()/2) - 355) + "px";
				positionLeft2 = (($(window).width()/2) - 250) + "px";
				
				$('#sendQuery').css('top', $(window).scrollTop() + 50)
				
				setTimeout(function() {
					
					$("#sendQuery").animate({
						left: positionLeft2
					})
					.animate({
						left: positionLeft
					}, "normal");
					
				}, 500); 
			
			}
		);
		
		return false;
	
	});
	
	
	
    /**************************
		LIGHTBOX
		AJAXEM NACITANI FORMULARE PRO DOPORUCENI ZNAMEMU
	*/
	$('.goodsDetailIcoSend').click(function() {
	
		thisHref = $(this).attr('href')
		thisGoods = thisHref.indexOf('?')
		ajaxHref = "/goods-send-friend-ajax" + thisHref.substring(thisGoods)
		
		$.post(
			ajaxHref,
			{},
			function(data){
				
				$("#sendQueryText").html(data);
				
				$('#overlay').css('width', $(window).width())
				$('#overlay').css('height', $('#page').height())
				$('#overlay').css('display', 'block')
				$('#sendQuery').css('display', 'block')
				
				$('span#goodsName').text($('h1').text())
				$('#sendQueryContent .h1').html('Doporučit známému<span></span>')
				
				$('.contactH2').css('display', 'block')
				$('.friendH2').css('display', 'none')
				
				positionLeft = (($(window).width()/2) - 355) + "px";
				positionLeft2 = (($(window).width()/2) - 250) + "px";
				
				$('#sendQuery').css('top', $(window).scrollTop() + 50)
				
				setTimeout(function() {
					
					$("#sendQuery").animate({
						left: positionLeft2
					})
					.animate({
						left: positionLeft
					}, "normal");
					
				}, 500); 
			
			}
		);
		
		return false;
	
	});
	
    
    
    $('.sendQueryClose').click(function(){
    
		$('#overlay').css('display', 'none')
		$('#sendQuery').css('display', 'none')
		$('#sendQuery').css('left', '-750px')
    
    });
    
    
    $('.goodsDetailGroupInput').click(function() {
		window.open($(this).attr('value'), '_self');
    });    
    
});



function closeWindow() {
    
	$('#overlay').css('display', 'none')
	$('#sendQuery').css('display', 'none')
	$('#sendQuery').css('left', '-750px')

};



/**************************
	SEND AJAX FORM
	AJAXEM ODESLANI ZEPTAT SE PRODAVACE
*/
function sendGoodsQuery(sender, args) {

	// ziskani nadrazeneho formulare
    var form1 = $(sender).parents('form:first').get(0);
	
	$.post(
		"/goods-query-ajax",
		$(form1).find(":input").serializeArray(),
		function(data){
			
			$("#sendQueryText").html(data);
		
		}
	);
	
	return false;
	
}


/**************************
	SEND AJAX FORM
	AJAXEM ODESLANI DOPORUCENI ZNAMEMU
*/
function sendGoodsFriend(sender, args) {

	// ziskani nadrazeneho formulare
    var form1 = $(sender).parents('form:first').get(0);
	
	$.post(
		"/goods-send-friend-ajax",
		$(form1).find(":input").serializeArray(),
		function(data){
			
			$("#sendQueryText").html(data);
		
		}
	);
	
	return false;
	
}



function UpdateBasket(sender, args) {

	// ziskani nadrazeneho formulare
    var form1 = $(sender).parents('form:first').get(0);
    
	$.post(
		"/ajax-basket",
		$(form1).find("input").serializeArray(),
		function(data){

			$.get(
				"/ajax-header-basket",
				function(data){
					$("#headerBasket").html(data);
				}
			);
			
			$.get(
				"/ajax-basket-info",
				function(data){				
					$("#basket-info").html(data);
				}
			);
			
		}
	);
	
}





$(document).ready(function() {
	$("#contentBasketLeftCol :radio[id^='basket.Transfer']").click(function(){
		// vsechny zakazeme
		$("#contentBasketLeftCol :radio[id^='basket.Payment']").each(function(index, htmlObject){
			htmlObject.disabled = true;

			$(htmlObject).parent().get(0).className='pDisabled';//.addClass("pDisabled");

		});
		// pokud je neaktivni a je checked => odeber mu jej
		$("#contentBasketLeftCol :radio[id^='basket.Payment']").each(function(index, htmlObject){
			if(htmlObject.disabled && htmlObject.checked)
				htmlObject.checked = false;                
		});

		// zaktivnime povolene
		$("#contentBasketLeftCol :radio[class*='"+this.id+"']").each(function(index, htmlObject){
			htmlObject.disabled = false;

			$(htmlObject).parent().get(0).className='';
			//$(htmlObject).parent().removeClass("pDisabled");
		});
	});
});









