
var animating = false;
var originalImage;
var originalOffset;
var nImage;

function startup() {
	//List functions to be run on startup here:
	externalLinks();	
	//sIFRreplace();
	
	
}

function update(arg){
//alert(arg);
	if (displayMode > 0){	
	   // removejscssfile("default_structural.css", "css"); 
	    //loadjscssfile("/styles/default2_structural.css", "css");
	    replacejscssfile("structural.css", "/styles/default2_structural.css", "css"); 
	}
	else{
	    //removejscssfile("default_structural2.css", "css"); 
	    //loadjscssfile("/styles/default_structural.css", "css");
	    replacejscssfile("structural.css", "/styles/default_structural.css", "css"); 
	}
}

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 moveElem(elem,eStart,eEnd,eTime,cID,tOff) {
	
	var FPS = 30;								// Frames per second
	var numFrames = FPS*(eTime/1000);			// Frames in animation
	var timePerFrame = eTime/numFrames;			// Time per frame in ms
	var dist = (eEnd - eStart)/numFrames;	// Distance to travel (in pixels)
	
	var newDist = eStart;
	var frame = 1;
	
	function displayNextFrame() {
		if (frame > numFrames || dist == 0) {
			clearInterval(intervalId);
			document.getElementById(elem).style.top = '-'+eEnd+'px';
			if(cID == '') {
				// alert("Do Nothing!");
			} else {
				// alert("Load Content!");
				swapContent(cID,tOff);
			}
			return;
		}
		
		newDist += dist;
	
		document.getElementById(elem).style.top = '-' + newDist + 'px';
	
		frame++;
	}
	
	var intervalId = setInterval(displayNextFrame,timePerFrame);
		
}

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 == mainID) { 
//document.getElementById(mainID).style.display = 'none';
} else {
    //document.getElementById(mainID).style.display = '';
}

//alert(clickedID + "/" + currentID + "/" + mainID); 

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 contentMe(cID,tOff,hOff,newImage) {
	if(cID==homeID){
		document.getElementById("sNavLI"+homeID).style.display='none';
	} else {
		document.getElementById("sNavLI"+homeID).style.display='';
	}
	if(cID != lastID) {
		var element = document.getElementById("content");
		document.getElementById("sNavOn"+lastID).style.left = "-5000px";
		document.getElementById("sNavOff"+lastID).style.left = "10px";
		document.getElementById("sNavOff"+cID).style.left = "-5000px";
		document.getElementById("sNavOn"+cID).style.left = "10px";
		lastID = cID;
		document.getElementById("sNavOn"+cID).parentNode.style.background = '';
		
		nImage = newImage;
	
		if(animating == false) {
			animating = true;
			if(nImage != '') {
				originalOffset == '0px';
			} else {
				originalOffset = '-'+hOff+'px';
			}
			originalImage = document.getElementById('headerImage').src;
			
			var curPos = 0;		// Starting position of element
			var timePerFrame = 5;	// Time per frame in ms
			var numFrames = 7;		// Frames in animation
			var dist = 5;			// Distance to travel (in pixels)
			
			var newPos = curPos;	
			var frame = 1;
					
			function displayNextFrame() {
				if (frame > numFrames) {
					//moveElem('header_backing',0,hOff,250,cID,tOff);
					clearInterval(intervalId);
					// alert("Done moving up!");
					curPos = newPos;
					// animating = false;
					swapContent(cID,tOff);
					return;
				}
				
				newPos = newPos - dist;
				
				element.style.marginTop = newPos + 'px';
			
				frame++;
			}
		
			var intervalId = setInterval(displayNextFrame,timePerFrame);
			
		} else {
			swapContent(cID,tOff);
		}
	}
}



function swapContent(cID,tOff) {
	var cLoad = cID;
	var tOffset = tOff;
	
	if((user_platform == "apple" && user_browser == "firefox") || (user_browser == "opera")) {
		document.getElementById('content_body').style.display = 'none';
		document.getElementById('tContainer').style.display = 'none';
	} else {
		new Effect.Fade(document.getElementById('content_body'),{duration:0.5});
		new Effect.Fade(document.getElementById('tContainer'),{duration:0.5});
	}
	
	function loadContent() {
		clearInterval(interval);
		// alert(tOff);
		document.getElementById("tContainer").style.top = "-"+tOff+"px";
		xajax_getContent(cLoad);
	}
	
	var interval = setInterval(loadContent,500);
	
}



function swapImage(newImage,hOffset) {
	if(newImage != document.getElementById('headerImage').src) {
		// alert("New image: "+newImage+"\n\nOld image: "+document.getElementById('headerImage').src);
		new Effect.Fade('headerImageContainer',{ 
						duration: 0.5,
						afterFinish: function() {
							document.getElementById('headerImage').src = "";
						}
						});
		function loadImage() {
			clearInterval(interval);
			document.getElementById('headerImage').src = newImage;
			new Effect.Appear('headerImageContainer',{ duration: 0.5 });
			moveElem('headerImage',0,hOffset,1000,'','');
		}
	
		var interval = setInterval(loadImage,750);
	}
}




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 showHideReservation() {
	var check_availability = document.getElementById('check_availability');
	if(check_availability.style.display == 'none') {
		check_availability.style.display= 'block';
		
		calendarControl.show();		
		setActive('arrival');
		showCalendarControl(document.getElementById('arrival'));
		
	} else {
		check_availability.style.display = 'none';
		calendarControl.hide();
	}
	
	
}



