var Flyover_Supported = false;
var Browser_Supported = true;

if (navigator.appName.indexOf('Microsoft') != -1 &&
	navigator.appVersion.indexOf('3.') >= 0)
{
	Browser_Supported = false;
}

if (navigator.userAgent.indexOf("MSIE")    != -1 && 
	navigator.userAgent.indexOf("Windows") != -1 && 
	navigator.appVersion.substring(0,1) > 3)
{
	Flyover_Supported = true;
}

   
if (Flyover_Supported)
{
	var CurFlyoverMenu = "";
	var HTMLStr;
	var x = 0;
	var y = 0;
	var x2 = 0;
	var y2 = 0;
	var ToolbarMenu;
	var ToolbarLoaded = false;
	var aDefICPColor = new Array(4);
	var ICPFont;
	var MaxMenu = 30;
	var TotalMenu = 0;
	var arrMenuInfo = new Array(30);
	var CurFlyover;
	var CurPane;
	
	// Intialize global variables
	ICPFont = "bold x-small Verdana";
	
	aDefICPColor[0]	= "#ffcc66";	// bgcolor;
	aDefICPColor[1] = "#d75c40";	// text font color
	aDefICPColor[2] = "white";		// mouseover font color
	aDefICPColor[3] = "#e77342";	// border color
}

function createFlyover(MenuIDStr, BitmapName, HelpStr, cx, cy, MenuURLStr)
{
	BitmapSrc = "images/nav_" + BitmapName + ".gif";
	if (Flyover_Supported == true)
		AltText = "";
	else
		AltText = HelpStr;

	MenuDisplayStr = "<IMG SRC=\"" + BitmapSrc + "\""
		+ " width='" + String(cx) + "' height='" 
		+ String(cy) + "' BORDER='0' ALT='" 
		+ AltText + "' NAME='_" + MenuIDStr + "'>";

	if (Flyover_Supported == false)
	{
		MenuStr = "<A HREF=\"" + MenuURLStr + "\""
			+ " onmouseout=\"" + "unhighlightImage('_" + MenuIDStr + "','" + BitmapName + "');\""
			+ " onmouseover=\"" + "highlightImage('_" + MenuIDStr + "','" + BitmapName + "');\">"
			+ MenuDisplayStr + "</a>";
		document.write(MenuStr);
		return false;
	}

	// Output style sheet and toolbar ID
	CurFlyover = MenuIDStr + "_span";
	CurPane = MenuIDStr + "_pane";
	document.write("<SPAN ID='" + CurFlyover + "' STYLE='display:none;'></SPAN>");

	MenuStr = "<A ID='AM_" + MenuIDStr + "' HREF=" + "\"" + MenuURLStr + "\""
		+ " onmouseover=" + "\"" + "mouseMenu('over','" + MenuIDStr + "');"
		+ " highlightImage('_" + MenuIDStr + "','" + BitmapName + "');"
		+ " doMenu('"+ MenuIDStr + "');" + "\""
		+ " onmouseout="  + "\"" + "mouseMenu('out' ,'" + MenuIDStr + "');"
		+ " hideMenu(); unhighlightImage('_" + MenuIDStr + "','" + BitmapName
		+ "');" + "\"" + ">" + MenuDisplayStr + "</a>";
	
	HTMLStr = "<DIV ID=\"" + CurPane + "_top\" STYLE='position:relative;height:20;width:100%'>"
		+ "<DIV ID=\"" + CurPane + "\" STYLE='position:absolute;top:0;left:0;height:20;background-color:black;' NOWRAP>"
		+ MenuStr + "</DIV></DIV>"
		+ "<SCRIPT TYPE='text/javascript'>var ToolbarMenu = " + CurFlyover + ";</SCRIPT>"
		+ "<DIV WIDTH=100%>";

	setSubMenuWidth(MenuIDStr, "default", 0);
	return true;
}

function drawFlyover()
{
	HTMLStr += "</DIV>";
	document.write(HTMLStr);
	ToolbarLoaded = true;

	var thisPane = document.all(CurPane);
	thisPane.style.backgroundColor = aDefICPColor[2];
}

function setSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
{
	var fFound = false;
	if (TotalMenu == MaxMenu)
	{
		alert("Unable to process menu. Maximum of " + MaxMenu + " reached.");
		return;
	}
	
	for (i = 0; i < TotalMenu; i++)
		if (arrMenuInfo[i].IDStr == MenuIDStr)
		{
			fFound = true;
			break;
		}

	if (!fFound)
	{
		arrMenuInfo[i] = new menuInfo(MenuIDStr);
		TotalMenu += 1;
	}

	if (!fFound && WidthType.toUpperCase().indexOf("DEFAULT") != -1)
	{
		arrMenuInfo[i].type = "A";
		arrMenuInfo[i].unit = 160;
	}
	else
	{
		arrMenuInfo[i].type = (WidthType.toUpperCase().indexOf("ABSOLUTE") != -1)? "A" : "R";
		arrMenuInfo[i].unit = WidthUnit;
	}
}

// This function creates a menuInfo object instance.
function menuInfo(MenuIDStr)
{
	this.IDStr = MenuIDStr;
	this.type  = "";
	this.unit  = 0;
	this.width = 0;
	this.count = 0;
}

function updateSubMenuWidth(MenuIDStr)
{
	for (i = 0; i < TotalMenu; i++)
		if (arrMenuInfo[i].IDStr == MenuIDStr)
		{
			if (arrMenuInfo[i].width < MenuIDStr.length) 
				arrMenuInfo[i].width = MenuIDStr.length;
			arrMenuInfo[i].count = arrMenuInfo[i].count + 1;
			break;
		}
}

function addSubMenu(MenuIDStr, SubMenuStr, SubMenuURLStr)
{	
	cFont   = ICPFont;
	cColor0 = aDefICPColor[0];
	cColor1 = aDefICPColor[1];
	cColor2 = aDefICPColor[2];
	cColor3 = aDefICPColor[3];
	
	var MenuPos = MenuIDStr.toUpperCase().indexOf("MENU");
	if (MenuPos == -1) { MenuPos = MenuIDStr.length; }
	URLStr = SubMenuURLStr;

	var LookUpTag  = "<!--" + MenuIDStr + "-->";
	var sPos = HTMLStr.indexOf(LookUpTag);
	if (sPos <= 0)
	{
		HTMLStr += "<SPAN ID='" + MenuIDStr + "'" +
				" STYLE='display:none;position:absolute;width:166;background-color:" + cColor0 + ";padding-top:0;padding-left:0;padding-bottom:0;z-index:9;'" +
				" onmouseout='hideMenu();'>";
		HTMLStr += "<HR  STYLE='position:absolute;left:0;top:0;color:" + cColor0 + "' SIZE=1>";
		HTMLStr += "<DIV STYLE='position:relative;left:0;top:0;'>";
		HTMLStr += "<TABLE width='100%' height='100%' cellpadding='8' cellspacing='0' border='1' bgcolor='" + cColor0 + "' bordercolor='" + cColor3 + "'><tr><td>";
	}

	TempStr = 	"<A ID='AS_" + MenuIDStr + "'" +
				"   STYLE='text-decoration:none;cursor:hand;font:" + cFont + ";color:" + cColor1 + "'" +
				"   HREF='" + URLStr + "' TARGET='_top'" +
				" onmouseout="  + "\"" + "mouseMenu('out' ,'" + MenuIDStr + "');" + "\"" + 
				" onmouseover=" + "\"" + "mouseMenu('over','" + MenuIDStr + "');" + "\"" + ">" +
				"&nbsp;" + SubMenuStr + "</A><BR>" + LookUpTag;
	if (sPos <= 0)
		HTMLStr += TempStr + "</td></tr></TABLE></DIV></SPAN>";
	else
		HTMLStr = HTMLStr.replace(LookUpTag, TempStr);	

	updateSubMenuWidth(MenuIDStr);	
}

