
function init(){
	try
	{
		gNav_Init();
	}
	catch(er){
	}
}

var navCollectionIDs = new Array()
	navCollectionIDs[0] = "GobalNavigationElement_Home"
	navCollectionIDs[1] = "GobalNavigationElement_Stay"
	navCollectionIDs[2] = "GobalNavigationElement_ToDo"
	navCollectionIDs[3] = "GobalNavigationElement_Real"
	navCollectionIDs[4] = "GobalNavigationElement_Forum"
	navCollectionIDs[5] = "GobalNavigationElement_Webcams"
	navCollectionIDs[6] = "GobalNavigationElement_Contact"
	navCollectionIDs[7] = "GobalNavigationElement_Advertise"

var navCollection = new navCollection();
var gNav_DefaultSection = ""
var gNav_Debug = false
var gNav_ImageRoot = "/images/nav/"
var gNav_Buffer_Timeout_Duration = 400
var gNav_Buffer_Timer

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 "home":
				gNav_DefaultSection = "GobalNavigationElement_Home"
				break;
			case "stay":
				gNav_DefaultSection = "GobalNavigationElement_Stay"
				break;
			case "todo":
				gNav_DefaultSection = "GobalNavigationElement_ToDo"
				break;
			case "real":
				gNav_DefaultSection = "GobalNavigationElement_Real"
				break;
			case "forum":
				gNav_DefaultSection = "GobalNavigationElement_Forum"
				break;
			case "webcams":
				gNav_DefaultSection = "GobalNavigationElement_Webcams"
				break;
			case "contact":
				gNav_DefaultSection = "GobalNavigationElement_Contact"
				break;
			case "advertise":
				gNav_DefaultSection = "GobalNavigationElement_Advertise"
				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) }
	}
}

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() }
	}

	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()
				navCollection.tObj.cancel()
				thisDiv.style.display = "block";
				thisDiv.p.bDiv.style.display = "block";
				thisDiv.p.aDiv.aRef.aImg.turnOn()
			}
			thisDiv.collapse = function(){
				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 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) }
}
