
var navCollectionIDs = new Array()
	navCollectionIDs[0] = "GobalNavigationElement_About"
	navCollectionIDs[1] = "GobalNavigationElement_Islands"
	navCollectionIDs[2] = "GobalNavigationElement_ToDo"
	navCollectionIDs[3] = "GobalNavigationElement_ToStay"
	navCollectionIDs[4] = "GobalNavigationElement_MyBah"
	navCollectionIDs[5] = "GobalNavigationElement_BookNow"
	navCollectionIDs[6] = "GobalNavigationElement_Shop"

var navCollection = new navCollection();

var gNav_DefaultSection = ""
var gNav_Debug = false

var gNav_ImageRoot = "/assets/nav/"

var gNav_Buffer_Timeout_Duration = 400
var gNav_Buffer_Timer

var gNav_Search_Container_ID = "GlobalNavigationSearch_Container"
var gNav_Search_DefaultValue = "Search"
var gNav_Search_Bright = "#29353b"
var gNav_Search_Dim = "#999999"
var gNav_Search_Destination = "/bahamas/search/default.aspx"

var gNav_Login_State = ( getCookie("__bahamasGUID") == null || getCookie("__bahamasGUID") == "" )?false:true;


//window.onload = gNav_Init;


function gNav_SeedPageVariables(ds,db){
	gNav_DefaultSection = (ds)?ds:""
	gNav_Debug = (db)?db:""
}

function gNav_Init(){
	if(typeof(section) != "undefined" && section.length > 0){
		switch(section){
			case "about":
				gNav_DefaultSection = "GobalNavigationElement_About"
				break;
			case "island":
				gNav_DefaultSection = "GobalNavigationElement_Islands"
				break;
			case "what":
				gNav_DefaultSection = "GobalNavigationElement_ToDo"
				break;
			case "where":
				gNav_DefaultSection = "GobalNavigationElement_ToStay"
				break;
			case "mybahamas":
				gNav_DefaultSection = "GobalNavigationElement_MyBah"
				break;
			case "shop":
				gNav_DefaultSection = "GobalNavigationElement_Shop"
				break;

		}
	}
	
	for(i=0;i<navCollectionIDs.length;i++){
		try{ new gNav(navCollectionIDs[i]) } 
		catch(er){ if(gNav_Debug) alert(er.message) }
	}
	
	if(gNav_DefaultSection != ""){
		try{navCollection.arr[gNav_DefaultSection].setDefaultImage()}
		catch(er){ if(gNav_Debug) alert(er.message) }
	}
	
	// login no longer used
	//gNav_Init_LogState();
	gNav_Init_Search(gNav_Search_Container_ID);
}

function gNav_Init_LogState(){
	var thisDiv = document.getElementById("GobalNavigationElement_MyBahLogin")
	
	thisDiv.p = navCollection
	thisDiv.aHref = new aHref(thisDiv);
	
	function aHref(t){
		var thisHref = t.getElementsByTagName('A')[0]
			thisHref.p = t
			thisHref.aImg = new aImg(thisHref);
			thisHref.setAttribute('href', ((gNav_Login_State)?"/bahamas/mybahamas/signout.aspx":"/bahamas/mybahamas/login.aspx"))
			
			thisHref.onmouseover = function(){
				thisHref.p.p.nav_Collapse_All();
				thisHref.aImg.src = thisHref.aImg.onImg.src;
			}
			thisHref.onmouseout = function(){
				thisHref.aImg.src = thisHref.aImg.offImg.src;
			}
			
		function aImg(t){
			var thisImg = t.getElementsByTagName('IMG')[0]
				thisImg.p = t
				thisImg.onImg = new Image(); thisImg.onImg.src = gNav_ImageRoot + ((gNav_Login_State)? "nav_log_out_on.gif" : "nav_log_in_on.gif")
				thisImg.offImg = new Image(); thisImg.offImg.src = gNav_ImageRoot + ((gNav_Login_State)? "nav_log_out_off.gif" : "nav_log_in_off.gif")
				thisImg.src = thisImg.offImg.src;
			return thisImg
		}
		return thisHref
	}
}

function navCollection(){
	this.arr = new Array()
	this.tObj = new tObj(this)
	this.nav_Collapse_All = function(){
		for(i=0;i<navCollection.arr.length;i++){ navCollection.arr[i].sDiv.collapse() }
		ieMenusShow();
	}

	function tObj(t){
		this.p = t
		this.start = function(){
			this.cancel();
			gNav_Buffer_Timer = setTimeout("navCollection.nav_Collapse_All()",gNav_Buffer_Timeout_Duration)
		}
		this.cancel = function(){
			clearTimeout(gNav_Buffer_Timer)
		}
	}
	
	return this
}