function setActive(elem) {

	var arrival = document.getElementById('title_arrival');
	var departure = document.getElementById('title_departure');
	if(arrival && elem == 'arrival') {
		if(arrival.src.indexOf('http://s201414225.onlinehome.us/hollywood/-a.gif') == -1) {
			arrival.src = arrival.src.replace('.gif','http://s201414225.onlinehome.us/hollywood/-a.gif');
			departure.src = departure.src.replace('http://s201414225.onlinehome.us/hollywood/-a.gif','.gif');
		}
		
	} else if(departure && elem == 'departure') {
		if(departure.src.indexOf('http://s201414225.onlinehome.us/hollywood/-a.gif') == -1) {
			arrival.src = arrival.src.replace('http://s201414225.onlinehome.us/hollywood/-a.gif','.gif');
			departure.src = departure.src.replace('.gif','http://s201414225.onlinehome.us/hollywood/-a.gif');
		}
	}
}



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(a_year > d_year) {
//			errors = 1;
//			message+= "- Your departure date is before your arrival date\n";
//		} else {
//			if(a_month > d_month) {
//				errors = 1;
//				message+= "- Your departure date is before your arrival date\n";
//			} else {
//				if(a_day > d_day) {
//					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').style.display = "block";
   // $('txtEventLink').value = "http://www.hardrock.com" + eventURL;
   // $('txtEventLink').focus();
   // $('txtEventLink').select();   
 }
 
 function emailPopup(){
   $('eventDetails').style.visibility = "hidden";
   $('eventEmail').style.display = "block";
  // getHTML("eventDetailsDiv", "EmailEvent.aspx");
 }
 
 function emailPopupClose(){
  $('eventDetails').style.visibility = "visible";
  $('eventEmail').style.display = "none";
 }
 function closePopup(div){
  $(div).style.display = "none";
 }
 
  function closeEventPopup(div){
 // $(div).style.display = "none";
  $(div).style.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();
}

//Uses protoype library
 
//loads url with argument 'url' into div with argument 'divID' using get method
function getHTML(divID, url)
	{	
	var myAjax = new Ajax.Updater(divID, url, {method: 'get',  onComplete: getComplete(url), onFailure: getFailed, onSuccess: getSuccess , evalScripts: true});
	}	
	
//loads url with argument 'url' into div with argument 'divID' using post method. 
//Serializes the form elements in the form given by frmID	
function postHTML(divID, url, frmID)
	{		
	var parms =  Form.serializeElements( $(frmID).getInputs('text') );//$(frmID).serialize(true);
	var myAjax = new Ajax.Updater(			
			divID, 			
			url, 			
			{
				method: 'post', 
				onComplete: postComplete(arg, url),
				parameters: parms
			});		
	}	

function getRequest(url)
	{			
    var pars;	
    var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: showResponse} );
	}

function processForm(frmID, url, doFunction){
    //var pars = $(frmID).serialize();
    
     
    var pars;
    var frmInputEls = $(frmID).getElementsByTagName('input');
    var frmTextAreaEls = $(frmID).getElementsByTagName('textarea');
    var frmSelectEls = $(frmID).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 } );
}




function formSubmitted(originalRequest)
{
    return originalRequest.responseText;
}

function showResponse(originalRequest)
{
	//put returned XML in the div
	$("eventPopupDiv").innerHTML = originalRequest.responseText;
}	
	
	
//function loaded after postHTML succesfully loads page	
function postComplete(frmID, url){}
function getFailed(){}
function getSuccess(){
}
//function loaded after getHTML succesfully loads page	
function getComplete(url){}

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;
       Effect.Fade(element, 
       { duration: fadeDur,  from:1.0, to:.75});
}

function showEffect(element, showDur){
   showDur = (showDur == null) ? 1 : showDur;
   Effect.Appear(element, 
   {duration: showDur, from:1.0, to:1.0});
}
   


function fadeButtons(exceptElement, fadeDur, showDur ){
    showDur = (showDur == null) ? 1 : showDur;
    fadeDur = (fadeDur == null) ? 0 : fadeDur;
    var els = $$('.locationNavButton');    
    els.each(function(item) {
        if(item != exceptElement) fadeEffect(item, fadeDur);
        else showEffect(item, showDur);
    });
}   



/* sub pages */
function togglePopup(divID){
    $(divID).style.display = ($(divID).style.display == "none" || $(divID).style.display == "" ) ? "block" : "none";
}



function showRoomPopup(divId, roomType, viewType, topPos){
    var imgFloorPlan, imgPhoto ;
    var title;

    $(divId).style.display = "block";
    if(topPos) $(divId).style.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").src = imgPhoto;
            $(divId + "Image").alt = title;
            $(divId + "Title").innerHTML = title;
            $(divId + "BtnViewFloorPlan").src = "/images/accom_btn_viewfloorplan.gif";
            $(divId + "BtnViewPhotos").src = "/images/accom_btn_roomphotos_off.gif";            
        break;
        
        case 'FloorPlan':
            $(divId + "Image").src = imgFloorPlan;
            $(divId + "Image").alt = title;
            $(divId + "Title").innerHTML = 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'), 'HORL', 'booknow','/rw.htm');
    
    //FloatDivInCenter('ReservationFrame');
    window.location = "https://booking.ihotelier.com/istay/istay.jsp?HotelID=72481&languageid=11";
}

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();
}