﻿$(document).ready(function(){
	$("a[rel^='photo']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		opacity: 0.80, /* Value between 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		default_width: 400,
		default_height: 200,
		theme: 'light_rounded'
	});

	/**************************
		POZICOVANI VYSKAKOVACIHO BOXU S PRODUKTY NA HOMEPAGE
	*/
	
	if ($("#header-rightCol ul#menu li#products").hasClass('odd1')) {
		liWidth = 0
	} else if ($("#header-rightCol ul#menu li#products").hasClass('odd2')) {
		liWidth = $("#header-rightCol ul#menu li.odd1").width()
	} else if ($("#header-rightCol ul#menu li#products").hasClass('odd3')) {
		liWidth = $("#header-rightCol ul#menu li.odd1").width() + $("#header-rightCol ul#menu li.odd2").width()
	} else if ($("#header-rightCol ul#menu li#products").hasClass('odd4')) {
		liWidth = $("#header-rightCol ul#menu li.odd1").width() + $("#header-rightCol ul#menu li.odd2").width() + $("#header-rightCol ul#menu li.odd3").width()
	} else if ($("#header-rightCol ul#menu li#products").hasClass('odd5')) {
		liWidth = $("#header-rightCol ul#menu li.odd1").width() + $("#header-rightCol ul#menu li.odd2").width() + $("#header-rightCol ul#menu li.odd3").width() + $("#header-rightCol ul#menu li.odd4").width()
	} else {
		liWidth = 0
	}
	
	productsWidth = (106 - $("#header-rightCol ul#menu li#products").width()) / 2
	leftPosition = 324 + liWidth - productsWidth
	
	$("#homeProducts #homeProductsHref").css('left', leftPosition)
	$("#homeProducts #homeProductsBox").css('left', leftPosition)
	
	
	/**************************
		ZOBRAZOVANI A ZAVIRANI BOXU S PRODUKTY NA HOMEPAGE
	*/
	$("#header-rightCol ul#menu li#products").mouseover(function() {
		$('#homeProducts').css('display', 'block')
	});
	$("#homeProductsHref").mouseover(function() {
		$('#homeProducts').css('display', 'block')
	});
	$("#homeProductsBox").mouseover(function() {
		$('#homeProducts').css('display', 'block')
	});
	$("#homeProductsHref").mouseout(function() {
		$('#homeProducts').css('display', 'none')
	});
	$("#homeProductsBox").mouseout(function() {
		$('#homeProducts').css('display', 'none')
	});


	/**************************
		SEARCH - PO KLIKNUTI ODSTRANI TEXT
	*/
	
	$('#searchTextInput').click(function() {
		if ($(this).attr('value') == 'zadejte hledaný výraz') {
			$(this).attr("value", "")
		}
	}).blur(function(){
		if ($(this).attr('value') == "") {
			$(this).attr("value", "zadejte hledaný výraz")
		}
	});
	
	/**************************
		HOME - EASYSLIDER
	*/
	$("#homeSliderIn").easySlider({
		auto: true, 
		continuous: true,
		numeric: true,
		speed: 800,
		pause: 5000
	});
	
	
	/**************************
	POCITANI VYSEK NADPISU NA SEZNAMU PRODUKTU
	*/
	if ($('#productContent').length == 1 || $('#rightCol').length == 1) {
		
		var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
		
		if (IE6 != true) {
			$('.productList').each(function(){  		
				var height = 0;			
				$('h2', this).each(function(){
					$(this).css('height', 'auto');
					height = this.offsetHeight > height ? this.offsetHeight : height;			
				}).each(function(){
					if(height > 0) $(this).css('height', height);
				});
			});	
		}
	}
	
	/**************************
		LIGHTBOX - CLOSE
	*/
	$('#lightBoxContent .close').click(function() {
		
		$('#lightBoxOverlay').css('display', 'none')
		$('#lightBoxContent').css('display', 'none')
		$('#lightBoxContent').css('left', '-800px')
	
	});
	
	/**************************
		LIGHTBOX
		AJAXEM NACITANI FORMULARE PRO ODESLANI PRODUKTU ZNAMEMU
	*/
	$('.send').click(function() {
		
		thisHref = $(this).attr('href')
		ajaxHref = thisHref + '&layout=ajax'
	
		$.post(
			ajaxHref,
			{},
			function(data){
				
				$("#formContent").html(data);
				
				$('#lightBoxOverlay').css('width', $(window).width())
				
				if ($('#page').height() > $(document).height()) {
					$('#lightBoxOverlay').css('height', $('#page').height())
				} else {
					$('#lightBoxOverlay').css('height', $(document).height())
				}
				
				$('#lightBoxOverlay').css('display', 'block')
				$('#lightBoxContent').css('display', 'block')
				
				leftPos = ($(document).width() / 2) - ($('#lightBoxContent').width() / 2)
				$('#lightBoxContent').css('left', leftPos)
				$('#lightBoxContent').css('top', $(window).scrollTop() + 100)
				Cufon.replace('span.h1', { fontFamily: 'calibriItalic' });
			}
		);
		
		return false;
	
	});
});

/**************************
	SEND AJAX FORM
	AJAXEM ODESLANI KONTAKTNIHO FORMULARE
*/
function friendForm(sender, args) {
	// ziskani nadrazeneho formulare
    var form1 = $(sender).parents('form:first').get(0);

	ajaxHref = '/send-friend/.sendmail?layout=ajax'

	$.get(
		ajaxHref,
		$(form1).find(":input").serializeArray(),
		function(data){
			
			$("#formContent").html(data);
		
		}
	);
	
	return false;
}


/*PRIDANI STRANKY DO OBLIBENYCH*/

function AddFavorite(linkObj,addUrl,addTitle) {
	if (document.all && !window.opera) {
		window.external.AddFavorite(addUrl,addTitle);
		return false;
	} else if (window.opera && window.print) {
		linkObj.title = addTitle;
		return true;
	} else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')) {
		if (window.confirm('Přidat oblíbenou stránku jako nový panel?')) {
			window.sidebar.addPanel(addTitle,addUrl,'');
			return false;
		}
	}
	window.alert('Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k vašim oblíbeným odkazům.');
	return false;
}
