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 #206a33"});
		}
		
	});

    otherLang();
	
});

//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//				     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;язкові";
		}
		//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 a").hover(
		function(){
			var open = $(this).attr("class");
			if(open == "clicker"){
				return;
			}
			$(this).css({background:"#206a33"});
		},
		function(){
			var open = $(this).attr("class");
			if(open == "clicker"){
				return;
			}
			$(this).css({background:"#65a275"});
		}
	);
	$(".bookmarks a").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");
		$("a[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 a").removeClass("clicker").css({background:"#65a275"});
		$(this).addClass("clicker").css({background:"#206a33"});
		$(".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>';*/
	
	var divWr = document.createElement("DIV");
		divWr.id = "wrapperFlash";
		divWr.setAttribute("style" , "width:" + workWidth + "px; height:" + workHeight + "px;");
		divWr.setAttribute("onclick" , "excl();");
		
	var divSlot = document.createElement("DIV");
		divSlot.id = "flashSlot";
		divSlot.style.width = flashBorder + "px";
		divSlot.style.height = flashHeight + "px";
		
	var tbl = document.createElement("table");
		tbl.setAttribute("cellspacing" , "0");
		tbl.cellspacing = "0"
		tbl.id = "cardRoot";
		if(window.navigator.userAgent.indexOf("MSIE")>=0){
			tbl.style.border="1px solid #cccccc";
			tbl.style.backgroundColor = "#ffffff";
		}
		
		
	var tblBody = document.createElement("tbody");
	
	for (var j = 0; j < 3; j++) {
		var row = document.createElement("tr");

		for (var i = 0; i < 3; i++) {
			var cell = document.createElement("td");
			if(window.navigator.userAgent.indexOf("MSIE")<0){
				if(j==0){
					switch (i) {
					case 0:
						cell.className = "bordLine";
						cell.width = "13";
						cell.height = "19";
						var child = document.createElement("img");
							child.setAttribute("src" , "/img/popup_cards-0-0.png");
							child.setAttribute("class" , "png");
							child.setAttribute("width" , "13");
							child.setAttribute("height" , "19");
							cell.appendChild(child);
						break;
					case 1:
						cell.className = "cardSh10";
						cell.height = "19";
						var child = document.createElement("div");
							child.setAttribute("style" , "height:19px;");
							cell.appendChild(child);
						break;
					case 2:
						cell.width = "13";
						cell.height = "19";
						var child = document.createElement("img");
							child.setAttribute("src" , "/img/popup_cards-2-0.png");
							child.setAttribute("class" , "png");
							child.setAttribute("width" , "13");
							child.setAttribute("height" , "19");
							cell.appendChild(child);
						break;
					}
				}
				else if(j==1){
					switch (i) {
					case 0:
						cell.className = "cardSh01";
						break;
					case 1:
						cell.className = "cardBody";
						cell.id = "pdf_body";
						cell.style.width = flashWidth +"px";
						break;
					case 2:
						cell.className = "cardSh21";
						break;
					}
				}
				else if(j==2){
					switch (i) {
					case 0:
						var child = document.createElement("img");
							child.setAttribute("src" , "/img/popup_cards-0-2.png");
							child.setAttribute("class" , "png");
							child.setAttribute("width" , "13");
							child.setAttribute("height" , "17");
							cell.appendChild(child);
						break;
					case 1:
						cell.className = "cardSh12";
						var child = document.createElement("div");
							child.setAttribute("style" , "height:17px;");
							cell.appendChild(child);
						break;
					case 2:
						var child = document.createElement("img");
							child.setAttribute("src" , "/img/popup_cards-2-2.png");
							child.setAttribute("class" , "png");
							child.setAttribute("width" , "13");
							child.setAttribute("height" , "17");
							cell.appendChild(child);
						break;
					}
				}
			}else{
				if(j==1 && i==1){
					cell.className = "cardBody";
					cell.id = "pdf_body";
					cell.style.width = flashWidth +"px";
					cell.style.padding = "5px 10px 10px";
				}
			}
			
			
			row.appendChild(cell);
			
		//	// Create a <td> element and a text node, make the text
		//	// node the contents of the <td>, and put the <td> at
		//	// the end of the table row
		//	var cell = document.createElement("td");
		//	var cellText = document.createTextNode("cell is row "+j+", column "+i);
		//	cell.appendChild(cellText);
		//	row.appendChild(cell);
		}

		// add the row to the end of the table body
		tblBody.appendChild(row);
    }

	
	
	// put the <tbody> in the <table>
        tbl.appendChild(tblBody);
        // appends <table> into <body>
        divSlot.appendChild(tbl);
		
	document.body.appendChild(divWr);
	document.body.appendChild(divSlot);
	//$("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"});
	var code = document.getElementById(pdfDoc).innerHTML;
	//alert(code);
	document.getElementById("pdf_body").innerHTML = code;
	document.getElementById("pdf_body").style.visibility = "visible";
	//$("#" + 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);
    var val;
	$("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;
}

function otherLang(){
	
	if(document.getElementById('other_lang')){
		var clickZone = document.getElementById('other_lang');
		var langList = document.getElementById('lang_list');
		$(clickZone).click(function(){
			if(langList.style.overflow != 'visible'){
				langList.style.overflow = 'visible';
			}
		});
		$(document).mouseup(function(){
			if(langList.style.overflow == 'visible'){
				langList.style.overflow = 'hidden';
			}
		}); 
	}
}



