// 07.24.03  modified by Marilyn Olsen to properly show drop-down menus in Opera browser
//
//
// Specific issues with IE and Netscape
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
			&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
			&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4up = (is_nav && (is_major >= 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie4up  = (is_ie  && (is_major >= 4));
var is_opera  = ( agt.indexOf('opera') != -1);
if ( is_opera ) is_nav6 = 1;

if (is_ie4up)    {n=0;ie=1;fShow="visible";fHide="hidden";}
if (is_nav4up) {n=1;ie=0;fShow="show";fHide="hide";}
if (is_nav6) {n=1;ie=0;fShow="visible";fHide="hidden";}

// Prep some vars
lastMenu = null;
window.onerror=new Function("return true")
rightX = leftX = topY = bottomY = 0;
isShowing = false;

// Build the menu
function Menu() {

	// Appearance:
	// -------------------------------------------------------
	this.bgColor = "#f0e68c"; // Main Menu Bar Back Color
	this.subMenuBGColor = "#f0e68c"; // Sub Menu Bar Back Color

	// Font Type
	if (is_ie4up) this.menuFont = "10pt Verdana";
	else this.menuFont = "10pt Verdana";

	this.fontColor = "#00539f"; // Sub Menu Font Color
	this.addItem    = addItem;
	this.addSubItem = addSubItem;
	this.showMenu   = showMenu;

	// Borders and Spacing
	this.mainOuterPaneCellpadding = 0;
	this.mainOuterPaneCellspacing = 0;
	this.mainOuterPaneBorder = 0;
	this.mainOuterPaneBGColor = "#f0e68c";
	this.mainInnerPaneCellpadding = 4;
	this.mainInnerPaneCellspacing = 1;
	this.mainInnerPaneBorder = 0;
	this.subMenuOuterPaneCellpadding = 0;
	this.subMenuInnerPaneCellpadding = 3;
	this.subMenuOuterPaneCellspacing = 0;
	this.subMenuInnerPaneCellspacing = 1;
	this.subMenuOuterPaneBGColor = "#00539f";
	this.subMenuOuterPaneBorder = 0;
	this.subMenuInnerPaneBorder = 0;
	this.subMenuPaneWidth = 255;
	// --------------------------------------------------------


	HTMLstr = "";
	if (is_ie4up) HTMLstr += "<DIV id='MainTable' style='position:relative'>\n";
	HTMLstr += '<TABLE border="'+this.mainOuterPaneBorder+'" width="100%" cellpadding="'+this.mainOuterPaneCellpadding+'" cellspacing="'+this.mainOuterPaneCellspacing+'" bgcolor="'+this.mainOuterPaneBGColor+'"><TR><TD>\n';
	HTMLstr += '<TABLE border="'+this.mainInnerPaneBorder+'" width="100%" cellpadding="'+this.mainInnerPaneCellpadding+'" cellspacing="'+this.mainInnerPaneCellspacing+'" bgcolor="'+this.mainOuterPaneBGColor+'">\n';
	HTMLstr += '<TR bgcolor="'+this.bgColor+'">';
	HTMLstr += "<td> \n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "</TD></TR>\n";
	HTMLstr += "</TABLE></TD></TR>\n";
	HTMLstr += "</TABLE>\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	if (is_ie4up) HTMLstr+= "</DIV>\n";
}

function addItem(idItem, text, lastitem, location) {
	var Lookup = "<!-- ITEM "+idItem+" -->";
	if (HTMLstr.indexOf(Lookup) != -1) {
		alert(idParent + " already exist");
		return;
	}
	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
	if (is_nav4up && !is_nav6) {
		MENUitem += '<ILAYER name="'+idItem+'">';
		MENUitem += '<A href="." class="clsMenuItemNS" onmouseover="displaySubMenu(\''+idItem+'\')" onclick="return true;">';
		MENUitem += text;
		MENUitem += "</A>\n";
		MENUitem += "</ILAYER>\n";
	}
	if (is_ie4up || is_nav6 ) {
		if ( location == null ) location = ".";
		MENUitem += '<SPAN id="'+idItem+'">\n';
		MENUitem += '<A class="clsMenuItemIE" href="'+location+'" style="text-decoration: none;" onmouseover="displaySubMenu(\''+idItem+'\')" onclick="return true;">';
		MENUitem += text;
		MENUitem += "</A>\n";
		MENUitem += "</SPAN>\n";
	}
	if (!lastitem) MENUitem += "&nbsp;|&nbsp;";
	MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
	MENUitem += "<!-- MAIN_MENU -->\n";

	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
}

function addSubItem(idParent, text, hint, location)
{
	var MENUitem = "";
	Lookup = "<!-- ITEM "+idParent+" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		alert(idParent + " not found");
		return;
	}
	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		if (is_nav4up && !is_nav6 )
		{
			MENUitem += "\n";
			MENUitem += '<LAYER id="'+idParent+'submenu" visibility="hide" z-index="2" bgcolor="'+this.subMenuBGColor+'">\n';
			MENUitem += '<TABLE border="'+this.subMenuOuterPaneBorder+'" bgcolor="'+this.subMenuOuterPaneBGColor+'" cellpadding="'+this.subMenuOuterPaneCellpadding+'" cellspacing="'+this.subMenuOuterPaneCellspacing+'" width="'+this.subMenuPaneWidth+'"><TR><TD>\n';
			MENUitem += '<TABLE border="'+this.subMenuInnerPaneBorder+'" bgcolor="'+this.subMenuOuterPaneBGColor+'" cellpadding="'+this.subMenuInnerPaneCellpadding+'" cellspacing="'+this.subMenuInnerPaneCellspacing+'" width="'+this.subMenuPaneWidth+'">\n';
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</TABLE></TD></TR></TABLE>\n";
			MENUitem += "</LAYER>\n";
			MENUitem += "\n";
		}
		if (is_ie4up || is_nav6 )
		{
			MENUitem += "\n";
			MENUitem += "<DIV id='"+idParent+"submenu' style='z-index:2;position:absolute; visibility: hidden; text-decoration: none; width: "+this.subMenuPaneWidth+"; font: "+this.menuFont+"; top: 23;'>\n";
			MENUitem += '<TABLE border="'+this.subMenuOuterPaneBorder+'" bgcolor="'+this.subMenuOuterPaneBGColor+'" cellpadding="'+this.subMenuOuterPaneCellpadding+'" cellspacing="'+this.subMenuOuterPaneCellspacing+'" width="'+this.subMenuPaneWidth+'"><TR><TD>\n';
			MENUitem += '<TABLE border="'+this.subMenuInnerPaneBorder+'" bgcolor="'+this.subMenuOuterPaneBGColor+'" cellpadding="'+this.subMenuInnerPaneCellpadding+'" cellspacing="'+this.subMenuInnerPaneCellspacing+'" width="'+this.subMenuPaneWidth+'">\n';
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</TABLE></TD></TR></TABLE>\n";
			MENUitem += "</DIV>\n";
			MENUitem += "\n";
		}
		MENUitem += "<!-- SUB_MENU -->\n";
		HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
	}

	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	if (is_nav4up || is_opera)  MENUitem = '<TR bgcolor="'+this.subMenuBGColor+'" onmouseover="this.style.backgroundColor=\'#f0e68c\';" onmouseout="this.style.backgroundColor=\'#F0E68C\'"><TD>&nbsp;&#149; <A class="sidebar" title="'+hint+'" href="'+location+'"><FONT color="'+this.fontColor+'" style="font:'+this.menuFont+';">'+text+'</FONT></A><BR></TD></TR>\n';
	if (is_ie4up) MENUitem = '<TR bgcolor="'+this.subMenuBGColor+'" onmouseover="this.className=\'clsMenuItemIEOver\';" onmouseout="this.className=\'clsMenuItemIE\'"><TD>&nbsp;&#149; <A class="sidebar" title="'+hint+'" href="'+location+'"><FONT color="'+this.fontColor+'">'+text+'</FONT></A><BR></TD></TR>\n';
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);

}