function gNav(pID) {
	this.pID = pID
	this.pDiv = new pDiv(this)
	this.aDiv = new aDiv(this)
	this.sDiv = new sDiv(this)
	this.bDiv = new bDiv(this)
	
	this.setDefaultImage = function(){
		this.aDiv.aRef.aImg.offImg.src = this.aDiv.aRef.aImg.defaultImg.src
		this.aDiv.aRef.aImg.turnOff()
	}

	
	function pDiv(t){ 
		var thisDiv = document.getElementById(t.pID)
			thisDiv.p = t
			thisDiv.p.hasSubDiv = false
			
		thisDiv.getDivByClassName = function(cN){
			var theDivs = thisDiv.getElementsByTagName('DIV')
			var theDiv = null;
			for(cNi=0;cNi<theDivs.length;cNi++){ if(theDivs[cNi].className.indexOf(cN) != -1){theDiv = theDivs[cNi]; } }
			return theDiv
		}
		
		return thisDiv
	}

	function aDiv(t){
		var thisDiv = t.pDiv.getDivByClassName("gNav_Anchor") //t.pDiv.getElementsByTagName('DIV')[0]
			thisDiv.p = t
			thisDiv.p.aDiv = thisDiv
			thisDiv.aRef = new aRef(thisDiv)
		
		function aRef(t){
			var thisRef = t.getElementsByTagName('A')[0]
				thisRef.p = t
				thisRef.aImg = new aImg(thisRef)
			
			function aImg(t){
				var thisImg = t.getElementsByTagName('IMG')[0]
					thisImg.p = t
					thisImg.onImg = new Image(); thisImg.onImg.src = nav_Image_Variants(thisImg,"on");
					thisImg.offImg = new Image(); thisImg.offImg.src = nav_Image_Variants(thisImg,"off")
					thisImg.shimImg = new Image(); thisImg.shimImg.src = nav_Image_Variants(thisImg,"shim")
					thisImg.defaultImg = new Image(); thisImg.defaultImg.src = nav_Image_Variants(thisImg,"default")
					thisImg.turnOn = function(){ thisImg.src = thisImg.onImg.src }
					thisImg.turnOff = function(){ thisImg.src = thisImg.offImg.src }
				return thisImg
			}
			return thisRef
		}
		return thisDiv
	}
	
		
	function sDiv(t){ 
		var thisDiv = t.pDiv.getDivByClassName("gNav_SubNav") //t.pDiv.getElementsByTagName('DIV')[1]
			thisDiv.p = t
			
			if(thisDiv.getElementsByTagName('UL').length <= 0){
				thisDiv.style.visibility = "hidden"
				thisDiv.style.padding = "0px"
				thisDiv.style.margin = "0px"
			}else{ 
				thisDiv.p.hasSubDiv = true 
				thisDiv.style.backgroundImage = "url(" + thisDiv.p.aDiv.aRef.aImg.shimImg.src + ")"
			}
			
			thisDiv.expand = function(){
				navCollection.nav_Collapse_All();
				ieMenusHide();
				navCollection.tObj.cancel();
				thisDiv.style.display = "block";
				thisDiv.p.bDiv.style.display = "block";
				thisDiv.p.aDiv.aRef.aImg.turnOn()
			}
			thisDiv.collapse = function(x){
				thisDiv.style.display = "none";
				thisDiv.p.bDiv.style.display = "none";
				thisDiv.p.aDiv.aRef.aImg.turnOff()
			}
			thisDiv.p.aDiv.aRef.onmouseover = function(){ thisDiv.expand() }
			thisDiv.onmouseover = function(){ navCollection.tObj.cancel() }
				
		return thisDiv
	}
		
	function bDiv(t){
		var thisDiv = t.pDiv.getDivByClassName("gNav_Buffer") //t.pDiv.getElementsByTagName('DIV')[2]
			thisDiv.p = t
			thisDiv.p.bDiv = thisDiv
			thisDiv.innerHTML = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"450\" width=\"750\"><tr><td></td></tr></table>"
			if(thisDiv.p.hasSubDiv){ thisDiv.onmouseover = function(){ navCollection.tObj.start() } }
			else{ thisDiv.onmouseover = function(){ navCollection.nav_Collapse_All() } }
		return thisDiv
	}
	
	navCollection.arr[navCollection.arr.length] = this
	navCollection.arr[this.pID] = this
}

