$(document).ready(function(){
  
	$('a.nw').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});	
	
	
	
	$("#verticalTabs2-env .tab").hide();
	$("#verticalTabs2-env #c1.tab").show();
	
	$("#verticalTabs-env2 .tab").hide();
	$("#verticalTabs-env2 #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");
	});
	
	//zobrazeni korespodencni adresy
	$(".showCor").change(function () {
		var checked = $("#cor").attr("checked");
		if (checked == true) {$("#corr").show("slow");}
		else {$("#corr").hide("slow");}
	});
	
	//selecty
	if ($("#reservation").size() > 0){
		$('select#board').selectmenu({style:'dropdown'});
		$('select#currency').selectmenu({style:'dropdown'});
	};
	
	
	$("#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(); }
	);		
	
	// carousel
	if ($(".carousel").size() > 0){
		$(".carousel").jCarouselLite({
	        btnNext: ".next",
	        btnPrev: ".prev"
	    });
	};
	
	//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");
		}		
	});

	});	

// 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;
	}
	
}
