var path = "/assets/images/menu/";
var path2 = "/img/buttons/";

$(document).ready(function(){
	jQuery.each(jQuery.browser, function(i) {
    	if($.browser.msie){
		$(" .navigation div.firstLevel table tr td:first-child, .footLink a:first-child")
			.css({ borderLeft:"0px" });
		$(".navigation div.firstLevel table tr td:last-child")
			.css({ backgroundColor:"#F8E7C0" });
		$(".secondLevel span:first-child")
			.css({ background:"none", paddingLeft:"0" });
		$(".jNiceSelectWrapper ul li:last-child")
			.css({borderBottom:"1px solid #9C7F52"});
		}
		
	});
	
});

//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//				     PopupSection					  +
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
function exClose(){
	$("#globWrap").html("");	
}
function ___createBlock(lang, id, captchaUrl){
		//russian
		if(lang == "ru"){
			var sender = "Отправитель";
			var addressee = "Получатель";
			var mailFrom = "E-mail отправителя";
			var mailTo = "E-mail получателя";
			var letter = "Текст открытки";
			var sendText = "Отправить";
			var captchaText = "Пожалуйста, введите код";
			var requiredText = "Все поля обязятельные";
		}
		//ukrainian
		else if(lang == "ua"){
			var sender = "Відправник";
			var addressee = "Отримувач";
			var mailFrom = "E-mail відправника";
			var mailTo = "E-mail отримувача";
			var letter = "Текст листівки";
			var sendText = "Надіслати";
			var captchaText = "Будь ласка, введіть код";
			var requiredText = "Всі поля обов&rsquo;язкові";
		}
		else if(lang == "de"){
			var sender = "Absender";
			var addressee = "Empfänger";
			var mailFrom = "Sender (E-mail)";
			var mailTo = "Adressat (E-mail)";
			var letter = "Text";
			var sendText = "Senden";
			var captchaText = "Bitte geben Sie Code ein";
			var requiredText = "obligatorische Felder zum Ausfüllen";
		}
		//default language
		else{
			var sender = "Sender";
			var addressee = "Recipient";
			var mailFrom = "From (e-mail)";
			var mailTo = "To (e-mail)";
			var letter = "Text";
			var sendText = "Send";
			var captchaText = "Please repeat code";
			var requiredText = "All fields are required";
		}
		text = '<div id="shWrapUp" onclick="exClose()"></div><table cellspacing="0" id="cardRoot"><tr><td class="bordLine"><img class="png" src="/img/popup_cards-0-0.png" width="13" height="19"></td><td class="cardSh10"><div style="height:19px;"></div></td><td><img class="png" src="/img/popup_cards-2-0.png" width="13" height="19"></td></tr><tr><td class="cardSh01"></td><td class="cardBody"><img style="//top:-5px;" class="close_button" onclick="exClose();" src="/img/close.gif" style="top:-10px;"><!-- BodySection --><h4 id="nameCard"></h4><div class="bigImg"><img src="" id="cardpixel" width="332" height="230" alt=""></div><div class="formGrad"><form action="' + location + '" method="POST" onSubmit="return submitVirtualCardsForm(this);"><input type="hidden" name="lang" value="' + lang + '"><input type="hidden" name="cardCaption" id="cardCaption"><input type="hidden" name="cardId" value="' + id + '"><table cellspacing="0" class="popForm"><tr><td class="padTd"><div><input type="text" value="' + sender + '" onclick="if(this.value==\'' + sender + '\') this.value=\'\'" onblur="if(this.value==\'\') this.value=\'' + sender + '\'; this.className=\'\';" name="sender"></div><div><input type="text" value="' + addressee + '" onclick="if(this.value==\'' + addressee + '\') this.value=\'\'" onblur="if(this.value==\'\') this.value=\'' + addressee + '\'; this.className=\'\';" name="recipient" onBlur="this.className=\'\';"></div></td><td><div><input type="text" value="' + mailFrom + '" onclick="if(this.value==\'' + mailFrom + '\') this.value=\'\'" onblur="if(this.value==\'\') this.value=\'' + mailFrom + '\'; this.className=\'\';" name="emailFrom"></div><div><input type="text" value="' + mailTo + '" onclick="if(this.value==\'' + mailTo + '\') this.value=\'\'" onblur="if(this.value==\'\') this.value=\'' + mailTo + '\'; this.className=\'\';" name="emailTo"></div></td></tr><tr><td colspan="2"><textarea name="message" cols="0" rows="0" onclick="if(this.value==\'' + letter + '\') this.value=\'\'" onblur="if(this.value==\'\') this.value=\'' + letter + '\'; this.className=\'\';">' + letter + '</textarea></td></tr></table><div style="float:left;height:23px;padding-top:4px;"><img src="' + captchaUrl + '" style="border:1px solid #9C7F52;width:75px;height:15px;margin-left:3px;"> <input type="text" name="captcha" style="background:#FFFFFF none repeat scroll 0 0;border:1px solid #9C7F52;color:#18226E;font-size:1em;padding:1px 3px;width:69px;"></div><div style="float:right;"><input type="image" src="/img/buttons/submit_' + lang + '.gif" title="' + sendText + '" alt="' + sendText + '"></div></form></div><span style="float:left;padding:0 0 0 8px;clear:both;">' + captchaText + '</span><span class="notes" style="float:right;padding:0 8px 0 0;">' + requiredText + '</span><!-- EndBodySection --></td><td class="cardSh21"></td></tr><tr><td><img class="png" src="/img/popup_cards-0-2.png" width="13" height="17"></td><td class="cardSh12"><div style="height:17px;"></div></td><td><img class="png" src="/img/popup_cards-2-2.png" width="13" height="17"></td></tr></table>';
		return text;
	}
