﻿$(document).ready(function(){

	var chooseLanguage = $("meta[http-equiv='Content-Language']").attr('content')

	$("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'
	});
	
	/**************************
		TITULNI STRANKA - SLIDER NOVINEK
	*/
	$("#newsContent").easySlider({
		/*auto: true,*/
		continuous: true,
		numeric: true,
		speed: 1000,
		pause: 10000
	});
	
	
	$('.do-noveho-okna').click(function(){  
	     window.open($(this).attr("href"));  
	     return false;  
	});
	
	
	if ($('#homeContent').length == 1) {
		
		/**************************
			TITULNI STRANKA - NACITANI OBRAZKU
		*/
		var i = 0;
		imageObj = new Image();
		images = new Array();
		for(i=0; i<=3; i++) {
		
			images[i]="/data/img/home-" + chooseLanguage + "/homeContent-" + [i] + ".jpg"
		
		}
	
		for(i=0; i<=3; i++) {
			imageObj.src=images[i];
		}
		
		/**************************
			TITULNI STRANKA - PROLINANI OBRAZKU
		*/
		var homeContentCount = 3;
		var homeContentCurrent = 1;
		
		function homeContentIMG() {
			homeContentPrev = homeContentCurrent % homeContentCount;
			homeContentNext = ++homeContentCurrent % homeContentCount;
			
			$('#homeContentIMGa').css('background', 'url(/data/img/home-' + chooseLanguage + '/homeContent-' + homeContentPrev + '.jpg) no-repeat');
	
			$('#homeContentIMGb').animate({
				opacity: 0.0
			}, 1000, function() {
				$(this).css('background', 'url(/data/img/home-' + chooseLanguage + '/homeContent-' + homeContentNext + '.jpg) no-repeat');
			});
			
			$('#homeContentIMGb').animate({
				opacity: 1.0
			}, 1000);	
			 
		}
		
		setInterval(homeContentIMG,5000); 
	}
	
	
	/**************************
		LIGHTBOX - CLOSE
		NAPISTE NAM
		POSLAT ZNAMEMU
	*/
	$('#lightBoxContactForm-header .close').click(function() {
		
		$('#overlay').css('display', 'none')
		$('#lightBoxContactForm').css('display', 'none')
		$('#lightBoxContactForm').css('left', '-800px')
	
	});
	
	/**************************
		LIGHTBOX
		AJAXEM NACITANI FORMULARE PRO NAPISTE NAM
	*/
	$('.lightBoxContactForm').click(function() {
		
		chooseLanguage = $("meta[http-equiv='Content-Language']").attr('content')
		
		thisHref = $(this).attr('href')
		thisGoods = thisHref.indexOf('?')
		ajaxHref = "/" + chooseLanguage + "/contact-ajax" + thisHref.substring(thisGoods)
		
		$.post(
			ajaxHref,
			{},
			function(data){
				
				$("#lightBoxContactForm-content").html(data);
				
				$('#overlay').css('width', $(window).width())
				
				if ($('#page').height() > $(document).height()) {
					$('#overlay').css('height', $('#page').height())
				} else {
					$('#overlay').css('height', $(document).height())
				}
				
				$('#overlay').css('display', 'block')
				$('#lightBoxContactForm').css('display', 'block')
				$('.contactH2').css('display', 'block')
				$('.friendH2').css('display', 'none')
				
				positionLeft = (($(window).width()/2) - 355) + "px";
				positionLeft2 = (($(window).width()/2) - 250) + "px";
				
				$('#lightBoxContactForm').css('top', $(window).scrollTop() + 100)
				
				setTimeout(function() {
					
					$("#lightBoxContactForm").animate({
						left: positionLeft2
					})
					.animate({
						left: positionLeft
					}, "normal");
					
				}, 500); 
			
			}
		);
		
		return false;
	
	});
	
	/**************************
		LIGHTBOX
		AJAXEM NACITANI FORMULARE PRO ODESLANI PRODUKTU ZNAMEMU
	*/
	$('.sendFriend').click(function() {
		
		chooseLanguage = $("meta[http-equiv='Content-Language']").attr('content')
		
		thisHref = $(this).attr('href')
		thisGoods = thisHref.indexOf('?')
		ajaxHref = "/" + chooseLanguage + "/friend-ajax" + thisHref.substring(thisGoods)
		
		$.post(
			ajaxHref,
			{},
			function(data){
				
				$("#lightBoxContactForm-content").html(data);
				
				$('#overlay').css('width', $(window).width())
				
				if ($('#page').height() > $(document).height()) {
					$('#overlay').css('height', $('#page').height())
				} else {
					$('#overlay').css('height', $(document).height())
				}
				
				$('#overlay').css('display', 'block')
				$('#lightBoxContactForm').css('display', 'block')
				$('.contactH2').css('display', 'none')
				$('.friendH2').css('display', 'block')
				
				positionLeft = (($(window).width()/2) - 355) + "px";
				positionLeft2 = (($(window).width()/2) - 250) + "px";
				
				$('#lightBoxContactForm').css('top', $(window).scrollTop() + 100)
				
				setTimeout(function() {
					
					$("#lightBoxContactForm").animate({
						left: positionLeft2
					})
					.animate({
						left: positionLeft
					}, "normal");
					
				}, 500); 
			
			}
		);
		
		return false;
	
	});	
	
	
	/**************************
		LIGHTBOX
		AJAXEM NACITANI FORMULARE PRO KONTAKTNI FORMULAR V KONTAKTECH
	*/
	$('.showContactArticle').click(function() {
		
		chooseLanguage = $("meta[http-equiv='Content-Language']").attr('content')
		
		thisHrefRel = $(this).attr('rel')
		
		thisHrefRelSeparator = thisHrefRel.indexOf('-')
		thisHrefRelID = thisHrefRel.substring(0, thisHrefRelSeparator)
		thisHrefRelName = thisHrefRel.substring(thisHrefRelSeparator + 1)
		
		ajaxHref = "/" + chooseLanguage + "/contact-web-ajax" + "?article=" + thisHrefRelID
		
		$.post(
			ajaxHref,
			{},
			function(data){
				
				$("#lightBoxContactForm-content").html(data);
				
				$('#overlay').css('width', $(window).width())
				
				if ($('#page').height() > $(document).height()) {
					$('#overlay').css('height', $('#page').height())
				} else {
					$('#overlay').css('height', $(document).height())
				}
				
				$('#overlay').css('display', 'block')
				$('#lightBoxContactForm').css('display', 'block')
				$('.friendH2').css('display', 'none')
				$('.contactH2').css('display', 'block')
				/*$('.contactH2').text(thisHrefRelName)*/
				
				if (chooseLanguage == 'cz') {
					$('.contactH2').text('Kontaktní formulář')
				} else if (chooseLanguage == 'en') {
					$('.contactH2').text('Contact form')
				}
				
				$('#contactForm h2').text(thisHrefRelName)
				
				if (chooseLanguage == 'ru') {
					Cufon.replace('.contactH2, #contactForm h2', { fontFamily: 'arial-rg' });
				} else {
					Cufon.replace('.contactH2, #contactForm h2', { fontFamily: 'alber-rg' });
				}
				
				positionLeft = (($(window).width()/2) - 355) + "px";
				positionLeft2 = (($(window).width()/2) - 250) + "px";
				
				$('#lightBoxContactForm').css('top', $(window).scrollTop() + 100)
				
				setTimeout(function() {
					
					$("#lightBoxContactForm").animate({
						left: positionLeft2
					})
					.animate({
						left: positionLeft
					}, "normal");
					
				}, 500); 
			
			}
		);
		
		return false;
	
	});
	
	
	/**************************
		SEARCH - PO KLIKNUTI ODSTRANI TEXT
	*/
	$('#searchTextInput').click(function() {			
		if ($(this).attr('value') == 'Hledaný výraz') {
			$(this).attr("value", "")
		} else if ($(this).attr('value') == 'Search term') {
			$(this).attr("value", "")
		} else if ($(this).attr('value') == 'Gesuchter Begriff') {
			$(this).attr("value", "")
		} else if ($(this).attr('value') == 'Poszukiwana fraza') {
			$(this).attr("value", "")
		} else if ($(this).attr('value') == 'Искомое выражение') {
			$(this).attr("value", "")
		}
	}).blur(function(){
		if ($(this).attr('value') == "" && chooseLanguage == 'cs') {
			$(this).attr("value", "Hledaný výraz")
		} else if ($(this).attr('value') == "" && chooseLanguage == 'en') {
			$(this).attr("value", "Search term")
		} else if ($(this).attr('value') == "" && chooseLanguage == 'de') {
			$(this).attr("value", "Gesuchter Begriff")
		} else if ($(this).attr('value') == "" && chooseLanguage == 'pl') {
			$(this).attr("value", "Poszukiwana fraza")
		} else if ($(this).attr('value') == "" && chooseLanguage == 'ru') {
			$(this).attr("value", "Искомое выражение")
		}
	});
	
	
	/**************************
		LIGHTBOX
		ZOBRAZENI CLANKU V LIGHTBOXU
	*/
	$('a.lightbox-clanek').click(function() {
	
		ajaxHref = $(this).attr('href') + ".ajax"
		$(window).scrollTop(0)
				
		$.post(
			ajaxHref,
			{},
			function(data){
				
				$("#lightBoxArticle-content").html(data);
				
				valueh1 = $("#lightBoxArticle-content h1").text()
				$("#lightBoxArticle-content h1").css('display', 'none')
				
				$('#lightBoxArticle-header .h2').text(valueh1)
				if (chooseLanguage == 'ru') {
					Cufon.replace('#lightBoxArticle-header .h2', { fontFamily: 'arial-rg' });
				} else {
					Cufon.replace('#lightBoxArticle-header .h2', { fontFamily: 'alber-rg' });
				}
				
				$('#overlay').css('width', $(window).width())
				$('#overlay').css('height', $('#page').height())				
				$('#overlay').css('display', 'block')
				$('#lightBoxArticle').css('display', 'block')
				
				positionLeft = (($(window).width()/2) - 485) + "px";
				positionLeft2 = (($(window).width()/2) - 420) + "px";
				$('#lightBoxArticle').css('top', 80)
								
				setTimeout(function() {
					
					$("#lightBoxArticle").animate({
						left: positionLeft2
					})
					.animate({
						left: positionLeft
					}, "normal");
					
					if ($('#page').height() < $('#lightBoxArticle').height()) {
						$('#overlay').css('height', $('#lightBoxArticle').height() + 150)
					}
					
				}, 500); 
				
			}
		);
		
		return false;
	
	});
	
	/**************************
		LIGHTBOX - CLOSE
		CLANEK
	*/
	$('#lightBoxArticle-header .close').click(function() {
		
		$('#overlay').css('display', 'none')
		$('#lightBoxArticle').css('display', 'none')
		$('#lightBoxArticle').css('left', '-1000px')
	
	});
	
});
	


