
var animating = false;
var originalImage;
var originalOffset;
var nImage;

function startup() {
	//List functions to be run on startup here:
	externalLinks();	
	//sIFRreplace();	
}


function createjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", filename);
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", filename);
 }
 return fileref
}

function removejscssfile(filename, filetype){
 var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none"; //determine element type to create nodelist from
 var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none"; //determine corresponding attribute to test for
 var allsuspects=document.getElementsByTagName(targetelement);
 for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
  if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1){
   allsuspects[i].parentNode.removeChild(allsuspects[i]);
   } //remove element by calling parentNode.removeChild()
 }
}

function replacejscssfile(oldfilename, newfilename, filetype){
 var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none"; //determine element type to create nodelist using
 var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none"; //determine corresponding attribute to test for
 var allsuspects=document.getElementsByTagName(targetelement);
 for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
  if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(oldfilename)!=-1){
  //alert("found!!");
   var newelement=createjscssfile(newfilename, filetype);
   allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i]);
  }
 }
}

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", filename);
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", filename);
 }
 if (typeof fileref!="undefined"){
    document.getElementsByTagName("head")[0].appendChild(fileref);
  }
}


function createCookie(name,value,days){
	if (days){
		var date=new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires="; expires="+date.toGMTString();
	} else {var expires="";}
	document.cookie=name+"="+value+expires+"; path=/";
}

function readCookie(name){
	var nameEQ=name+"=";
	var ca=document.cookie.split(';');
	for(var i=0;i<ca.length;i++){
		var c=ca[i];
		while(c.charAt(0)==' '){c=c.substring(1,c.length);}
		if(c.indexOf(nameEQ)==0){ return c.substring(nameEQ.length,c.length);}
	}
	return null;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}

// Open links in external window for XHTML 1.0 Strict compliancy
// To make a link open in external window add the "rel" attribute to the <a> tag
// and set its value to "external" example:
//     <a href="http://www.google.com" rel="external">Google</a>
function externalLinks() {
	if (!document.getElementsByTagName){ return;}
	var anchors = document.getElementsByTagName("a");
	var areas = document.getElementsByTagName("area");
	var forms = document.getElementsByTagName("form");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external"){
		    anchor.target = "_blank";
		}
	}
	for (var x=0; x<areas.length; x++) {
		var area = areas[x];
		if (area.getAttribute("href") &&
		area.getAttribute("rel") == "external"){
		    area.target = "_blank";
		}
	}
	for (var y=0; y<forms.length; y++) {
		var form = forms[y];
		if (form.getAttribute("rel") == "external"){
		    form.target = "_blank";
		}
	}
}

function dropDown(menu,fa) {
	var myMenu = document.getElementById(menu);
	
	if(fa == 'appear') {
		new Effect.Appear(myMenu,{duration:0.3});
	} else if(fa == 'fade') {
		new Effect.Fade(myMenu,{duration:0.5});
	}
}

function sHover(elem,e) {
	thisId = elem.nextSibling.id.substr(7,elem.nextSibling.id.length);
	
	if(document.getElementById("sNavOn"+thisId).style.left != '10px') {
		if(e == "on") {
			elem.parentNode.style.background = "url('http://gaia/hardrockhotelcorporate/website/images/side_hover.gif') left top no-repeat";
		} else if(e == "off") {
			elem.parentNode.style.background = "";
		}
	} else {
		if(e == "on") {
			elem.style.cursor = 'default';
		} else if(e == "off") {
			elem.style.cursor = 'pointer';
		}
	}
}

function leftNavHide(elID){
    if(elID == "ONlocation") elID = "ONlocation/map";
    document.getElementById(elID).style.left = "-5000px";
}
function leftNavShow(elID){
    if(elID == "OFFlocation") elID = "OFFlocation/map";
    document.getElementById(elID).style.left = "10px";
}


function leftnavclick(clickedID)
{

if(clickedID == "location"){ clickedID = "location/map"};
if(currentID == "location"){ currentID = "location/map"};

document.getElementById('ON' + currentID).style.left = "10px"; 
document.getElementById('OFF' + currentID).style.left = "-5000px";
document.getElementById('ON' + clickedID).style.left = "-5000px"; 
document.getElementById('OFF' + clickedID).style.left = "10px"; 
currentID = clickedID; 
}






function openMenu(elem,stat) {
	var menuElem = document.getElementById(elem);
	
	switch(stat) {
		case 'on':
			menuElem.style.display = 'block';
			break;
		case 'alive':
			menuElem.style.display = 'block';
			break;
		case 'off':
			menuElem.style.display = 'none';
			break;
	}
	
}