function gNav_Init_Search(t){
		try{ new sDiv(); }
		catch(er){ if(gNav_Debug) alert(er.message) }

		function searchGlow(t){ t.style.color = (t.value == gNav_Search_DefaultValue || t.value == "")?gNav_Search_Dim:gNav_Search_Bright }
		function sDiv(){ 
			var ti = document.getElementById(t)
				ti.sInput = new sInput(ti);
				ti.sGo = new sGo(ti);
				ti.searchGo = function(){
					if(ti.sInput.value != "" && ti.sInput.value != gNav_Search_DefaultValue){
						window.location = gNav_Search_Destination + "?qt=" + URLEncode( ti.sInput.value );
					}
				}
		}
		function sInput(t){ 
			var ti = t.getElementsByTagName('INPUT')[0]
				ti.p = t
				
				ti.onfocus = function(){
					searchGlow(ti);
					if(ti.value==gNav_Search_DefaultValue){ ti.value = "" }; 
				}
				ti.onblur  = function(){ 
					searchGlow(ti);
					if(ti.value==""){ ti.value = gNav_Search_DefaultValue };
				}
				ti.onkeyup = function(){ searchGlow(ti); }
				ti.onkeydown = function(evt){
					var evt = (evt)?evt:window.event
					var keycode = (evt.which)?evt.which:(evt.keyCode)?evt.keyCode:null;
					if(keycode==13){ ti.p.searchGo();return false; }
				}
				searchGlow(ti);
			return ti;
		}
		function sGo(t){
			var ti = t.getElementsByTagName('INPUT')[1]
				ti.p = t
				ti.onclick = function(){ ti.p.searchGo();return false; }
			return ti;
		}
		
		function URLEncode( plaintext ){
			var SAFECHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";
			var HEX = "0123456789ABCDEF";
			var encoded = "";
			for (var i = 0; i < plaintext.length; i++ ) {
				var ch = plaintext.charAt(i);
				if (ch == " ") { encoded += "+"; /* x-www-urlencoded, rather than %20 */ } 
				else if (SAFECHARS.indexOf(ch) != -1) { encoded += ch; } 
				else {
					var charCode = ch.charCodeAt(0);
					if (charCode > 255) {
						//alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" + "(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted." );
						encoded += "+";
					} else {
						encoded += "%";
						encoded += HEX.charAt((charCode >> 4) & 0xF);
						encoded += HEX.charAt(charCode & 0xF);
					}
				}
			} 
			
			return encoded;
		}

}

function nav_Image_Variants(t,b){
	var baseVal = t.src
	var curPat, newPat
	curPat = /.*?\/([^\/]*)(_off)(\.gif)$/;
	switch(b){
		case "on": newPat = '$1_on$3'; break;
		case "off": newPat = '$1_off$3'; break;
		case "shim": newPat = '$1_shim$3'; break;
		case "default": newPat = '$1$2_default$3'; break;
		}
	if(curPat.test(baseVal)){ return gNav_ImageRoot + baseVal.replace(curPat,newPat) }
}

function goAdvSearch(path, id) {
	var input;
	if (document.getElementById) {  
		input = document.getElementById(id);  
	} else {
		input = document.all[id].className;	
	}
	var str = "";
	if (input != null && input.value != null) {
		if (input.value != gNav_Search_DefaultValue) {
			str = input.value;
		}
	}
	window.location = path + "?qt=" + URLEncode( str );
}

function URLEncode( plaintext ){
	var SAFECHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
		if (ch == " ") { encoded += "+"; /* x-www-urlencoded, rather than %20 */ } 
		else if (SAFECHARS.indexOf(ch) != -1) { encoded += ch; } 
		else {
			var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				//alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" + "(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} 
	
	return encoded;
}

function SearchHelpPagePop(pageURL){
	var w = 600;
	var h = 450;
	var wint = ( (screen.height - h) * .5 ) / 2;
	var winl = (screen.width - w) / 2;

	var pURL= pageURL
		pInfo='toolbar=0,';
		pInfo+='location=0,';
		pInfo+='directories=0,';
		pInfo+='status=0,';
		pInfo+='menubar=0,';
		pInfo+='scrollbars=1,';
		pInfo+='resizable=0,';
		pInfo+='width=' + w + ',';
		pInfo+='height=' + h + ',';
		pInfo+='top=' + wint + ',';
		pInfo+='left=' + winl;
	var mywin = window.open(pURL, 'SearchHelp', pInfo);
	mywin.focus();
	}
	
	
/* added aug 23 2006 for the advanced search page
they normally do nothing but will be redefined on pages that need to hide
select boxes when the menus show up 
note that the redefnition must come after this file is loaded 
so it can't be in the head tag */
function ieMenusHide() {
}
function ieMenusShow() {
}