function ___getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}
function ___winSize(){
	var myWidth = 0, winHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}
	arrayWinSize = new Array(winWidth,winHeight);
	return arrayWinSize;
}
function ___docSize(){
	if(document.getElementById("root")){
		docHeight = parseInt(document.getElementById("root").offsetHeight);
		docWidth = parseInt(document.getElementById("root").offsetWidth);
		arrayDocSize = new Array(docWidth,docHeight);
	}
	return arrayDocSize;
}
jQuery(function() {
	$("a.python").click(function(){
		___getPageScroll();
		var ScrY = arrayPageScroll[1];
		___winSize();
		var winWidth = arrayWinSize[0];
		var winHeight = arrayWinSize[1];
		var bigimg = $(this).attr("href");
		var toCache  = new Image(); toCache.src = bigimg;
		var title = $(this).attr("title");
		var lang = $(this).attr("lang");
		var captchaUrl = $(this).attr("captcha");
		var cardId = $(this).attr("cardId");
		var rootWidth = $(".share").width();
		var rootHeight = $(".share").height() + 60;
		if(winWidth >= rootWidth){
			maxWidth = winWidth;
		}
		else{
			maxWidth = rootWidth;
		}
		if(winHeight >= rootHeight){
			maxHeight = winHeight;
		}
		else{
			maxHeight = rootHeight;
		}
		___createBlock(lang, cardId, captchaUrl);
		$("#globWrap").html(text);
		$("#cardpixel").attr({"src": bigimg});
		$("#shWrapUp").css({width:maxWidth - 20 + "px", height:maxHeight + "px"}); 
		$("#nameCard").html(title);
		$("#cardCaption").val(title);
		upH = $("#cardRoot").height();
		upW = $("#cardpixel").width();
		$("#cardRoot").css({top:parseInt(ScrY + winHeight/2 - upH/2) + "px", left:parseInt(winWidth/2 - upW/2) + "px"});
		$("#cardRoot").css({ display: "none", visibility:"visible"});
		$("#cardRoot").fadeIn("fast");
		return false;
	});
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//				     GallerySection				      +
//+++++++++++++++++++++++++++++++++++++++++++++++++++++



//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//				     NavigationSection				  +
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
function changeChildrenImage(parent, imageSource){
	if (parent.childNodes[0].nodeName.toLowerCase() == 'img')
		parent.childNodes[0].src = imageSource;
	else
		parent.childNodes[1].src = imageSource;
}
jQuery(function() {
	//left bookmarks
	$(".bookmarks span").hover(
		function(){
			var open = $(this).attr("class");
			if(open == "clicker"){
				return;
			}
			$(this).css({background:"#977849"});
		},
		function(){
			var open = $(this).attr("class");
			if(open == "clicker"){
				return;
			}
			$(this).css({background:"#A68E6C"});
		}
	);
	$(".bookmarks span").click(function(){
		//$("#ui-datepicker-div").css({visibility:"hidden"});
		var open = $(this).attr("class");
		if(open == "clicker"){
			return;
		}
		
		if(document.getElementById('palm')){
			oldImg = $("img#palm").attr("src");
			pathOld = oldImg.substring(oldImg.lastIndexOf("/")+1, oldImg.lastIndexOf("_."));
			$("img#palm").attr({"src": path2 + pathOld + ".gif", "id": ""});
		}
		target = $(this).attr("name");
		$("span[name='"+ target +"'] img").attr({"id":"palm"});
		srcImg = $("img#palm").attr("src");
		pathImg = srcImg.substring(srcImg.lastIndexOf("/")+1, srcImg.lastIndexOf("."));
		$("img#palm").attr({"src": path2 + pathImg + "_.gif"});
		$(".bookmarks span").removeClass("clicker").css({background:"#A68E6C"});
		$(this).addClass("clicker").css({background:"#977849"});
		$(".formbox > *").css({ display:"none" });
		$("#" + target).css({ display:"block" });
	});
	$("#calOut").click(function(){
		var bla = document.getElementById('datepickerOut');
		try {
			bla.focus();
		}
		catch(err) {
		}
	});
	$("#calIn").click(function(){
		var bla = document.getElementById('datepickerIn');
		try {
			bla.focus();
		}
		catch(err) {
		}
	});
	$("#calOrder0").click(function(){
		var bla = document.getElementById('oder0');
		try {
			bla.focus();
		}
		catch(err) {
		}
	});
	$("#calOrder1").click(function(){
		var bla = document.getElementById('oder1');
		try {
			bla.focus();
		}
		catch(err) {
		}
	});
	$("#Form0").click(function(){
		var bla = document.getElementById('dateForm0');
		try {
			bla.focus();
		}
		catch(err) {
		}
	});
	$("#Form1").click(function(){
		var bla = document.getElementById('dateForm1');
		try {
			bla.focus();
		}
		catch(err) {
		}
	});
	$("#Form2").click(function(){
		var bla = document.getElementById('dateForm2');
		try {
			bla.focus();
		}
		catch(err) {
		}
	});
	$("#Form3").click(function(){
		var bla = document.getElementById('dateForm3');
		try {
			bla.focus();
		}
		catch(err) {
		}
	});
	$("#Form4").click(function(){
		var bla = document.getElementById('dateForm4');
		try {
			bla.focus();
		}
		catch(err) {
		}
	});
});

function excl(){
	//$("#flashSlot").html("");
	//$("#wrapperFlash").fadeOut("fast");
	$("#wrapperFlash, #flashSlot").remove();
}


function __flashBlock(pdfDoc){
	___getPageScroll();
	___winSize();
	___docSize();
	// arrayWinSize; arrayPageScroll; arrayDocSize
	if(arrayWinSize[0] > arrayDocSize[0]){
		workWidth = arrayWinSize[0] - 50;
	}else{
		workWidth = arrayDocSize[0];
	}
	if(arrayWinSize[1] > arrayDocSize[1]){
		workHeight = arrayWinSize[1];
	}else{
		workHeight = arrayDocSize[1];
	}
	var flashWidth = parseInt(document.getElementById(pdfDoc).offsetWidth);
	var flashHeight = parseInt(document.getElementById(pdfDoc).offsetHeight);
	var flashBorder = flashWidth + 26;
	//var wrapBox = '<div id="wrapperFlash" style="width:' + workWidth + 'px; height:'+ workHeight+ 'px;" onclick="excl()\;"></div><div id="flashSlot" style="width:' + flashWidth + 'px; height:'+ flashHeight+ 'px;"></div>';
	var wrapBox = '<div id="wrapperFlash" style="width:' + workWidth + 'px; height:'+ workHeight+ 'px;" onclick="excl()\;"></div><div id="flashSlot" style="width:' + flashBorder + 'px; height:'+ flashHeight+ 'px;"><table cellspacing="0" id="cardRoot"><tr><td class="bordLine"><img class="png" src="/img/popup_cards-0-0.png" width="13" height="19"></td><td class="cardSh10"><div style="height:19px;"></div></td><td><img class="png" src="/img/popup_cards-2-0.png" width="13" height="19"></td></tr><tr><td class="cardSh01"></td><td class="cardBody" id="pdf_body" style="width:'+ flashWidth +'px;"></td><td class="cardSh21"></td></tr><tr><td><img class="png" src="/img/popup_cards-0-2.png" width="13" height="17"></td><td class="cardSh12"><div style="height:17px;"></div></td><td><img class="png" src="/img/popup_cards-2-2.png" width="13" height="17"></td></tr></table></div>';
	$("body").append(wrapBox);
	var margTop = parseInt((arrayWinSize[1]/2) + arrayPageScroll[1] - (flashHeight/2)) - 20;
	var margLeft = parseInt((arrayWinSize[0]/2) + arrayPageScroll[0] - (flashWidth/2)) - 20;
	$("#flashSlot").css({top:margTop + "px", left:margLeft + "px"});
	$("#" + pdfDoc).clone().appendTo("#pdf_body").css({visibility:"visible"});
}

function resizeFlash(){
	___getPageScroll();
	___winSize();
	___docSize();
	if(arrayWinSize[0] > arrayDocSize[0]){
		workWidth = arrayWinSize[0] - 50;
	}else{
		workWidth = arrayDocSize[0];
	}
	if(arrayWinSize[1] > arrayDocSize[1]){
		workHeight = arrayWinSize[1];
	}else{
		workHeight = arrayDocSize[1];
	}
	var flashWidth = parseInt(document.getElementById("flashSlot").offsetWidth);
	var flashHeight = parseInt(document.getElementById("flashSlot").offsetHeight);
	//alert('ap');
	var margTop = parseInt((arrayWinSize[1]/2) + arrayPageScroll[1] - (flashHeight/2)) - 20;
	var margLeft = parseInt((arrayWinSize[0]/2) + arrayPageScroll[0] - (flashWidth/2)) - 20;
	$("#flashSlot").css({top:margTop + "px", left:margLeft + "px"});
}

$(window).resize(function(){
	if(document.getElementById("wrapperFlash") && document.getElementById("flashSlot")){
		resizeFlash();
	}
});

//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//				     VirtualTour     			      +
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
var virtWidth = 166;
var imageCount = 0;
var step_switch = 1;
function aniFWD(){
	if(step_switch == 0){
		return false;	
	}
	step_switch = 0;
	$("#max_scroll").animate({marginLeft:"-166px"}, 300);
	setTimeout("step_switch = 1",500)
}

function aniBack(){
	if(step_switch == 0){
		return false;	
	}
	step_switch = 0;
	$("#max_scroll").animate({marginLeft:"+166px"}, 300);
	setTimeout("step_switch = 1",500)
}

function virtualTour(dir){
	if(document.getElementById("max_scroll")){
		var lineNode = document.getElementById("max_scroll");
		var qElements = $("#max_scroll img").length;
		var maxLimit = qElements*virtWidth-virtWidth;
		var leftPosition =  parseInt(document.getElementById("max_scroll").style.marginLeft);
		if(dir == "fwd"){
			if(leftPosition == -maxLimit){
				$(lineNode).css({marginLeft:"0"});
				imageCount = 0;
			}
			aniFWD();
			imageCount = ++imageCount;
		}
		else{
			if(leftPosition == 0){
				$(lineNode).css({marginLeft:-maxLimit + "px"});
				imageCount = qElements - 1;
			}
			aniBack();
			imageCount = --imageCount;
		}
		var imgHref = $("#" + imageCount).attr("alt");
		$("#targetLink").attr({href:imgHref});
		
	}
}
function trim(string){
	return string.replace(/(^\s+)|(\s+$)/g, "");
}

function submitVirtualCardsForm(form){
	var fields = new Array('sender','recipient','emailFrom','emailTo');
	for (var i in fields){
		if (trim(form[fields[i]].value) == ''){
			form[fields[i]].className = 'error';
			return false;
		}
	}
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	if(!emailRegExp.test(form.emailFrom.value)){
		form.emailFrom.className = 'error';
		return false;
	}
	if(!emailRegExp.test(form.emailTo.value)){
		form.emailTo.className = 'error';
		return false;
	}
}

document.onmousedown = function(ev) {
    var ev = ev || window.event;
    var target = ev.target || ev.srcElement;
	var a = document.getElementById('fly_list');
    if(a) {
		if(target.getAttribute('id') != "roomsQuestionToggler"){
			document.getElementById('fly_list').style.display = 'none';
		}
    }
}

function roomsSeasonChange(seasonId) {
	$("div.nntext div").hide();
	$("div.nntext div[seasonId='" + seasonId + "']").show();
}

function roomsCurrencyChange(name, rate) {
	var rate = parseFloat(rate);
	$("div.nntext div strong").each(function() {
		if (rate == 1) {
            val = parseFloat($(this.parentNode.parentNode).find("span").text());
        } else {
            val = parseFloat(this.innerHTML);
            if (val != 0) {
                val /= roomsCurrentRate;
                val *= rate;
                val = Math.ceil(val);
            }
        }
		this.innerHTML = val + " " + name;
	});
	roomsCurrentRate = rate;
}

