//	Configure these variable only
var mainbgColor	= "#000000";
var subbgColor 	= "#000000";
var mainHeight  = 20;
var mainWidth	= 780;
var subWidth	= 200;
var subYpos		= [90,123,123];

//	List all browsers here. No need to touch this
var ie, ns, ns6;
// Check for IE4 or above.
if (document.all)
	ie=1;
// Check for NS4.51 or above.
if (document.layers)
	ns=1;
//	Check for NE6
if (document.getElementById&&!document.all)
	ns6=1;



var x, y; // use for loops.
var TheLastID=0; // Keep track of the last ID, so we know which one to close each time.
var HTMLstr = "";
var d = document;
var Xco, Yco;

/*
window.onerror = myError;
function myError(message, url, line)
{
alert ("ERROR\n\nMESSAGE: "+message+"\n\nFILE: "+url+ "\n\nLINE NO.: "+line);
return true;
}
*/

function Top()
{
	HTMLstr += "<table cellspacing='0' cellpadding='0' width='" + mainWidth+ "' bgcolor='" + mainbgColor+ "' border='0'>";
	HTMLstr += "<tr><td width='1'>&nbsp;</td><td height='" + mainHeight + "' valign='center'>";
	d.write(HTMLstr);
	HTMLstr="";
}

function Bottom()
{
	HTMLstr += "</td></tr></table>";
	d.write(HTMLstr);
	HTMLstr ="";
}

function prepMainMenu()
{
	var MENUitem = "";
	for(x=0;x<addMenuItem.length;x++)
	{
		MENUitem += "<span id='Main" + x + "' class='measurable'><a href='";

		if(addMenuItem[x][2])
			MENUitem += addMenuItem[x][2];
		else
			MENUitem += "#";

		MENUitem +="' class='top' ";

		if(!addMenuItem[x][2])
			MENUitem +="onmouseover='displaySubMenu(" + x + ")'";
		else
			MENUitem +="onmouseover='displaySubMenu(-1)'";

		MENUitem += " onclick="; 

		if(addMenuItem[x][2])
			MENUitem += "''";
		else
			MENUitem += "'return false;'";

		MENUitem +=">" + addMenuItem[x][1] + "&nbsp;&nbsp;&nbsp;&nbsp;" + "</a></span>";
	}
	d.write(MENUitem);
	MENUitem = "";
}

function prepSubMenus()
{
	var SM = "";

	for(x=addSubMenuItem[0][0];x<=addSubMenuItem[addSubMenuItem.length-1][0];x++)
	{
		if(ie||ns6)
			SM += "<div id='Sub" + x + "' style='visibility:hidden;position:absolute;width:relative;' onmouseover='IEBum(0)' onmouseout='IEBum(1)'>";
		if(ns)
			SM += "<div id='Sub" + x + "' class='cMenu'>";
	//	if(ns6)
	//		SM += "<div id='Sub" + x + "' style='visibility:hidden;position:absolute;width:relative;'>"; 

		SM += "<table border='0' bgcolor='" +subbgColor+ "' cellspacing=0 cellpadding=0 width='" + subWidth + "'>"; 
		for(y=0;y<addSubMenuItem.length;y++)
		{
			if(addSubMenuItem[y][0] == x)
			{
				SM += "<tr><td height='13' valign='center'>&nbsp;";
				if (ie||ns6) 
					SM += "<a href='"+addSubMenuItem[y][2]+ "' id='link' class='top' onmouseover='IEBum(0)'>"; 
				else
					SM += "<a href='" + addSubMenuItem[y][2] + "' id='link' class='top'>";
				SM += addSubMenuItem[y][1] + "</a></td></tr>";
			}
		}

		SM +="</table></div>";
		d.write(SM);
		SM = "";
	}
}

/* 
   IE is a bummer for hiding layers with links in them this function is IE specific, Many many many 
   many other ways of resolving this issue so I chose one, the cleanest way, but not the most portable one.
*/

function IEBum(num) 
{
	if(ie)
	{
		if (num==0) d.all["Sub"+TheLastID].style.visibility='visible';
		if (num==1) d.all["Sub"+TheLastID].style.visibility='hidden';
	}
	if(ns6)
	{
		if (num==0) d.getElementById("Sub"+TheLastID).style.visibility='visible';
		if (num==1) d.getElementById("Sub"+TheLastID).style.visibility='hidden';
	}
}

function hideLast() 
{
	if(ie)	{d.all["Sub" + TheLastID].style.visibility = 'hidden';}
	if(ns)	{d.layers["Sub" + TheLastID].visibility = 'hide';}
	if(ns6) {d.getElementById("Sub" + TheLastID).style.visibility='hidden';}
}

function displaySubMenu(idIt)
{
	hideLast(); // before doing anything else close the last ID
	var Sub  = "Sub" + idIt
	var Main = "Main" + idIt;
	if(idIt==-1) return /* No sub Menu to display so return early, just before hideLast is run */
		
	if(ie) 
	{
		Yco = subYpos[0];
		Xco = d.all[Main].offsetLeft;
		d.all[Sub].style.left = Xco;
		d.all[Sub].style.top  = Yco;
		d.all[Sub].style.visibility = 'visible';
	}	

	if(ns)
	{
		Yco = subYpos[1]; 
		Xco = d.layers[Main].pageX;
		d.layers[Sub].left = Xco;
		d.layers[Sub].top  = Yco;	
		d.layers[Sub].onmouseout = function () {this.visibility = 'hide';}
		d.layers[Sub].visibility='show';
	}

	if(ns6)
	{
		Yco = subYpos[2];
		Xco = d.getElementById(Main).offsetLeft;
		d.getElementById(Sub).style.left = Xco;
		d.getElementById(Sub).style.top  = Yco;
		d.getElementById(Sub).style.visibility = 'visible';
	}

	TheLastID = idIt;
}

function outsideSub(e)
{
	var xx, yy;
	
	if (ie) { xx = window.event.clientX; yy = window.event.clientY; }
	if (ns)	{ xx = e.pageX;yy = e.pageY; }
	if (ns6){ xx = e.pageX;yy = e.pageY; }
       
	if ((xx > (Xco+subWidth)) || (xx < Xco))
		hideLast();
}

if(ns) 
{
	Top();
	prepMainMenu();
	Bottom();
	prepSubMenus();
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=outsideSub;
}

if(ie)
{
	Top();
	prepMainMenu();
	Bottom();
	prepSubMenus();
	document.body.onmousemove=outsideSub;
}

if(ns6)
{
	Top();
	prepMainMenu();
	Bottom();
	prepSubMenus();
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=outsideSub;
}