function checkAvailability(theForm) {
	var formElem = document.getElementById('availability_form');
	var arrival = document.getElementById('arrival');
	var departure = document.getElementById('departure');
	var num_rooms = document.getElementById('rooms').value;
	var num_adults = document.getElementById('adults').value;
	var num_children = document.getElementById('children').value;
	
	var errors = 0;
	var message = "There were errors in your submission:\n\n";
	
	if(arrival.value == 'MM-DD-YY') {
		errors = 1;
		message+= "- You did not choose an arrival date\n";
	}
	if(departure.value == 'MM-DD-YY') {
		errors = 1;
		message+= "- You did not choose a departure date\n";
	}
	if(errors == 0) {
		a_month = arrival.value.split('-')[0];
		a_day = arrival.value.split('-')[1];
		a_year = arrival.value.split('-')[2];
		d_month = departure.value.split('-')[0];
		d_day = departure.value.split('-')[1];
		d_year = departure.value.split('-')[2];
		dateError = 0;
		
		var a_date =new Date(a_year, a_month - 1, a_day);
		var d_date =new Date(d_year, d_month - 1, d_day);
		
        var num_nights = Math.ceil((d_date.getTime() - a_date.getTime())/(1000*60*60*24));
        if (num_nights < 0){
            errors = 1;
		    message+= "- Your departure date is before your arrival date\n";
        }

	}

	if(errors == 0) {
		window.location = "http://universalhotels.ibe.netbooker.com/web/FrontController.nb4?module=PropertySearch&operation=SinglePropertySearch&execute=yes&propertyCodeType=RV&instanceId=96&lookAndFeelId=1014&propertyCode=UEHRH&chainCode=UE&specialRate=PCT,S&locale=fr&propertyCodeType=RV&adults="+num_adults+"&children="+num_children+"&numberOfRooms="+num_rooms+"&numberOfNights="+num_nights+"&arriveDate="+a_day+"&arriveMonth="+a_month+"&arriveYear="+a_year+"&departDate="+d_day+"&departMonth="+d_month+"&departYear="+d_year;
		
	
	
	} else {
		alert(message);
	}
}



function clearForm(theForm) {
	var formElem = document.getElementById('availability_form');
		formElem.reset();
		document.getElementById('arrival').focus;
		showCalendarControl(document.getElementById('arrival'));
		setActive('arrival'); 
}


var oldonload = window.onload;

if (typeof window.onload != 'function') {
	window.onload = startup;
} else {
	window.onload = function() {
		oldonload();
		startup();
	}
}


// Event Pop Up

var eventURL;
function eventPopup(eventID, locationID){
    
    eventURL = "/EventDetails.aspx?EventID="+eventID+"&LocationID="+locationID;
    //$('eventPopupDiv').style.display = "block";
    $('eventPopupDiv').style.visibility = "visible";
    //getHTML("eventDetailsDiv", eventURL);   
 }
 
 function linkPopup(){
    $('#eventLinkPopup').css("display","block");
 }
 
 function emailPopup(){
   $('#eventDetails').css("visibility","hidden");
   $('#eventEmail').css("display","block"); 
 }
 
 function emailPopupClose(){
  $('#eventDetails').css("visibility","visible");
  $('#eventEmail').css("display","none"); 
 }
 function closePopup(div){
  $("#"+div).css("display","none"); 
 }
 
function closeEventPopup(div){ 
  $("#"+div).css("visibility","hidden");
 }


function printEvent(divId){
    var a = window.open('','','width=1,height=1');
	a.document.open("text/html");
	a.moveTo(-5000,-5000);
	a.document.write('<link rel="stylesheet" type="text/css" href="/styles/event_popup.css" />');
	a.document.write('<link rel="stylesheet" type="text/css" href="/styles/print.css" />');
	a.document.write('<link rel="stylesheet" type="text/css" href="/styles/visual.css" />');
	a.document.write(document.getElementById(divId).innerHTML);
	a.document.close();	
	a.print();
	a.close();
}


