// menu rollover & Netscape resize fix
// 2004/06/16
//
// body tag <body onresize=" fixNav()" ~>
//
d = window.document
loaded = false;

// browser detection object

function lib_bwCheck(){
	this.ver = parseInt(navigator.appVersion);
	this.agent = navigator.userAgent.toLowerCase();
	this.dom = document.getElementById?1:0
	this.opera = (this.agent.indexOf("opera")>-1);
	this.opera5 = (this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1);
	this.nav = ((this.agent.indexOf('mozilla')>-1) && (this.agent.indexOf('spoofer')==-1) && (this.agent.indexOf('compatible') == -1) && (this.agent.indexOf('opera')==-1) && (this.agent.indexOf('webtv')==-1) && (this.agent.indexOf('hotjava')==-1));
	this.nav4up = (this.nav && (this.ver == 4));
	this.nav6up = (this.nav && (this.ver >= 5));
	this.gecko = (this.agent.indexOf('gecko')>-1);
	this.ie5 = (this.agent.indexOf("msie 5")>-1 && this.dom && !this.opera)?1:0
	this.ie6 = (this.agent.indexOf("msie 6")>-1 && this.dom && !this.opera)?1:0
	this.ie4 = (document.all && !this.dom && !this.opera)?1:0
	this.ie = ((this.agent.indexOf("msie") != -1) && (this.agent.indexOf("opera") == -1));
	this.ie4up = (this.ie && (this.ver >= 4));
	this.mac = this.agent.indexOf("mac")>-1
	this.ns6 = (this.dom && this.ver>=5)?1:0
	this.ns4 = (document.layers && !this.dom)?1:0
	this.bw = (this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera)
	return this
}
bw = new lib_bwCheck() // Browser object

function lib_pfCheck(){
	this.ver = parseInt(navigator.appVersion);
	this.agent = navigator.userAgent.toLowerCase();	
	this.win = ((this.agent.indexOf("win")!=-1) || (this.agent.indexOf("16bit")!=-1) );
	// NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
	// Win32; can't distinguish between Win95 and WinNT.
	this.win95 = ((this.agent.indexOf("win95")!=-1) || (this.agent.indexOf("windows 95")!=-1));

	// is this a 16 bit compiled version?
	this.win16 = ((this.agent.indexOf("win16")!=-1) || (this.agent.indexOf("16bit")!=-1) || (this.agent.indexOf("windows 3.1")!=-1) || (this.agent.indexOf("windows 16-bit")!=-1) );  

	this.win31 = ((this.agent.indexOf("windows 3.1")!=-1) || (this.agent.indexOf("win16")!=-1) || (this.agent.indexOf("windows 16-bit")!=-1));

	this.winme = ((this.agent.indexOf("win 9x 4.90")!=-1));
	this.win2k = ((this.agent.indexOf("windows nt 5.0")!=-1));
	
	// NOTE: Reliable detection of Win98 may not be possible. It appears that:
	//       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
	//       - On Mercury client, the 32-bit version will return "Win98", but
	//         the 16-bit version running on Win98 will still return "Win95".
	this.win98 = ((this.agent.indexOf("win98")!=-1) || (this.agent.indexOf("windows 98")!=-1));
	this.winnt = ((this.agent.indexOf("winnt")!=-1) || (this.agent.indexOf("windows nt")!=-1));
	this.win32 = (this.win95 || this.winnt || this.win98 || ((this.ver >= 4) && (navigator.platform == "Win32")) || (this.agent.indexOf("win32")!=-1) || (this.agent.indexOf("32bit")!=-1));	

	this.os2 = ((this.agent.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) || (this.agent.indexOf("ibm-webexplorer")!=-1));
	
	this.mac = (this.agent.indexOf("mac")!=-1);
	this.mac68k = (this.mac && ((this.agent.indexOf("68k")!=-1) || (this.agent.indexOf("68000")!=-1)));
	this.macppc = (this.mac && ((this.agent.indexOf("ppc")!=-1) || (this.agent.indexOf("powerpc")!=-1)));
	
	return this
}
pf = new lib_pfCheck() // Platform object

