var agt=navigator.userAgent.toLowerCase(); 
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1)); 
var is_nav3 = (is_nav && (parseInt(navigator.appVersion) == 3)); 
var is_nav4 = (is_nav && (parseInt(navigator.appVersion) == 4)); 
var is_nav4up = (is_nav && (parseInt(navigator.appVersion) >= 4)); 
var is_nav5up = (is_nav && (parseInt(navigator.appVersion) >= 5)); 
var is_ie   = (agt.indexOf("msie") != -1); 
var is_ie3  = (is_ie && (parseInt(navigator.appVersion) < 4)); 
var is_ie4  = (is_ie && (agt.indexOf("msie 4")!=-1)); 
var is_ie4up  = (is_ie  && (parseInt(navigator.appVersion) >= 4)); 
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4); 
var is_mac    = (agt.indexOf("mac")!=-1);
var is_ie50   = (is_ie && (agt.indexOf("msie 5.0")!=-1)); 

if (is_ie5up || is_nav5up)
	gShowMenus = true;
else
	gShowMenus = false;

var gCurNav='';

function writeMenus() {	
	for (var j=0;j<menus.length;j++) {
		document.writeln('<tr valign="top">');
		menuid=menus[j][0];
		menutitle=menus[j][1];
		menuhref=menus[j][2];
		menuleveltwo=menus[j][3];
		if (menuhref=='') {
			menuhref='#';
		}		
		if (gShowMenus) {
			if (menuleveltwo==1) {
				//this nav has popup menus
				s="showMenu('"+menuid+"');menuTimer(1);";
				t="menuTimer(0);gCurNav='"+menuid+"'";
			} else {
				s="";
				if (thisMenuName==menuid)
					//this nav is nav name of this page - don't turn off hover
					t="";
				else
					t="this.className='firstlevelnav';";
			}
			if (thisMenuName==menuid)
				//nav with pop up menu and nav name of this page
				document.writeln('<td onmouseover="hideMenus();'+s+'" onmouseout="'+t+'" onclick="location.href=\''+menuhref+'\';" id="TD'+menuid+'" class="firstlevelnavhover"><small>');
			else
				//nav with pop up menu
				document.writeln('<td onmouseover="hideMenus();this.className=\'firstlevelnavhover\';'+s+'" onmouseout="'+t+'" onclick="location.href=\''+menuhref+'\';" id="TD'+menuid+'" class="firstlevelnav"><small>');
		} else {
			if (thisMenuName==menuid)
				//nav with no pop up menu and nav name of this page
				document.writeln('<td onclick="location.href=\''+menuhref+'\';" class="firstlevelnavhover"><small><a href="'+menuhref+'" class="firstlevelnavlinkon">');
			else
				//nav with no pop up menu
				document.writeln('<td onmouseover="this.className=\'firstlevelnavhover\';" onmouseout="this.className=\'firstlevelnav\';" onclick="location.href=\''+menuhref+'\';" class="firstlevelnav"><small><a href="'+menuhref+'" class="firstlevelnavlink">');
		}
		document.writeln(''+menutitle+'<\/a></small><\/td>');
		document.writeln('<td><img src="/images/pixel.gif" alt="" width="1" height="1" border="0" id="IM'+menuid+'"><\/td>');
		document.writeln('</tr>');
		document.writeln('<tr><td colspan="2" style="background-image: url(/images/ln_divider.gif); background-repeat: repeat-x;"><img src="/images/pixel.gif" alt="" width="1" height="2" border="0"><\/td><\/tr>');
	}
}

var gActiveMenus =  new Array();
// writeMenuLayers was changed to writeMenuLevelTwo
function writeMenuLevelTwo() {
	if (gShowMenus) {
		for(j=0;j<menus.length;j++) {
			menu_name=menus[j][0];
			dosub=menus[j][3];
			if (dosub==1) {
				gActiveMenus[gActiveMenus.length]=menu_name;
				eval('k=menus_'+menu_name+'.length');
				document.writeln('<div id="menu'+menu_name+'" class="menu">');
				document.writeln('<table cellpadding="0" cellspacing="0" width="167" border="0" style="border: 1px solid #000;" onmouseout="menuTimer(0);" onmouseover="menuTimer(1);">');
				for (i=0;i<k;i++) {
					eval('mTitle=menus_'+menu_name+'['+i+'][0]');
					eval('mHref=menus_'+menu_name+'['+i+'][1]');
					document.writeln('<tr valign="top">');
					document.writeln('<td onmouseover="this.className=\'secondlevelnavhover\';" onmouseout="this.className=\'secondlevelnav\';" class="secondlevelnav" onclick="location.href=\''+mHref+'\';"><small>'+mTitle+'</small><\/td>');
					document.writeln('<\/tr>');
				}
				document.writeln('<\/table>');
				document.writeln('<\/div>');
			}
		}
	}
}

function hideMenus() {
	//turn off nav hover for this menu except if it's nav of this page
	if (gCurNav!='' && gCurNav!=thisMenuName) {
		eval('document.getElementById("TD'+gCurNav+'").className="firstlevelnav"');
		gCurNav='';
	}
	//hide layers
	for(j=0;j<gActiveMenus.length;j++) {
		eval('document.getElementById("menu'+gActiveMenus[j]+'").style.visibility = "hidden"');
	}
}

function showMenu(menu_id) {

    //padding between cells in left hand nav
    LeftNavPad=2;

	//set offsets for menu popup positioning
	if (is_mac && is_ie5up) {
		var xPos = 1;
		var yPos = -2;
	} else {
		var xPos = 1;
		var yPos = -2;
	}
	//calculate layer position based on menu nav position
	var elem = document.getElementById('IM'+menu_id);
	while (elem.offsetParent != null) {
		xPos += elem.offsetLeft;
		yPos += elem.offsetTop;
		elem = elem.offsetParent;
	}
	xPos += elem.offsetLeft;
	yPos += elem.offsetTop;
	yHeight = document.getElementById('menu'+menu_id).offsetHeight;

    //calculate height of window
    if (typeof(window.innerWidth) == 'number') {
        yClip = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        yClip = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { 
        yClip = document.body.clientHeight;
    }

    //show menu 'bottom up' if getting clipped by bottom of window
	if (yPos+yHeight>yClip) {
	    yPos -= document.getElementById('menu'+menu_id).offsetHeight - document.getElementById('TD'+menu_id).offsetHeight - LeftNavPad * 2;
	    
	    //recalc top if top is getting clipped
	    if (yPos<5) {
	        yPos += -yPos + 5;
	    }
	}
	//set layer position
	if (is_nav5up) {
		eval('document.getElementById("menu'+menu_id+'").style.left = xPos');
		eval('document.getElementById("menu'+menu_id+'").style.top = yPos');
	} else {
		eval('document.getElementById("menu'+menu_id+'").style.pixelLeft = xPos');
		eval('document.getElementById("menu'+menu_id+'").style.pixelTop = yPos');
	}
	//show layer
	eval('document.getElementById("menu'+menu_id+'").style.visibility = "visible"');
}

var gTimer;
function menuTimer(t)  {
	if (t==0)
		gTimer = setTimeout('hideMenus()', 500);
	if (t==1)
		clearTimeout(gTimer);
}