/* <![CDATA[ */
var promoSettings = new Array();
var blurText = "";
var firstFocus = true;
// carousel variables/settings
var eType = 0;
var FADE_SPEED = 2000;
var TRANSITION_SPEED = 5000;
var imgWidth = 605;
var slideImgWidth = "-605px";
var imgHeight = "";
var opacity = "0.15";
var thumbWidth = "50px";
var thumbHeight = "50px";
var isHomepage;
var newHeight;
var propSelect = "#Property_ReservationBoxForm";
var propCity = "#City_ReservationBoxForm";
var crumbsHotelName = "";
var crumbsCityName = "";
// JavaScript Document

var controllerFunction ="";
var gseconds = new Array();
var timearray = new Array();
var inprogress = false;

var carouselWidth = "720";
var carouselHeight = "329";

function SelectDropDownById(jvarId, jvarValue, jvarByText)
{
	var objField = document.getElementById(jvarId);
	SelectDropDown(objField, jvarValue, jvarByText);
}

function SelectDropDown(field, value, byText){
    try {    
        for (var i = 0; i < field.length; i++) {
            if (byText==true) {
                if (field.options[i].text == value)
                    field.options[i].selected = true
                else
                    field.options[i].selected = false
            } else {
                if (field.options[i].value == value)
                    field.options[i].selected = true
                else
                    field.options[i].selected = false
            }
        } // End For
    } catch ( e1 ) {
    }
}