function lib_cssCheck(){
	if (bw.nav4up) {
		document.write('<Link rel="stylesheet" href="' + cssfolder + '/nav4up.css" type="text/css">');
		//alert("here0");
	}
	else if (bw.ie4up && pf.win32 || bw.opera || bw.gecko || bw.nav6up) {
		document.write('<Link rel="stylesheet" href="' + cssfolder + '/ie4up.css" type="text/css">');
		//alert("here1");
	}
	else if (bw.ie4up && pf.macppc) {
		document.write('<Link rel="stylesheet" href="' + cssfolder + '/iemac.css" type="text/css">');
		//alert("here2");
	} else {
		document.write('<Link rel="stylesheet" href="' + cssfolder + '/generic.css" type="text/css">');
		//alert("here3");
	}
}

lib_cssCheck();

function lib_obj(obj){
	this.el = bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval('document.' + obj):0;
	this.css = bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
	this.moveIt = lib_moveIt;
	this.showIt = lib_showIt;
	this.hideIt = lib_hideIt;
	return this;
}

function lib_moveIt(x,y){
	if (x){this.x=x; this.css.left = x;}
	if (y){this.y=y; this.css.top = y;}
}

function lib_showIt(){this.css.visibility = "visible"}
function lib_hideIt(){this.css.visibility = "hidden"}

// DHTML fix detection for Netscape browser resize
if (d.layers) {
	origWidth=innerWidth;
	origHeight=innerHeight;
	onresize=DHTMLfix;
}
		
// DHTML fix for Netscape browser resize
function DHTMLfix() {
	if (origWidth != innerWidth || origHeight != innerHeight) {
		location.reload();
	}
}

function fixNav(){
	if(d.all)history.go(0)
	if (d.layers) {
		DHTMLfix();
	}
}

// X Position Layer relative to anchor image
function get_xPos(object,offset){
	if(d.layers && !d.dom){
		xPos = d.images[object].x
	} else {
		xPos = d.images[object].offsetLeft;
		tempEl = d.images[object].offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
		    tempEl = tempEl.offsetParent;
		}
	}
	if (offset) xPos = xPos + offset;
	return xPos;
}


// Y Position Layer relative to anchor image 
function get_yPos(object,offset){
	if(d.layers && !d.dom){
		yPos = d.images[object].y
	} else {
		yPos = d.images[object].offsetTop;
		tempEl = d.images[object].offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
		    tempEl = tempEl.offsetParent;
		}
	}
	if (offset) yPos = yPos + offset;
	return yPos
}




// rollover functions: add image names in the array
// html usage<a href="index.html" onmouseover="m_rollover('home');" onmouseout="m_rollout('home');">
menu_ar = new Array();
menu_ar[0] = 'item0';
menu_ar[1] = 'item1';
menu_ar[2] = 'item2';
menu_ar[3] = 'item3';
menu_ar[4] = 'item4';
menu_ar[5] = 'item5';
rightmost_menu = menu_ar[5];

delay=300;
active = menu_ar[0];
timer = null;

function load_menu_rollovers(){
	mro_ar = new Array();
	for (var i=0;i<menu_ar.length;i++){
		mro_ar[menu_ar[i]] = new Array();
		mro_ar[menu_ar[i]]['off']=new Image();
		mro_ar[menu_ar[i]]['on']=new Image();
		mro_ar[menu_ar[i]]['off'].src=imgfolder+'m'+menu_ar[i]+".gif";
		mro_ar[menu_ar[i]]['on'].src=imgfolder+'m'+menu_ar[i]+"_on.gif";
	}
}

load_menu_rollovers();

function m_rollover(which){
	document.images[which].src =mro_ar[which]['on'].src;
}

function m_rollout(which){
	document.images[which].src =mro_ar[which]['off'].src;
}


// function called onload to initialize dynamic elements

function init(){
	place_menus();
	loaded = true;
}

// menu placement


function place_menus(){
	mDiv = new Array();
	for (var i=0;i<menu_ar.length;i++){
		mDiv[menu_ar[i]] = new lib_obj('m' + menu_ar[i]);
		mDiv[menu_ar[i]].moveIt(get_xPos(menu_ar[i]),false);
	}
	mDiv[rightmost_menu].moveIt(get_xPos(rightmost_menu,+10),false);
//	mDiv['loc'].moveIt(get_xPos('loc',2),false);
	loaded=true;
}



// menu functions 

function changeActive(which){
	if (loaded){
		clearTimeout(timer);
		mDiv[active].hideIt();
		m_rollout(active);
		active=which;
		mDiv[active].showIt();
		m_rollover(active);

	}
}

function killIt(){
	if (loaded){
		mDiv[active].hideIt();
		m_rollout(active);
	}
}

function killMenu(){
	if (loaded){
		timer = setTimeout("killIt()",delay);
	}
}

function sleep(){
	clearTimeout(timer);
}
