$(document).ready(function(){
	if($("a#templateNewsletter").length > 0) {
		// přihlášení k newsletteru
		$("a#templateNewsletter").fancybox({
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'speedIn' : 1,
			'speedOut' : 1,
			'overlayShow' : true,
			'hideOnOverlayClick' : true,
			'overlayOpacity' : 0,
			'showCloseButton' : true,
			'centerOnScroll' : true,
			'content' : httpPath+'templates/lipensko/subscribe.php?lang_id='+$("a#templateNewsletter").attr("class"),
			'type' : 'iframe',
			'width' : 258,
			'height' : 90,
			'margin' : 0,
			'padding' : 2,
			'scrolling' : 'no'
		});
	}

	if($("#rezervationRightForm").length > 0) {
		// rezervace ubytovani
		$("#rezervationRightForm input, #rezervationRightForm select").keydown(function(event){
			if((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
				return false;
			}
		});
		$("#rezervationRightForm").submit(function(){
			return false;
		});
	}
	// fancy nad vším
	$("#fancybox-wrap").css("z-index","9999");
	// rezervace datum
	if($("input[name=SrchFromYear]").length > 0) {
		$("input[name=SrchFromYear], input[name=SrchFromMonth], input[name=SrchFromDay]").datepicker({
			onSelect: function(a, b) {
				d = a.split("/");
				$("input[name=SrchFromYear]").val(d[2]);
				$("input[name=SrchFromMonth]").val(d[0]);
				$("input[name=SrchFromDay]").val(d[1]);
				return false;
			}
		});
	}
	if($("#ubytovaniNasTip").length > 0) {
		// náš tip rotátor
		autoSlide.init();
	}
	if($(".onEventChangeSize").length > 0) {
		/*$(".onEventChangeSize").focus(function(){
			$(this).css("height", "50px");
		}).blur(function(){
			if($(this).val() == "" || $(this).val().length < 10)
				$(this).css("height", "14px");
		});*/
	}
	if($("#sliderHolder").length > 0) {
		slideShow.init();
	}
	if($(".rezervovatOnline").length > 0) {
		$(".rezervovatOnline").click(function(){
			var base = "http://web.deskline.net/lipno/cs/show_accommodation/CZE/";
			var dalsi = $(this).attr("rel");
			var link = base+dalsi;
			$.fancybox.showActivity();
			$.fancybox({
				'transitionIn' : 'none',
				'transitionOut' : 'none',
				'speedIn' : 1,
				'speedOut' : 1,
				'overlayShow' : true,
				'hideOnOverlayClick' : true,
				'overlayOpacity' : 0,
				'showCloseButton' : true,
				'centerOnScroll' : true,
				'content' : link,
				'type' : 'iframe',
				'width' : '90%',
				'height' : '90%',
				'margin' : 0,
				'padding' : 2,
				'scrolling' : 'yes',
				'onComplete' : function() {
					$.fancybox.hideActivity();
				}
			});
			return false;
		});
	}
	if($("#hdpOD, #hdpDO").length > 0) {
		$("#hdpOD, #hdpDO").datepicker();
	}
	if($("#accPoptavka").length > 0) {
		$("#accPoptavka").addClass("active");
		$("#accPoptavka").click(function(){
			// poptavka
			$("#accPoptavka").addClass("active");
			$("#accRezervace").removeClass("active");
			return false;
		});
		$("#accRezervace").click(function(){
			// rezervace deskline
			$("#accPoptavka").removeClass("active");
			$("#accRezervace").addClass("active");
			return false;
		});
		$("#rezervationRightForm a").click(function(){
			if($("#accRezervace").hasClass("active")) {
				var d = new Date();
				var link = $("#rezervationRightForm").attr("action");
				link += '?SrchFromDay='+$("input[name=SrchFromDay]").val();
				link += '&SrchFromMonth='+$("input[name=SrchFromMonth]").val();
				link += '&SrchFromYear='+$("input[name=SrchFromYear]").val();
				link += '&qfdNights='+$("input[name=qfdNights]").val();
				link += '&qfdNumberOfUnits='+$("input[name=qfdNumberOfUnits]").val();
				link += '&qfdAdults='+$("input[name=qfdAdults]").val();
				link += '&qfdChildren='+$("input[name=qfdChildren]").val();
				link += '&CLR_all=true';
				link += '&qfdArrivalDate='+$("input[name=SrchFromYear]").val()+''+$("input[name=SrchFromMonth]").val()+''+$("input[name=SrchFromDay]").val();
				$.fancybox.showActivity();
				$.fancybox({
					'transitionIn' : 'none',
					'transitionOut' : 'none',
					'speedIn' : 1,
					'speedOut' : 1,
					'overlayShow' : true,
					'hideOnOverlayClick' : true,
					'overlayOpacity' : 0,
					'showCloseButton' : true,
					'centerOnScroll' : true,
					'content' : link,
					'type' : 'iframe',
					'width' : '90%',
					'height' : '90%',
					'margin' : 0,
					'padding' : 2,
					'scrolling' : 'yes',
					'onComplete' : function() {
						$.fancybox.hideActivity();
					}
				});
				return false;
			}
			else {
				$.fancybox.showActivity();
				$.fancybox({
					'transitionIn' : 'none',
					'transitionOut' : 'none',
					'speedIn' : 1,
					'speedOut' : 1,
					'overlayShow' : true,
					'hideOnOverlayClick' : true,
					'overlayOpacity' : 0,
					'showCloseButton' : true,
					'centerOnScroll' : true,
					'content' : httpPath+'templates/lipensko/poptavka.php?param='+$("input[name=SrchFromDay]").val()+'-'+$("input[name=SrchFromMonth]").val()+'-'+$("input[name=SrchFromYear]").val()+'-'+$("input[name=qfdNights]").val()+'-'+$("input[name=qfdNumberOfUnits]").val()+'-'+$("input[name=qfdAdults]").val()+'-'+$("input[name=qfdChildren]").val()+'-'+$("a#templateNewsletter").attr("class").replace("lang_", ""),
					'type' : 'iframe',
					'width' : 600,
					'height' : 375,
					'margin' : 0,
					'padding' : 2,
					'scrolling' : 'no',
					'onComplete' : function() {
						$.fancybox.hideActivity();
					}
				});
				return false;
			}
		});
	}
	if($("iframe[height=450][width=100%]").length > 0) {
		$("iframe[height=450][width=100%]").attr("src", "http://www.google.com/maps/ms?ie=UTF8&hl=cs&msa=0&msid=205011786845907913380.0004a3b389360224dd7c8&ll=48.778818,14.16687&spn=0.40723,1.031342&z=10&output=embed");
	}
	if($("#fb-like-button").length > 0) {
		$("#fb-like-button").html('<iframe src="http://www.facebook.com/plugins/like.php?href='+$("#fb-like-button").attr('rel')+'&amp;layout=standard&amp;show_faces=false&amp;width=595&amp;action=like&amp;font&amp;colorscheme=light&amp;height=24"	scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:595px; height:28px;" allowTransparency="true"></iframe>');
	}
	if($(".uniquePoptavka").length > 0) {
		$(".uniquePoptavka input, .uniquePoptavka textarea").keypress(function(e){
			if(e.which == 13)
				$(".uniquePoptavka").submit();
			else
				return true;
		});
	}
	if($(".slideDownDiv").length > 0) {
		$(".slideDownExecute").click(function(){
			$(".slideDownExecute").hide();
			$(".slideDownDiv").fadeIn();
			return false;
		});
	}
	
	if($("#google_map_canvas").length > 0) {
		$.getScript(httpPath+"templates/lipensko/js/google_map.js");
	}
	if($("#gmap_canvas").length > 0) {
		$.getScript(httpPath+"templates/lipensko/js/cyklo_google.js");
	}
});
// only with jQuery Easing
var autoSlide = {
		"vars": {
			"blockCount":0,
			"current":0,
			"bw":240,
			"bc":"#ubytovaniNasTipInner",
			"ibc":".ubytovaniNasTipBlock",
			"move":true,
			"interval":5000
		},
		"move": function() {
			var as = this;
			if(as.vars.blockCount > 1) {
				if(as.vars.move == true) {
					as.vars.current = as.vars.current + 1;
					var levaPozice = (as.vars.current*as.vars.bw)*-1;
					$(as.vars.bc).animate({'left': levaPozice}, 1000, 'easeOutCirc', function(){
						if(as.vars.current == as.vars.blockCount) {
							as.vars.current = 0;
							$(as.vars.bc).css("left","0px");
						}
					});
				}
				setTimeout("autoSlide.move()", as.vars.interval);
			}
		},
		"init": function() {
			var as = this;
			as.vars.blockCount = $(".ubytovaniNasTipBlock").length;
			if(as.vars.blockCount > 1) {
				var obsah = $(as.vars.bc+" "+as.vars.ibc+":first").html();
				$(as.vars.bc).append('<div class="'+as.vars.ibc.replace(".","")+'">'+obsah+'</div>');
			}
			$(as.vars.ibc).mouseenter(function(){
				as.vars.move = false;
			}).mouseleave(function(){
				as.vars.move = true;
			});
			setTimeout("autoSlide.move()", as.vars.interval);
		}
};
var slideShow = {
		"vars": {
			"current":0,
			"photos":["winter-11-01.jpg", "winter-11-02.jpg", "winter-11-05.jpg", "winter-11-03.jpg", "winter-11-04.jpg"],
			"cache":["", "", "", "", "", ""],
			"interval":5000
		},
		"slide": function() {
			var ss = this;
			if(ss.vars.current == (ss.vars.photos.length-1))
				ss.vars.current = 0;
			else
				ss.vars.current = ss.vars.current + 1;
			//alert(ss.vars.current);
			if(ss.vars.cache[ss.vars.current] != "") { // cache
				var source = ss.vars.cache[ss.vars.current];
				$("#sliderHolder img").before('<img src="'+source+'" alt="" />');
				$("#sliderHolder img:last").fadeOut(2000, function() {
					$("#sliderHolder img:last").remove();
				});
			}
			else { // new load
				var d = new Date();
				var img = new Image();
				var source = httpPath+"templates/lipensko/images/slide/"+ss.vars.photos[ss.vars.current]+"?t="+d.getTime();
				img.onload = function() {
					$("#sliderHolder img").before('<img src="'+source+'" alt="" />');
					$("#sliderHolder img:last").fadeOut(2000, function() {
						$("#sliderHolder img:last").remove();
					});
				}
				img.src = source;
				ss.vars.cache[ss.vars.current] = source;
			}
			setTimeout("slideShow.slide()", ss.vars.interval);
		},
		"init": function() {
			var ss = this;
			setTimeout("slideShow.slide()", ss.vars.interval);
		}
};
