

// Basic data declarations
var nav_rolloverTimer = new Array();               // Timers for navigation menus
var nav_rolloffTimer = new Array();
var nav_onImg = new Array();
var nav_offImg = new Array();
var nav_currentImg = new Array();
var nav_imgPath = "/images/nav/global/gnav";
var nav_ready;

// Swap images on based on the DIV object that contains the image and a name array
function imageOn(layerObj,name) {
	if (layerObj.doc.images) {
		if (name == whichMenu) {
			layerObj.doc.images[name].src = nav_currentImg[name].src
		} else {
			layerObj.doc.images[name].src = nav_onImg[name].src
		}
	}
}

function navImgOn(name) {
	var imgName = name;
	eval("navObj=" + nav_navDivPrefix);
	imageOn(navObj,imgName);
	return true;
}

// Swap images off based on the DIV object that contains the image and a name array 
function imageOff(layerObj,name) {
	if (layerObj.doc.images) {
		if (name == whichMenu) {
			layerObj.doc.images[name].src = nav_currentImg[name].src
		} else {
			layerObj.doc.images[name].src = nav_offImg[name].src
		}
	}
}

function navImgOff(name) {
	var imgName = name;
	eval("navObj=" + nav_navDivPrefix);
	imageOff(navObj,imgName);
	return true;
}

// Helper code to generate Image objects for image swaps
function imgSwapInit(refName,imgActive,imgNormal,imgCurrent) {
  nav_onImg[refName] = eval("new Image()");
  nav_offImg[refName] = eval("new Image()");
  nav_currentImg[refName] = eval("new Image()");
  nav_onImg[refName].src = imgActive;
  nav_offImg[refName].src = imgNormal;
  nav_currentImg[refName].src = imgCurrent;
  return true;
}

function setRolloffTimer(name, currMenu) {
	if (nav_ready) {
		if (nav_rolloverTimer[name]) clearTimeout(nav_rolloverTimer[name]);
		nav_rolloffTimer[name] = setTimeout("closeMenu('" + name + "', '" + currMenu + "');", nav_menuInterval);
	}
}

function setRolloverTimer(name, currMenu) {
	if (nav_ready) {
	
		if (nav_rolloffTimer[name]) clearTimeout(nav_rolloffTimer[name]);
		nav_rolloverTimer[name] = setTimeout("openMenu('" + name + "', '" + currMenu + "');", nav_menuInterval);
	}
}

// Wrapper functions to handle opening menus
function openMenu(name, currMenu) {
	if (nav_rolloverTimer[name]) clearTimeout(nav_rolloverTimer[name]);
	if (name!==currMenu) {
		if (currMenu!='') navImgOff(currMenu);
		navImgOn(name);
		}
	nav_menuObjs[name].openMenu();
	return false;
}

function closeMenu(name, currMenu) {
	if (nav_rolloffTimer[name]) clearTimeout(nav_rolloffTimer[name]);
	if (name!==currMenu) {
		if (currMenu!='') navImgOn(currMenu);
		navImgOff(name);
		}
	nav_menuObjs[name].closeMenu();
	
	return false;
}

function getDomObjRef(id) {
	var obj;
	if (is.ie) {
		obj = document.all[id];
	}
	return obj; 
}

function goTo(theURL){
	if (theURL) { 
		document.location.href = theURL;
	}
}

// ********************************************************
// onLoad Initialization function
// ********************************************************
function init() {
	
    // LAYER INITIALIZATION
	eval(nav_navDivPrefix + " = new DynLayer('" + nav_navDivId + "','')");

	
	// Initialize layer objects and events for menus
	for (var i = 0; i < nav_menuNames.length; i++) {
	  var menuName = nav_menuNames[i];
	  var menuObj = nav_menuObjs[menuName];
	  
	  // Build layer object for menu
	  eval(menuObj.containerDivRef + " = new DynLayer('" + menuObj.containerDivName + "','')");
	  
	  // Bind mouseover|out event handlers to menus
	  eval("menuDivObj=" + nav_menuObjs[menuName].containerDivRef);
	  menuDivObj.elm.onmouseover = new Function("setRolloverTimer('"+menuName+"', '" + whichMenu + "')");
	  menuDivObj.elm.onmouseout = new Function("setRolloffTimer('"+menuName+"', '" + whichMenu + "')");
	  
	  // Bind mousedown events for all menu elements
		  if (is.ie) {
			  var textArray = nav_menuText[menuName];
			  var urlArray = nav_menuURLs[menuName];
			  
				  for (var j = 0; j < textArray.length; j++) {
					elmName = menuObj.name + 'Elm' + j;
					menuElmObj = getDomObjRef(elmName);
					
					if ((textArray[j] != '') && (urlArray[j] != '')) menuElmObj.onclick = new Function("goTo('/" + menuName +"/" + urlArray[j] + "'); return false;");
				  }
		  }	  
	}
	
	
	nav_ready = true;
}