/**************************
	ZOBRAZUJE TABULKU, KTERA JE MALA A PO NAJETI MYSI SE ZVETSI + PRI ODJETI CEKA 2s A PAK SE TEPRVE SCHOVA
*/	
var tableTimer;
var tableTimerNumber;

$(document).ready(function(){	
	
	defaultHTML = $('div.tabulka').html()

	$('div.tabulka').html('<div class="corner"><div class="cornerLeftBG"><div class="cornerRightTop"><div class="cornerLeftTop"><div class="cornerRightBottom"><div class="cornerLeftBottom"><div class="cornerRightBG"><div class="cornerContent">' + defaultHTML + '</div></div></div></div></div></div></div></div>')	
	
	$('.corner').mouseenter(function() {

		$('div.tabulka').css('height', $('table.tabulka').height())
		$('div.tabulka').css('overflow', 'visible')
		$('.cornerContent').css('height', $('table.tabulka').height() - 26)
		$('.cornerContent').css('width', $('table.tabulka').width())
				
		$('.corner').css('position', 'absolute')
		$('.corner').css('left', '-26px')
		$('.corner').css('top', '-26px')
		
		$('#in_goodsLeftCol h2').css('position', 'relative')
		$('#in_goodsLeftCol h2').css('z-index', '1000000')
		
		$('.corner').addClass('cornerShow')
		
		clearTimeout(tableTimer);
		
	}).mouseleave(function() {
		
		tableTimerNumber = 2;
		tableTimerCount();
		
	});	
	
});

	function tableTimerCount() {
		if(tableTimerNumber >= 0) {
			tableTimerNumber--;
			/*$('h1').text(tableTimerNumber) - vyblije odecitani do h1 */
			if (tableTimerNumber > 0) {
				
				tableTimer = setTimeout('tableTimerCount()', 1000);
				
			} else {
				
				$('.corner').removeClass('cornerShow')
				
				$('div.tabulka').css('height', 'auto')
				$('div.tabulka').css('overflow', 'hidden')
				$('div.tabulka').css('position', 'relative')
				$('div.tabulka').css('top', '0px')
				
				$('.corner').css('position', 'static')
				$('.corner').css('left', 'auto')
				$('.corner').css('top', 'auto')
				$('.corner').css('width', 'auto')
						
				$('#in_goodsLeftCol h2').css('position', 'static')
				$('#in_goodsLeftCol h2').css('z-index', '1')
			
				$('div.corner').html(defaultHTML)	
				$('div.corner').html('<div class="cornerLeftBG"><div class="cornerRightTop"><div class="cornerLeftTop"><div class="cornerRightBottom"><div class="cornerLeftBottom"><div class="cornerRightBG"><div class="cornerContent">' + defaultHTML + '</div></div></div></div></div></div></div>')	
				
			}
		} 
	}