function serializeForm(frmID){
    //var pars = $(frmID).serialize();    
     
    var pars;
    var frmInputEls = $("#" + frmID).get(0).getElementsByTagName('input');
    var frmTextAreaEls = $("#" + frmID).get(0).getElementsByTagName('textarea');
    var frmSelectEls = $("#" + frmID).get(0).getElementsByTagName('select');
    var i, j ,k;
    
    //add paramaters
    
    //for inputs
    for(i = 0; i<frmInputEls.length; i++){
        if(frmInputEls.name != "" && frmInputEls.name != "undefined"){             
             switch (frmInputEls[i].type){
                 case "radio":
                     pars += (frmInputEls[i].checked) ? "&" + frmInputEls[i].name + "=" + frmInputEls[i].value : '' ;
                 break;
                 
                 case "checkbox":
                     pars += (frmInputEls[i].checked) ? "&" + frmInputEls[i].name.replace("[]","") + "=" + frmInputEls[i].value : '' ;
                 break;
                 
                 default:
                    pars += "&" + frmInputEls[i].name + "=" + frmInputEls[i].value;                   
                 break;             
             }            
       }       
    }
    
      //for drop down boxes
    for(j = 0; j<frmSelectEls.length; j++){
        if(frmSelectEls.name != ""){                        
            pars += "&" + frmSelectEls[j].name + "=" + frmSelectEls[j].options[frmSelectEls[j].selectedIndex].value ;
       }       
    }
    
    //for textareas
    for(k= 0; k<frmTextAreaEls.length; k++){
        if(frmTextAreaEls.name != ""){
            if(pars != "") pars += "&";             
            pars += "&" + frmTextAreaEls[k].name + "=" + frmTextAreaEls[k].value;           
       }       
    }
    
    //if(doFunction == null) doFunction = "formSubmitted";    
    //var myAjax = new Ajax.Request( url, {method: 'post', parameters: pars, onComplete: formSubmitted } );
    
    return pars;

}


function formSubmitted(originalRequest)
{
    return originalRequest.responseText;
}

function showResponse(originalRequest)
{
	//put returned XML in the div
	$("#eventPopupDiv").innerHTML = originalRequest.responseText;
}	
	


function callIFrameFunction(iframeName, functionName){
    if (window.frames.iframeName && window.frames.iframeName.functionName) {
    window.frames.iframeName.functionName();
    }
}

function fadeEffect(element, fadeDur){
    //fadeDur = (fadeDur == null) ? 1 : fadeDur;
    
    //$(element).hide("slow");
    $(element).fadeTo("slow", .5);
}

function showEffect(element, showDur){
   //showDur = (showDur == null) ? 1 : showDur;
   
   //$(element).show("slow");
    $(element).fadeTo("slow", 1);

}
   


function fadeButtons(exceptElement, fadeDur, showDur ){
    showDur = (showDur == null) ? 1 : showDur;
    fadeDur = (fadeDur == null) ? 0 : fadeDur;
    var els = $('.locationNavButton');    
    els.each(function() {
        if($(this).attr('id') != exceptElement){
            fadeEffect($(this).get(0), fadeDur);
        }else {
            showEffect($(this).get(0), showDur);
        }
    });
}   



/* sub pages */
function togglePopup(divID){
    //$(divID).style.display = ($(divID).style.display == "none" || $(divID).style.display == "" ) ? "block" : "none";
    
    $("#"+divID).toggle();
}



function showRoomPopup(divId, roomType, viewType, topPos){
    var imgFloorPlan, imgPhoto ;
    var title;

    $("#"+divId).css("display","block");
    if(topPos){ $("#"+divId).css("top",topPos + "px")};
    //$('content_body').style.height = "500px";

    switch ( roomType ){    
        case 'DeluxeKing':
            imgPhoto = "/images/accom_roomdetail_deluxe_king.jpg";
            imgFloorPlan = "/images/accom_FloorPlan_deluxe_king.gif";
            title = "Deluxe King Rooms";
        break;
        
        case 'DeluxeQueen': 
            imgPhoto = "/images/accom_roomdetail_deluxe_queen.jpg";
            imgFloorPlan = "/images/accom_FloorPlan_deluxe_queen.gif";
            title = "Deluxe Queen Rooms";   
        break;
        
        case 'StandardViewRoom': 
            imgPhoto = "/images/accom_roomdetail_standardview.jpg";
            imgFloorPlan = "/images/accom_FloorPlan_standardview.gif";
            title = "Standard Rooms";   
        break;
        
         case 'PoolViewRoom': 
            imgPhoto = "/images/accom_roomdetail_poolview.jpg";
            imgFloorPlan = "/images/accom_FloorPlan_poolview.gif";
            title = "Pool View Rooms";   
        break;
        
         case 'GardenViewRoom': 
            imgPhoto = "/images/accom_roomdetail_gardenview.jpg";
            imgFloorPlan = "/images/accom_FloorPlan_gardenview.gif";
            title = "Garden View Rooms";   
        break; 
        
        case 'GracelandSuite': 
            imgPhoto = "/images/accom_roomdetail_gracelandsuite.jpg";
            imgFloorPlan = "/images/accom_FloorPlan_gracelandsuite.gif";
            title = "Graceland Suite";   
        break;
        
        case 'HospitalitySuite': 
            imgPhoto = "/images/accom_roomdetail_hospitalitysuite.jpg";
            imgFloorPlan = "/images/accom_FloorPlan_hospitalitysuite.gif";
            title = "Hospitality Suites";   
        break;
        
        case 'KidsSuite': 
            imgPhoto = "/images/accom_roomdetail_kidssuite.jpg";
            imgFloorPlan = "/images/accom_FloorPlan_kidssuite.gif";
            title = "Kids Suites";   
        break; 
        
         case 'KingSuite': 
            imgPhoto = "/images/accom_roomdetail_kingsuite.jpg";
            imgFloorPlan = "/images/accom_FloorPlan_kingsuite.gif";
            title = "King Suites";   
        break; 
                
    }      
       
    switch ( viewType ){
        case 'Photos':
            $("#"+divId + "Image").attr("src",imgPhoto);
            $("#"+divId + "Image").attr("alt",title);
            $("#"+divId + "Title").html(title);
            $("#"+divId + "BtnViewFloorPlan").attr("src","/images/accom_btn_viewfloorplan.gif");
            $("#"+divId + "BtnViewPhotos").attr("src","/images/accom_btn_roomphotos_off.gif");          
        break;
        
        case 'FloorPlan':
            $("#"+divId + "Image").attr("src",imgFloorPlan);
            $("#"+divId + "Image").attr("alt",title);
            $("#"+divId + "Title").html(title);
            $("#"+divId + "BtnViewFloorPlan").src = "/images/accom_btn_viewfloorplan_off.gif";
            $("#"+divId + "BtnViewPhotos").src = "/images/accom_btn_roomphotos.gif";    
        break;
    }

}