$(function() {
	
	if($("#primaryMenu").length > 0 )
		$("<a name=\"top\" class=\"toplink\"></a>").insertAfter("#primaryMenu");
		
	var elemSearch = $("#searchVal");
	var tempSearch = $("#searchVal").val();
	
	elemSearch.addClass("idle");
	elemSearch.focus(function(){
		if($(this).val() == tempSearch)
			$(this).val("");
			elemSearch.removeClass("idle");
	}).blur(function(){
		if($(this).val() == "") {
			$(this).val(tempSearch);
			elemSearch.addClass("idle");
		}	
	});	
	
	var elemOpt = $("#Promo_ReservationBoxForm");
	var tempOpt = $("#Promo_ReservationBoxForm").val();
	
	var defaultOpt = "Optional";
	
	elemOpt.addClass("idle");
	elemOpt.focus(function(){
		if($(this).val() == tempOpt) {
			if(tempOpt.toLowerCase() != "optional")
				$(this).attr("value",tempOpt);
			else
				$(this).attr("value","");
		}
		elemOpt.removeClass("idle");
	}).blur(function(){
		if($(this).val() == "" && tempOpt.toLowerCase() != "optional") {
			$(this).attr("value",defaultOpt+"");
			//$(this).val(tempOpt);
			elemOpt.addClass("idle");
		}	
	});	
	
	if($("#galleria li").length > 6) {
		$('<p id="up">Up</p>').insertBefore('#prop-carousel .content');
		$('<p id="dn">Down</p>').insertAfter('#prop-carousel .content');
		$("p#dn").bind("mousedown", function(){ var tempVal = $("div.content").height() - $(".thumbs").height(); $(".thumbs").animate({ top: tempVal }, 500 ); });
		$("p#up").bind("mousedown", function(){ $(".thumbs").animate({ top: "0px" }, 500 ); });
		$("#prop-carousel .content").removeClass("thumbs-only");
	}
	
	if($("#galleria").length > 0)
		if(!isHomepage)
			$("<div id=\"imageViewer\"></div>").insertBefore("#prop-carousel .content");
		
	//Photo Gallery - lightBox init
	try {
		$(".prop-gallery a").lightBoxDefault({
			imageLoading: '/common/images/lightbox/lightbox-ico-loading.gif',
			imageBtnClose: '/common/images/lightbox/lightbox-btn-close.gif',
			imageBtnPrev: '/common/images/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/common/images/lightbox/lightbox-btn-next.gif'
		}); //end
	} catch(e){}
	try {
		$("#galleria a").lightBox({
			imageLoading: '/common/images/lightbox/lightbox-ico-loading.gif',
			imageBtnClose: '/common/images/lightbox/lightbox-btn-close.gif',
			imageBtnPrev: '/common/images/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/common/images/lightbox/lightbox-btn-next.gif'
		}); //end Photo Gallery
	} catch(e){}
	try {
		$("#ascottBrands ul a").lightBox();
	} catch(e){}
	
	
	$("#galleria").show(); //JS-On show Galleria
	$("#prop-carousel #banner").hide(); //JS-Off hide Banner
		
	if(isHomepage) { 
		$('#galleria').carouFredSel({
			circular 		: true,
			pagination		: "#page-controls",
			items 			: { 
				visible 	: 1,
				width		: carouselWidth,
				height		: carouselHeight
			},
			auto 			: {
				fx			: "crossfade"
			},
			scroll			: {
				fx			: "crossfade",
				duration	: 1200	
			}
		});	
	}
	
	
	else { 
		e_carousel = $("#galleria img").length; 
		showImage($("#galleria img:first"),0);
		
		$("#control li span").click(function() {
			
			var myDate = new Date();
			gseconds += myDate.getTime() + "," ;
			timearray = gseconds.split(",");	
			if (timearray.length > 2 ){
			var lastvalue =timearray[timearray.length-2];
			var prevlast = timearray[timearray.length-3];
			var diff = lastvalue  - prevlast ;
			var diffseconds = diff/1000 ;
				if(diffseconds < 2){
					inprogress = true;
				}else{
					inprogress = false;
				}
			}			
			var imageSource = $("#galleria li img").eq($("#control li span").index(this));
			
			if(inprogress == false){	
			clearTimeout(timer);	
			showImage(imageSource,1);
			}
			return false;
		});
	
		$("#galleria a").click(function() {
			
			var myDate = new Date();
			gseconds += myDate.getTime() + "," ;
			timearray = gseconds.split(",");	
			if (timearray.length > 2 ){
			var lastvalue =timearray[timearray.length-2];
			var prevlast = timearray[timearray.length-3];
			var diff = lastvalue  - prevlast ;
			var diffseconds = diff/1000 ;
				if(diffseconds < 2){
					inprogress = true;
				}else{
					inprogress = false;
				}
			}			
			var imageSource = $(this).children("img");
			
			if(inprogress == false){	
			clearTimeout(timer);	
			showImage(imageSource,1);
			}
			return false;
		});
	}
	
	
	
	//Crossbranding BlockUI
	try {
	$(".crossBrands ul").children("li").each(function() {
		var getClass = $(this).attr("class");
		$(this).find("a.link").attr("content",$("#ascottBrands div."+getClass).html()); 
		$(this).find("a.link").attr("href",$("#ascottBrands span."+getClass).find("img.hBanner").attr("src"));
	});
	
	$(".crossBrands ul a").lightBoxInit({
		imageLoading: '/common/images/lightbox/lightbox-ico-loading.gif',
		imageBtnClose: '/common/images/lightbox/lightbox-btn-close.gif',
		imageBtnPrev: '/common/images/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: '/common/images/lightbox/lightbox-btn-next.gif'
	}); //end Photo Gallery
	}
	catch(e) {}
	
	//virtual tour
	$(".vtour img").bind("click",function(){
		$.blockUI({ 
			message:$(this).next().html(),
			css: { cursor: 'default', border:'8px #FFF solid', background: '#fff', width: 'auto', height: 'auto' },
			overlayCSS: { cursor: 'default' }
		});
		$('.blockUI.blockMsg').addClass('vtour');
		$('.blockUI.blockMsg').center();
		return false;
	});
	
	$("body").click(function(event){
	if($(event.target).is(".blockUI-close")){$.unblockUI();	}
	});
	 //$("body").click(function() { $.unblockUI();	});//currently commented it by khaing
	$(window).resize(function() { try { $('.blockUI.blockMsg').center();$('.blockUI.blockMsg') } catch(e){} });
	$("#languageBar ul li:not(.current,.one)").css("display" , "none");
	
	if(isMobile && $("#languageBar ul li").length <= 1) $("#languageBar").hide();	
	if(!isMobile){
		$("#languageBar ul li").mouseover(function() { $("#languageBar ul li").siblings().show(); });
		$("#languageBar ul li").mouseout(function() { $("#languageBar ul li").siblings().hide(); $("#languageBar ul li.current").show(); });
	}
	//$("#member-login").mouseover(function() { $("#member-login").addClass("member-login-hover");$("#member-login #member-login-select").show(); });
	//$("#member-login").mouseout(function() { $("#member-login").removeClass("member-login-hover");$("#member-login #member-login-select").hide(); $("#member-login li.current").show(); });
	
	//Other Properties Show/Hide Toggle 
	$(".tab-function > li div.content").hide(); $(".tab-function li").eq(0).find("div.content").show();
	$("ul.tab-function").css("height",$(".tab-function > li.current").find("div.content").height()+50); //onload set height of tab content
	
	$(".tab-function li h5").click(function() {  
		$(".tab-function > li").removeClass("current"); 
		$(".tab-function > li div.content").hide(); 
		$(this).next("div.content").show();
		$(this).parent().addClass("current");
	
		newHeight = $(this).next("div.content").height()+50;
		$("ul.tab-function").css("height",newHeight);
		 
	});
	//End Other Properties Show/Hide Toggle

	try {
		$(".pop-up").popupWindow({ centerScreen:1, width:850, height:630, scrollbars:1, location:0 }); //popup for Interactive Map;
		$(".corp-pop").popupWindow({ centerScreen:1, width:750, height:500, scrollbars:1, location:0 }); //popup for Corporate Login
		$(".pop-cancel-policy").popupWindow({ centerScreen:1, width:400, height:500, scrollbars:1, location:0 }); //popup for Guarantee and Cancellation Policy		
		$(".pop-currency").popupWindow({ centerScreen:1, width:430, height:400, scrollbars:1, location:0 }); //popup for Currency Converter
		$(".pop-disclaimer").popupWindow({ centerScreen:1, width:300, height:370, scrollbars:1, location:0, windowName:'Disclaimer' }); //popup for Disclaimer
		$(".pop-video").popupWindow({ centerScreen:1, width:470, height:335, scrollbars:0, location:0 }); //popup for Video
	}
	catch(e) {}
	
	//this script will get the values from array built in jasmine component and will apply the necessary CSS/STYLES
	//Settings are stored and controlled by user with Article Subform
	var offsetTop = "";
	var panelBtn = "";
	var panelBg = "";
	var element = "#propPromo";
	
	if(promoSettings.length > 0) {
		if(isHomepage)
		element = "#home-panel";
		for(i=0; i<=promoSettings.length; i++) {
			try {
				offsetTop= promoSettings[i][0];
				panelBtn = "url(\"" + promoSettings[i][1] + "\") no-repeat 200px";
				panelBg = promoSettings[i][2];
				if(panelBg != "") {
					$(element +" li").eq(i).find("h4").css("background","none");
					$("<div class=\"BG\" style=\"background:"+panelBg+"; \"></div>").insertBefore($(element +" li").eq(i).find("h4"));
					$(element +" li").eq(i).find("div.BG").css("top",offsetTop+"px");
					$(element +" li").eq(i).find("h4").css("top",offsetTop+"px"); //apply top position
					$(element +" li").eq(i).find("h4 a").eq(i).css("background",panelBtn); //apply image link
				}
				
			}
			catch(e){}
		}
	}
	
	//$(".testimonials span.read-more").click(function() { $(this).next().toggle(); });
	$(".testimonials span").click(function(){
		$(this).next(".body").slideDown();
		$(this).hide();
	});
	
	//add class "last" to the last item of specific lists
	$("#primaryMenu ul li:first").addClass("first");
	$("#primaryMenu ul li:last").prev().addClass("last");
	$("#ascottBrands ul li:last").addClass("last");
	$(".crossBrands-ascott-links li:last").addClass("last");
	$("#legalDisclaimer ul li:last").addClass("last");
	$("#home-panel li:last").addClass("home-panel-last");
	
	$("#subscribe-email").focus(function() {
		if(firstFocus) blurText = $(this).val();
		if(blurText == $(this).val()) $(this).val("");
		firstFocus = false;
	});
	$("#subscribe-email").blur(function() { if($(this).val() == "") $(this).val(blurText); });
});	