/**************************
	SEND AJAX FORM
	AJAXEM ODESLANI KONTAKTNIHO FORMULARE
*/
function sendContactForm(sender, args) {

	// ziskani nadrazeneho formulare
    var form1 = $(sender).parents('form:first').get(0);
    
    chooseLanguage = $("meta[http-equiv='Content-Language']").attr('content')
	ajaxHref = "/" + chooseLanguage + "/contact-ajax"
	
	$.post(
		ajaxHref,
		$(form1).find(":input").serializeArray(),
		function(data){
			
			$("#lightBoxContactForm-content").html(data);
		
		}
	);
	
	return false;
	
}


/**************************
	SEND AJAX FORM
	AJAXEM ODESLANI KONTAKTNIHO FORMULARE V KONTAKTECH
*/
function sendContactWebForm(sender, args) {

	// ziskani nadrazeneho formulare
    var form1 = $(sender).parents('form:first').get(0);
    
    chooseLanguage = $("meta[http-equiv='Content-Language']").attr('content')
	ajaxHref = "/" + chooseLanguage + "/contact-web-ajax"
	
	$.post(
		ajaxHref,
		$(form1).find(":input").serializeArray(),
		function(data){
			
			$("#lightBoxContactForm-content").html(data);
			
			if (chooseLanguage == 'ru') {
				Cufon.replace('#contactForm h2', { fontFamily: 'arial-rg' });
			} else {
				Cufon.replace('#contactForm h2', { fontFamily: 'alber-rg' });
			}			
		}
	);
	
	return false;
	
}


/**************************
	SEND AJAX FORM
	AJAXEM ODESLANI DOPORUCENI PRODUKTU ZNAMEMU
*/
function friendForm(sender, args) {

	// ziskani nadrazeneho formulare
    var form1 = $(sender).parents('form:first').get(0);
	
	chooseLanguage = $("meta[http-equiv='Content-Language']").attr('content')
	ajaxHref = "/" + chooseLanguage + "/friend-ajax"
	
	$.post(
		ajaxHref,
		$(form1).find(":input").serializeArray(),
		function(data){
			
			$("#lightBoxContactForm-content").html(data);
		
		}
	);
	
	return false;
	
}