function showMenu()
{
	document.writeln(HTMLstr);
}

////////////////////////////////////////////////////////////////////////////
// Private declaration
function displaySubMenu(idMainMenu)
{
	var menu;
	var submenu;
	if ( is_nav6 )
	{
		submenu = document.getElementById(idMainMenu+"submenu");
		if (lastMenu != null && lastMenu != submenu) hideAll();
		submenu.style.left = document.getElementById(idMainMenu).offsetLeft -4;
		submenu.style.top  = document.getElementById(idMainMenu).offsetTop + 65;
		submenu.style.visibility = fShow;

		leftX  = parseInt(document.getElementById(idMainMenu+"submenu").style.left);
		rightX = leftX + parseInt(document.getElementById(idMainMenu+"submenu").style.width);
		topY = document.getElementById(idMainMenu).offsetTop;
		bottomY  = parseInt(document.getElementById(idMainMenu+"submenu").style.top)+parseInt(document.getElementById(idMainMenu+"submenu").offsetHeight);
	} else if (is_nav4up && !is_nav6) {
		submenu = document.layers[idMainMenu+"submenu"];
		if (lastMenu != null && lastMenu != submenu) hideAll();
		submenu.left = document.layers[idMainMenu].pageX - 9;
		submenu.top  = document.layers[idMainMenu].pageY + 21;
		submenu.visibility = fShow;

		leftX  = document.layers[idMainMenu+"submenu"].left;
		rightX = leftX + document.layers[idMainMenu+"submenu"].clip.width;
		topY = document.layers[idMainMenu].pageY;
		bottomY  = document.layers[idMainMenu+"submenu"].top+document.layers[idMainMenu+"submenu"].clip.height;
	} else if (is_ie4up) {
		menu = eval(idMainMenu);
		submenu = eval(idMainMenu+"submenu.style");
		submenu.left = menu.offsetLeft -9;
		submenu.top  = 24;
		submenu.visibility = fShow;
		if (lastMenu != null && lastMenu != submenu) hideAll();

		leftX  = document.all[idMainMenu+"submenu"].style.posLeft;
		rightX = leftX + document.all[idMainMenu+"submenu"].offsetWidth;
		topY = document.all[idMainMenu+"submenu"].offsetParent.offsetTop;
		bottomY  = document.all[idMainMenu+"submenu"].offsetParent.offsetTop + document.all[idMainMenu+"submenu"].style.posTop+
			document.all[idMainMenu+"submenu"].offsetHeight;
	}
	lastMenu = submenu;
	isShowing = true;
}

