$(window).ready(function(){
  
	$('a.nwc').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});	
	
	$("a.fancyvirtual").fancybox({
		 'padding'           : 0,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});	
	
	$("a.modal").each(function() {
    var a = $(this);
    a.fancybox({		
  		'scrolling'		: 'no',
  		'titleShow'		: false,		
  		'onStart'		: function() {
  			var boxId = a.attr("href");

  			var promena = "#" + boxId.split("#")[1];
  			$(promena).show();
  		},
    		'onClosed'		: function() {
    			var boxId = a.attr("href");
    			var promena = "#" + boxId.split("#")[1];
    			
    		    $(promena).hide();
  		}
  	});  
  });
	
	
  
	/*$("a.modal").fancybox({		
		'scrolling'		: 'no',
		'titleShow'		: false,		
		'onStart'		: function() {
			var boxId = $(this).attr("href");
			console.log($(this).attr("href"));
			var promena = "#" + boxId.split("#")[1];
			$(promena).show();
		},
		'onClosed'		: function() {
			var boxId = $(this).attr("href");
			var promena = "#" + boxId.split("#")[1];
			
		    $(promena).hide();
		}
	});*/
	
	
	// carousel
	if ($(".carousel").size() > 0){
		$(".carousel").jCarouselLite({
	        btnNext: ".next",
	        btnPrev: ".prev"
	    });
	};
	
	if ($(".carousel1").size() > 0){
		$(".carousel1").jCarouselLite({
	        visible: 3,
	        start: 0,
	        btnNext: ".next",
	        btnPrev: ".prev"
	    });
	};
	
	if ($(".carousel2").size() > 0){
		$(".carousel2").jCarouselLite({
	       	visible: 3,
	        start: 0,
	        btnNext: ".next",
	        btnPrev: ".prev"
	    });
	};
	
	if ($(".carousel3").size() > 0){
		$(".carousel3").jCarouselLite({
	       	visible: 3,
	        start: 0,
	        btnNext: ".next",
	        btnPrev: ".prev"
	    });
	};
	
	if ($(".thisCarousel").size() > 0){
		$('.thisCarousel').jcarousel();
	};
	
	$("#verticalTabs2-env .tab").hide();
	$("#verticalTabs2-env #c1.tab").show();
	
	$("#verticalTabs-env2 .tab").hide();
	$("#verticalTabs-env2 #c1.tab").show();
	
	$("#verticalTabs-env3 .tab").hide();
	$("#verticalTabs-env3 #c1.tab").show();
	
	// definice menu
  	$("#nav").ndMenu();
	
	//validace formu
  	$("#form").ndFormValidator();
  	
  	// zobrazeni boxu definujte sluzby po kliknuti
  	$(".showDef").click(function () {
  		$("#def").show("slow");
	});
	$(".hiddenDef").click(function () {
  		$("#def").hide("slow");
	});
	
	$(".showNights").click(function () {
  		$("#nights").show("slow");
	});
	$(".hiddenNights").click(function () {
  		$("#nights").hide("slow");
	});
	
	//zobrazeni korespodencni adresy
	$(".showCor").change(function () {
		var checked = $("#cor").attr("checked");
		if (checked == true) {$("#corr").show("slow");}
		else {$("#corr").hide("slow");}
	});
	
	$("#hotel").change(function() {
		var thisValue = $(this).attr("value");
		$(".custom-value").hide();
		
		if (thisValue == 1){
			$("#lanterna").show("slow");
			$("#horal").hide("slow");
			$("#galik").hide("slow");
		}
		if (thisValue == 2){
			$("#lanterna").hide("slow");
			$("#horal").show("slow");
			$("#galik").hide("slow");
		}
		if (thisValue == 3){
			$("#lanterna").hide("slow");
			$("#horal").hide("slow");
			$("#galik").show("slow");
		}
	});
	
	//selecty
	//if ($("#reservation").size() > 0){
	//	$('select#board').selectmenu({style:'dropdown'});
	//	$('select#currency').selectmenu({style:'dropdown'});
	//};
	
	//volba typu poukazu
	$(".type2").change(function() {
		var parent	=	$(this).find("option:selected").parents("ul");
		var hodnota	=	$(parent).find("option:selected").val();
		
		$(parent).find(":radio").attr("checked",true);
  		$("#def").show("slow");
  		$("#nights").show("slow");

		if(hodnota=="other"){
			$(parent).find(".custom-value").show();
		}
		else {
			$(parent).find(".custom-value").hide();
		}
	})
	
	
	$("#control a").click(function(){
		var myHref = $(this).attr("href");	// ziskani retezce z odkazu
			myHref = myHref.substring(1);	// odseknuti #
		
		$("#control a").removeClass("active");
		$(this).addClass("active");
		
		// prace s obsahovymi prvky
		$("#verticalTabs2-env .tab").hide();
		$("#verticalTabs2-env .tab").each(function(){				
			if( $(this).attr("id") == myHref ){ $(this).show(); }
		});
		
		return false;			
	});
	
	// obarveni tabulek
	$("#article table").each(function(){
		
		// liche radky tabulky
		$(this).find("tr:odd").addClass("odd");
		
		// prvni sloupec			
		$(this).find("tr").each(function(){
			$(this).find(":first").addClass("first");
		});
		
		var table = $(this).clone();
		var tableEnv = $("<div class='tblBody'></div>").append( table );
	
		$(this).after( tableEnv ).remove();
		//tableEnv.appendTo("#envelope");
		
	});
		
	// efekty pro obrazky
	$("a.fancybox").fancybox({type:"image"});
	
	// bubliny v kalendari
	$(".hasBubble").hover(
		function(){ $(this).find(".bubble").show(); },
		function(){ $(this).find(".bubble").hide(); }
	);		
	

	//slider
	index = 1;
	timer = 0;		
	max = $("#c1 .imageArea .item").size();
	
	cardId = "#c1";
	
	$(".slider .imageArea .item").hide();
	//$(".tab").hide();
	$(cardId).show();
	
	// -------------------
	
	function hideAndShow(pIndex){
		if(pIndex <= 0){ index = max; }
		if(pIndex <= max){}			
		else{ index=1; } // globalni promenna
			
		var elementPath = cardId + " .imageArea .item";
					
		$(elementPath).hide();
		$(elementPath).eq(index-1).fadeIn(1000);
	}				
	
	// -------------------
	
	function slideShow(){
		if(index <= max){ index++; }			
		else{ index=1; }
		
		hideAndShow(index);
	}
			
	// -------------------								
	
	timer = setInterval(function(){ slideShow(); }, 4000);
	
	$(".ctrl").click(function() {
		clearInterval(timer);	// zastaveni casovace

		// pridani indexu
		//var oriented = $(this).attr("id");			
		//if(oriented == "ctrlLeft"){ index++; }
		//if(oriented == "ctrlRight"){ index--; }
		if($(this).hasClass('ctrlRight')){ index--; }
    	if($(this).hasClass('ctrlLeft')){ index++; }		

		// zobrazeni polozky
		hideAndShow(index);
		timer = setInterval(function(){ slideShow(); }, 4000);
		return false;
	});
			
	// -------------------
	
	$("#control a").click(function() {
		cardId = $(this).attr("href");
		
		$(".tab").hide();
		$(cardId).show();		
			
		index = 1;
		max = $(cardId + " .imageArea .item").size();
		hideAndShow(index);	
			
		return false;
	});
	
	// -------------------
	
	hideAndShow(1);						
});	
  
 // generator galerii 