function DynLayer(id,nestref) {
	if (is.ns) {
		if (is.ns4) {
			if (!nestref) var nestref = DynLayer.nestRefArray[id]
			if (!DynLayerTest(id,nestref)) return
			this.css = (nestref)? eval("document."+nestref+".document."+id) : document.layers[id]
			this.elm = this.event = this.css
			this.doc = this.css.document
			this.w = this.css.clip.width
			this.h = this.css.clip.height
		} else if (is.ns6) {
			this.elm = document.getElementById(id)
			this.css = this.elm.style
			this.doc = document
			this.w = getStyle(id,"width")
			this.h = getStyle(id,"height")
		}
		this.x = this.css.left
		this.y = this.css.top
		
	}
	else if (is.ie) {
		this.elm = this.event = document.all[id];
		this.css = document.all[id].style;
		this.doc = document;
		this.x = this.elm.offsetLeft;
		this.y = this.elm.offsetTop;
		this.w = (is.ie4)? this.css.pixelWidth : this.elm.offsetWidth;
		this.h = (is.ie4)? 113 : this.elm.offsetHeight;
		this.docHeight = 'document.body.scrollHeight';
		this.docWidth = (is.ie4)? 'document.body.clientWidth' : 'document.body.clientWidth';
	}
	this.id = id
	this.nestref = nestref
	this.obj = id + "DynLayer"
	eval(this.obj + "=this")
}
function DynLayerShow() {
	this.css.visibility = (is.ns4)? "show" : "visible"
}
function DynLayerHide() {
	this.css.visibility = (is.ns4)? "hide" : "hidden"
}

DynLayer.prototype.show = DynLayerShow
DynLayer.prototype.hide = DynLayerHide
DynLayer.prototype.setbg = DynLayerSetbg
DynLayerTest = new Function('return true')
DynLayer.nestRefArray = new Array()
DynLayer.refArray = new Array()
DynLayer.refArray.i = 0
DynLayer.set = false


// BrowserCheck Object
function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns6 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
    	this.ie6 = (this.version.indexOf('MSIE 6')>0)
	this.min = (this.ns||this.ie)
}
is = new BrowserCheck()

// CSS Function
function css(id,left,top,width,height,color,vis,z,other) {

	if (id=="START") return '<STYLE TYPE="text/css">\n'
	else if (id=="END") return '</STYLE>'
	var str = (left!=null && top!=null)? '#'+id+' {position:absolute; left:' + left + 'px;' + ' top:'+top+'px;' : '#'+id+' {position:relative;'
	if (arguments.length>=4 && width!=null) str += ' width:'+width+'px;'
	if (arguments.length>=5 && height!=null) {
		str += ' height:'+height+'px;'
		if (arguments.length<9 || other.indexOf('clip')==-1) str += ' clip:rect(0px '+width+'px '+height+'px 0px);'
	}
	if (arguments.length>=6 && color!=null) str += (is.ns)? ' layer-background-color:'+color+';' : ' background-color:'+color+';'
	if (arguments.length>=7 && vis!=null) str += ' visibility:'+vis+';'
	if (arguments.length>=8 && z!=null) str += ' z-index:'+z+';'
	if (arguments.length==9 && other!=null) str += ' '+other
	str += '}\n'
	return str
}
function writeCSS(str,showAlert) {
	str = css('START')+str+css('END')
	document.write(str)
}

// Set the background color of a DIV
function DynLayerSetbg(color) {
	if (is.ns) this.doc.bgColor = color
	else if (is.ie) this.css.backgroundColor = color
}

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (document.defaultView)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	else if (x.currentStyle)
		var y = eval('x.currentStyle.' + styleProp);
	return parseInt(y);
}