function BookNow(roomType){
    //showHideReservation();
    openReservationFrame($('#booknow').get(0), 'HORL', 'booknow','/rw.htm');    
    FloatDivInCenter('ReservationFrame');
}

function doRollOver(el, src){
    el.src = src;
}



function getScrollXY(){
  var scrOfX=0, scrOfY=0;
  if(typeof(window.pageYOffset)=='number'){
    //Netscape compliant
    scrOfY=window.pageYOffset;
    scrOfX=window.pageXOffset;
  }else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){
    //DOM compliant
    scrOfY=document.body.scrollTop;
    scrOfX=document.body.scrollLeft;
  }else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){
    //IE6 standards compliant mode
    scrOfY=document.documentElement.scrollTop;
    scrOfX=document.documentElement.scrollLeft;
  }
  return [scrOfX,scrOfY];
}


function getSize() {
  var W=0, H=0;
  if(typeof(window.innerWidth)=='number'){
    //Non-IE
    W=window.innerWidth;
    H=window.innerHeight;
  }else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){
    //IE 6+ in 'standards compliant mode'
    W=document.documentElement.clientWidth;
    H=document.documentElement.clientHeight;
  }else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){
    //IE 4 compatible
    W=document.body.clientWidth;
    H=document.body.clientHeight;
  }
  return [W,H];
}


function centerElement(elem, parentID) {
//Centers and element withing the parent element
//If parentID is null it will center the element within the document
//by DR

    var d = document;    
    if (parentID) {
        var parentEl = d.getElementById?d.getElementById(parentID):d.all?d.all[parentID]:d.layers[parentID];         
        intW = parentEl.offsetWidth;
        intH = parentEl.offsetHeight;        
    }else {
       intW = getSize()[0];     
       intH = getSize()[1]; 
    }
        
    var left = parseInt((intW - elem.offsetWidth) / 2, 10);
    var top =  parseInt((intH - elem.offsetHeight) / 2, 10);

    elem.style.left = left + 'px';
    elem.style.top = top + 'px';

    parentEl = left = top = elem = null;
}

var stayCenterTimeoutID;

function FloatDivInCenter(id, parentID)
{  
//Keeps element centered on page
//Tested and works on IE6, IE7, Safari, and FF2
//fixed to work on multiple browsers by DR
//Be sure to clear the timeout using timeoutid "stayCenterTimeoutID" 

	var startY = 150;
	var d = document;
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	
	centerElement(el, parentID);
	
	function ml(id)
	{		
		if(d.layers){el.style=el};		
		el.sP=function(y){this.style.top=y + 'px';};
		el.y = Math.floor(getScrollXY()[1]+getSize()[1]/2)-50;
		el.y -= startY;
		return el;
	}
	window.stayCenter=function()
	{
		var pY = Math.floor(getScrollXY()[1]+getSize()[1]/2 )-50;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.y);
		stayCenterTimeoutID = setTimeout("stayCenter()", 10);		
	};
	ftlObj = ml(id);
	stayCenter();
}