function GenerateCustomFckGallery(files_array)
{
	var result="";
	for (var a=0;a<files_array.length;a++)
		result+="<a href=\""+files_array[a].path+"\" class=\"fancybox\" rel=\"roadtrip\"><img title=\"\" alt=\"\" src=\""+files_array[a].thumb+"\" /></a>";
	return result;
}

	
	// ------------------------------
	
	$(document).ready(function() {  				
		
		// zmena adresy
		$("#from").keydown(function(e){
			var to = $("#to").val();
			
			if( (e.keyCode == 13) && ( to != 0 ) ){
				ndMaps_createNavigation($(this).val(), to,"");
			}
			if( (e.keyCode == 13) && ( to == 0 ) ){ alert("Vyberte hotel"); }
		});
		
		// zmena hotelu
		$("#to").change(function(e){
			var from = $("#from").val();
			
			if( $(this).val != 0 ){
				ndMaps_createNavigation(from, $(this).val(),"route");
			}		
		});
	
		$(".mapControl input[type='checkbox']").click(function(){
			
			var thisVal = $(this).val();
			var thisCheck = $(this).attr("checked");
			var thisRel = $(this).attr("rel");
			
			if( thisCheck == false ){
				ndMaps_hideTrack( thisRel );
			}
			if( thisCheck == true ){
				ndMaps_showTrack( thisRel );
			}		
		});

	});	

// kontrola newsletteru
function kontrola(){

	email = document.getElementById("inpNewsMail").value;
	
	if( email != "" ){
		alert("Zasílame Vám e-mail pro registraci/editaci odběru novinek.");
		return true;
	}
	else{
		alert("Zadejte prosím Váš e-mail.");
		return false;
	}
	
}