$.fn.center = function () {
	this.css("position","absolute");
	this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
	this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
	return this;
}

function showImage(src,clickFlag) { //start showImage
	var largeImage = new Image();
	$(largeImage).load(function() { //load bind
		$(this).hide().addClass('homegalleryPic');
		$("#imageViewer").append(this); //append new image

		if(eType == '0') { // IF FADE EFFECT
			$(this).fadeIn(FADE_SPEED, function() { //fade in 		
				if(!isHomepage) {
					$("#imageViewer img").attr('alt',$("#galleria img").eq(c).attr("alt")); $("#imageViewer img").attr('title',$("#galleria img").eq(c).attr("alt")); 
				}
		
			if($("#imageViewer img").length >1) $("#imageViewer img:first").remove();
			if($("#imageViewer #detailContainer").length >1) $("#detailContainer").remove();
			
				if(!isHomepage) {
					if( e_carousel-1 > c ) { c++; timer = setTimeout('showImage($("#galleria img:eq('+ c +')"),0)',TRANSITION_SPEED); }
					else { c=0; timer = setTimeout('showImage($("#galleria img:first"),0)', TRANSITION_SPEED); } 
				}
			
			}); //end fade in 
		}// end IF FADE EFFECT 	
	}); //end load bind   
	
	if(!isHomepage) {
		$(largeImage).attr("src", src.parent().attr("href"));
		src.parent().parent().parent().find("li").each(function(){ $(this).attr("class","thumb") });
		src.parent().parent().attr("class","thumb-active");
		$("#imageViewer").unbind('click').click(function(){ src.trigger('dblclick'); });
		var c = $("#galleria img").index(src);
	}
} //end showImage

function PopupNewWindow(pageURL) {
	var url = pageTracker._getLinkerUrl(pageURL);
	window.open(url,'','scrollbars=yes,menubar=yes,resizable=yes,width=800,height=600,titlebar=yes,toolbar=yes,top=0,left=0,location=yes');
} //from Old Citadines - Temp


function switchDIV(jvarDIV, jvarDIV2) {
	var divOne = document.getElementById(jvarDIV);
	var divTwo = document.getElementById(jvarDIV2);
		
	divOne.style.display = "none";
	divTwo.style.display = "block";
}

function parseURLParam() {
	var temp=location.href;
	if(temp.indexOf("?")>0){
		temp=temp.substr(temp.indexOf("?")+1,temp.length);
	var parArrayTemp=temp.split('&');
	var parArray=new Array();
		for(var i=0; i<parArrayTemp.length;i++){
		parArray.push(parArrayTemp[i].split('='));
		}
		return parArray;
	}
	else return "";

} //end parseURLParam
/* ]]> */
