// 07.24.03  modified by Marilyn Olsen to properly show drop-down menus in Opera browser
// 01.08.2004  modified some more for opera
//
// 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);
var is_opera7 = (is_opera && (is_major >= 7));
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 = "#A0B7E0"; // Main Menu Bar Back Color
	this.subMenuBGColor = "#eef2f8"; // Sub Menu Bar Back Color
	this.subMenuBGColorOver = "#fafafa"; // Sub Menu Bar Back Color
	this.subMenuBGColor2 = "#fafafa";
	// Font Type
	if (is_ie4up) this.menuFont = "10pt Verdana";
	else this.menuFont = "10pt Verdana";

	this.fontColor = "#000;" // 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 = "#A0B7E0";
	this.mainInnerPaneCellpadding = 4;
	this.mainInnerPaneCellspacing = 1;
	this.mainInnerPaneBorder = 0;
	this.subMenuOuterPaneCellpadding = 0;
	this.subMenuInnerPaneCellpadding = 3;
	this.subMenuOuterPaneCellspacing = 0;
	this.subMenuInnerPaneCellspacing = 1;
	this.subMenuOuterPaneBGColor = "#011f5b";
	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="." 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 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="1" 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='position:absolute; visibility: hidden; text-decoration: none; width: "+this.subMenuPaneWidth+"; font: "+this.menuFont+";'>\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";
	MENUitem = '<TR bgcolor="'+this.subMenuBGColor+'" onmouseover="this.style.backgroundColor=\'#fafafa\';" onmouseout="this.style.backgroundColor=\'#eef2f8\'"><TD>&nbsp;&#149; <A title="'+hint+'" href="'+location+'"><FONT style="font:'+this.menuFont+';">'+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  && !is_opera)
	{
		submenu = document.getElementById(idMainMenu+'submenu');
		if (lastMenu != null && lastMenu != submenu) hideAll();

		submenu.style.left = document.getElementById(idMainMenu).offsetLeft  + -9 + "px";
		submenu.style.top  = document.getElementById(idMainMenu).offsetTop + 115 +"px"; // Change the menu spacing for Netscape start: 123
		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_opera) {
		submenu = document.getElementById(idMainMenu+'submenu');
		if (lastMenu != null && lastMenu != submenu) hideAll();

		submenu.style.left = document.getElementById(idMainMenu).offsetLeft  + -9 + "px";
		submenu.style.top  = document.getElementById(idMainMenu).offsetTop + 114 +"px"; // Change the menu spacing for Opera
		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  =30;  // Change the menu spacing for IE
		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()
{ 	//alert(lastMenu);
	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;
}


// 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();
		}
	}
}

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;
}