function addSubMenuLine(MenuIDStr)
{	
	var LookUpTag = "<!--" + MenuIDStr + "-->";
	var sPos = HTMLStr.indexOf(LookUpTag);
	if (sPos > 0)
	{
		cColor  = aDefICPColor[1];
		TempStr = "<HR STYLE='color:" + cColor + "' SIZE=1>" + LookUpTag;
		HTMLStr = HTMLStr.replace(LookUpTag, TempStr);
	}
}

function mouseMenu(id, MenuIDStr) 
{
	IsMouseout = (id.toUpperCase().indexOf("OUT") != -1);

	if (IsMouseout)
	{
		color = aDefICPColor[1];
		if (MenuIDStr == CurFlyoverMenu && aDefICPColor[1] != "") 
			color = aDefICPColor[1];
	}
	else
	{
		color = aDefICPColor[2];
		if (MenuIDStr == CurFlyoverMenu && aDefICPColor[2] != "") 
			color = aDefICPColor[2];
	}
	window.event.srcElement.style.color = color;
}

function doMenu(MenuIDStr) 
{
	var thisMenu = document.all(MenuIDStr);
	if (ToolbarMenu == null || thisMenu == null || thisMenu == ToolbarMenu) 
	{
		window.event.cancelBubble = true;
		return false;
	}

	// Reset dropdown menu
	window.event.cancelBubble = true;
	ToolbarMenu.style.display = "none";
	showElement("SELECT");
	showElement("OBJECT");
	ToolbarMenu = thisMenu;

	// Set dropdown menu display position
	var thisItem = document.all(MenuIDStr + "_pane_top");
	y  = thisItem.offsetTop + thisItem.offsetHeight + 1;
	y2 = y;
	x = thisItem.offsetLeft + 10;
	x2 = x + window.event.srcElement.offsetWidth;
	thisMenu.style.top  = y;
	thisMenu.style.left = x;
	thisMenu.style.clip = "rect(0 0 0 0)";
	thisMenu.style.display = "block";

	// delay 2 millsecond to allow the value of ToolbarMenu.offsetHeight be set
	window.setTimeout("showMenu()", 250);
	return true;
}

function showMenu() 
{
	if (ToolbarMenu != null) 
	{ 
		y2 = y + ToolbarMenu.offsetHeight;

		ToolbarMenu.style.clip = "rect(auto auto auto auto)";
		hideElement("SELECT");
		hideElement("OBJECT");
		hideElement("IFRAME");
	}
}

function hideMenu()
{
	if (ToolbarMenu != null && ToolbarMenu != document.all(CurFlyover)) 
	{
		// Don't hide the menu if the mouse move between the menu and submenus
		cY = event.clientY + document.body.scrollTop;
		if((event.clientX >= (x+5) && event.clientX <= x2) && (cY > (y-10) && cY <= y2))
		{
			window.event.cancelBubble = true;
			return; 
		}

		ToolbarMenu.style.display = "none";
		ToolbarMenu = document.all(CurFlyover);
		window.event.cancelBubble = true;

		showElement("SELECT");
		showElement("OBJECT");
		showElement("IFRAME");
	}
}

function hideElement(elmID)
{
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;

		// Find the element's offsetTop and offsetLeft relative to the BODY tag.
		objLeft   = obj.offsetLeft;
		objTop    = obj.offsetTop;
		objParent = obj.offsetParent;
		while (objParent.tagName.toUpperCase() != "BODY")
		{
			objLeft  += objParent.offsetLeft;
			objTop   += objParent.offsetTop;
			objParent = objParent.offsetParent;
		}
		// Adjust the element's offsetTop relative to the dropdown menu
		objTop = objTop - y;

		if (x > (objLeft + obj.offsetWidth) || objLeft > (x + ToolbarMenu.offsetWidth))
			;
		else if (objTop > ToolbarMenu.offsetHeight)
			;
		else
			obj.style.visibility = "hidden";
	}
}

function showElement(elmID)
{
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;
		obj.style.visibility = "";
	}
}

function highlightImage(n,s) {
	if (Browser_Supported) {
		document.images[n].src= "images/nav_" + s + "_on.gif";
	}
}

function unhighlightImage(n,s) {
	if (Browser_Supported) {
		document.images[n].src= "images/nav_" + s + ".gif";
	}
}