function hideAll()
{
	if (lastMenu != null) {
		if ( is_nav6 ) {
			lastMenu.style.visibility = "hidden";
		}
		else lastMenu.visibility = fHide;

		lastMenu.left = 0;
		isShowing = false;
	}
}

function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}

// original function updateIt(e)
// original {
// original 	e = e || window.Event || window.event;
// original 	var x = e.pageX || e.clientX;
// original 	var y = e.pageY || e.clientY;
// original
// original 	//window.status = "MouseX:"+x+" MouseY:"+y+" MinX:"+leftX+" MaxX:"+rightX+" MinY:"+topY+" MaxY:"+bottomY;
// original 	if (x > rightX || x < leftX) {
// original 		hideAll();
// original 	} else if (y > bottomY || y < topY) {
// original 		hideAll();
// original 	}
// original }


// modified to properly display in Opera browser.
function updateIt(e)
{
	e = e || window.Event || window.event;
	if (ie&&!is_opera)
	{
	var x = e.clientX;
	var y = e.clientY;

	if (x > rightX || x < leftX) {
		hideAll();
		} else if (y > bottomY || y < topY) {
		hideAll();
		}
	}

	if (n)
	{
	var x = e.pageX;
	var y = e.pageY;

	window.status = "MouseX:"+x+" MouseY:"+y+" MinX:"+leftX+" MaxX:"+rightX+" MinY:"+topY+" MaxY:"+bottomY;
	if (x > rightX || x < leftX) {
		hideAll();
		} else if (y > bottomY || y < topY) {
		hideAll();
		}
	}
}

//function operahide(){
//        if (is_opera){
//        	if (!MainTable.contains(event.toElement))
//        	 hideAll()
//		}
//}


if (is_ie4up)
{
	//document.body.onclick=hideAll;
	document.body.onscroll=hideAll;
	document.body.onmousemove=updateIt;
}
if (is_nav4up || is_opera)
{
	//document.onmousedown=hideAll;
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=updateIt;
}
