//Menu Code Copyright 2002 by Harold Blackorby/SCORE Interactive
//May not be reused without written permission

function Is() {
  var agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
  this.ns4up = (this.ns && (this.major >= 4));
  this.ns4 = (this.ns && (this.major == 4));
  this.ns6up = (this.ns && (this.major >= 5));
  this.ns7up = (this.ns && (this.major >= 7));
  this.ie = (agent.indexOf("msie") != -1);
  this.ie4up = (this.ie && (this.major >= 4));
  this.win = (agent.indexOf("win")!=-1);
  this.mac = (agent.indexOf("mac")!=-1);
}

var is = new Is();
var screen_width;
var screen_height;
var available_width;
var available_height;
var doc;
var sty;
var htm;
var xdiff;
var ydiff;
var allready;
var prevMenu = "";
var prevSubMenu = "";
var numMenus = -1;
var numSubs = 0;
var aryMenu = new Array();
var arySub = new Array();
var lastTimeout = "";
var rollColor = "#CEBFC6";
var baseColor = "#EFEFEF";
var rollSubColor = "#5a7082";
var baseSubColor = "#798FA1";

// added by Rudi to resolve issues with Netscape 4 in Mac
var NaN;
var showed = "false";


function imgClicked(menu, x, y)
{
	if (showed == "true"){
		showed = "false";
		hideMenu();
	}
	else
	{
		showed = "true";
		showMenu(menu,x,y);
	}
}

function roll(obj) {
//	hideMenu();
}
function rollBack(obj) {
//	hideMenu();
}
function showMenu(menu,x,y)
{
	//hideMenu();
	
	if (allready)
	{
		if (lastTimeout != "")
		{
			clearTimeout(lastTimeout);
			lastTimeout = "";
		}
		lastTimeout = setTimeout("hideMenu();",30000);

		//the following code creates an xoffset for use with a centered page design
		if(is.ns) {
			available_width=innerWidth;
		} 
		else if(is.ie4up) {
			available_width=document.body.clientWidth;
		}		
		available_width = available_width - 760;
		xoffset = parseInt(available_width / 2,10);
//		xoffset = 0;
		
		if (menu.indexOf("sub") == -1)
		{
			menuID = menu.substring(4,menu.length);
//			alert(menuID);
			x = aryMenu[menuID - 1][2];
			y = aryMenu[menuID - 1][3];
		}
		else
		{
			menuID = menu.substring(3,menu.length);
			x = arySub[menuID][3];
			y = arySub[menuID][4];
		}
		
		if (x == "" || x == null)
			x = 0;
		
		if (y == "" || y == null)
			y = 0;

		if (is.ie4up || is.ns4up)
		{
			myLyr = eval(doc + menu + sty);
			if (myLyr)
			{
				myLyr.top = y + ydiff;
				myLyr.left = x + xdiff + xoffset;
				myLyr.visibility = "visible";
				showed = "true";
			}
		}
	}
	prevMenu = menu;
	
}

function hideSubs()
{
	if (allready) {
	if (is.ie4up || is.ns4up) {
		j = 1
		while (j <= numSubs)
		{
			myLyr = eval(doc + arySub[j][1] + sty);
			myLyr.visibility = "hidden";
			j++;
		}
	}
	}
	return true;
}

function hideMenu()
{
	showed = "false";
	if (allready) {
		j = 0
		while (j <= numMenus)
		{
			myLyr = eval(doc + aryMenu[j][1] + sty);
			myLyr.visibility = "hidden";
			j++;
		}
		hideSubs();
	}
	return true;
}

function hideDDMenu()
{
	showed = "false";
	if (allready) {
		j = 0
		while (j <= numMenus)
		{
			myLyr = eval(doc + aryMenu[j][1] + sty);
			myLyr.visibility = "hidden";
			j++;
		}
		hideSubs();
	}
	return true;
}

function hideMenuOne(menu)
{
//	showed = "false";
	if (menu != "" && allready) {
		myLyr = eval(doc + menu + sty);
//		myLyr.visibility = "hidden";
	}
	return true;
}

function changeColor(menu,color)
{
	if (allready) {
		menu = menu.id;	
		myLyr = eval(doc + menu + sty);
		myLyr.background = eval(color);
	}
}

function changeAColor(menu,color)
{
	if (allready) {
		myLyr = eval(doc + menu + sty);
		myLyr.background = eval(color);
	}
}

function writeMenus()
{
	j = 0;
	while (j <= numMenus)
	{
		document.write("<div width='140' name='" + aryMenu[j][1] + "' id='" + aryMenu[j][1] + "' class='menu' ");
		document.write("onMouseOver='showMenu(\"" + aryMenu[j][1] + "\");' ");
		document.write("onMouseOut='hideMenuOne(\"" + aryMenu[j][1] + "\");'>");
		document.write("<TABLE CELLPADDING='0' align='left' CELLSPACING='0' BORDER='0' WIDTH='140' class='mainmenu'>");
		k = 4;
		while (k <= (aryMenu[j].length-1))
		{
			document.write("<TR>");
			document.write("<TD class='white' id='" + aryMenu[j][1] + "sub" + k + "' name='" + aryMenu[j][1] + "sub" + k + "' ");
			document.write("onMouseOver='changeColor(this,\"rollColor\");' onMouseOut='changeColor(this,\"baseColor\");'><A class='textWhite'");
			strhref = new String(aryMenu[j][k+2]);
			splithref = strhref.split(":new:");
			aryMenu[j][k+2] = splithref[0];
			if (strhref.indexOf(":new:") > 0)
			{
				document.write(" HREF='" + aryMenu[j][k+2] + "' target='_blank'");
			}
			else
			{
				document.write(" HREF='" + aryMenu[j][k+2] + "'");
			}
			
			SubMenuID = parseInt(aryMenu[j][k+1],10);
			if ((SubMenuID > 0) && (SubMenuID != NaN))
			{
				document.write(" onmouseover='hideSubs();");
				document.write(" showMenu(\"" + arySub[SubMenuID][1] + "\",");
				document.write(arySub[SubMenuID][2] + "," + arySub[SubMenuID][3] + ")'");
			}
			else
				document.write(" onmouseover='hideSubs();'");
			document.write(">" + aryMenu[j][k] + "</A></TD></TR>");
			k = k + 3;
		}
		document.write("</TABLE>");
		document.write("</div>");
		j++
	}
/*
	j = 1;
	while (j <= numSubs)
	{
		document.write("<div name='" + arySub[j][1] + "' id='" + arySub[j][1] + "' class='menu'");
		document.write(" onMouseOver='showMenu(\"" + arySub[j][1] + "\"); showMenu(\"menu" + arySub[j][0] + "\");'");
		document.write(" onMouseOut='hideMenu();hideSubs();'>");
		document.write("<TABLE CELLPADDING='0' CELLSPACING='0' BORDER='0' WIDTH='132' class='submenu'>");
		k = 5;
		while (k <= (arySub[j].length-1))
		{
			document.write("<TR>");
			document.write("<TD class='blue' id='" + arySub[j][1] + "sub" + k + "' name='" + arySub[j][1] + "sub" + k + "' ");
			document.write("onMouseOver='changeColor(this,\"rollSubColor\");' onMouseOut='changeColor(this,\"baseSubColor\");'><A class='textWhite'");
			
			strsubhref = new String(arySub[j][k+1]);
			splitsubhref = strsubhref.split(":new:");
			arySub[j][k+1] = splitsubhref[0];
			if (strsubhref.indexOf(":new:") > 0)
			{
				document.write(" HREF='" + arySub[j][k+1] + "' target='_blank'");
			}
			else
			{
				document.write(" HREF='" + arySub[j][k+1] + "'");
			}
			
		//	document.write(" HREF='" + arySub[j][k+1] + "'");
			document.write(">" + arySub[j][k] + "</A></TD></TR>");
			k = k + 2;
		}
		document.write("</TABLE>");
		document.write("</div>");
		j++
	}
*/
}

function makeMenu()
{
	numMenus += 1;
	numItems = arguments.length;
	aryMenu[numMenus] = new Array(numItems-1);
	aryMenu[numMenus][0] = arguments[0]
	aryMenu[numMenus][1] = "menu" + arguments[0]
	j = 2;
	while (j <= arguments.length)
	{		
		aryMenu[numMenus][j] = arguments[j-1];
		j++;
	}
}

function makeSub()
{
	numSubs += 1;
	numItems = arguments.length;
	arySub[numSubs] = new Array(numItems-1);
	arySub[numSubs][0] = arguments[1] //the parent menu ID
	arySub[numSubs][1] = "sub" + arguments[0]
	j = 3;
	while (j <= arguments.length)
	{		
		arySub[numSubs][j] = arguments[j-1];
		j++;
	}
}

function startup()
{
	//Basically determines what Document Object Model to use.
	//Note there is one for Netscape 6 >, and IE 4 >.
	//You can also specify a xdifferency and a ydifference to
	//add to the x and y coordinates (to compensate for browser differences)
	screen_width = screen.width;
	screen_height = screen.height;
	if(is.ns4up) {
		available_width=innerWidth;
		available_height=innerHeight;
	} 
	else if(is.ie4up) {
		available_width=document.body.clientWidth;
		available_height=document.body.clientHeight;
	}
	

	if (is.ns6up)
	{
		//alert("Netscape 6!");
		doc = 'document.getElementById("';
		sty = '").style';
		htm = "";
		xdiff = -7;
		ydiff = 10;
		allready = true;
	}
	else if(is.ie4up) {
		//alert("IE!");
		doc = "document.all.";
		sty = ".style";
		htm = "";
		xdiff = 0;
		ydiff = 8;
		allready = true;
	}
	else if(is.ns4) {
		//alert("Netscape 4!");
		doc = "document.";
		sty = "";
		htm = ".document";
		xdiff = -10;
		ydiff = 12;
	}
//	else
	if (is.ns4)
	{
		j = 0;
		while (j <= numMenus)
		{
			myLyr = eval(doc + aryMenu[j][1] + sty);
			j++;
		}
	}
//		allready = false;
	allready = true;
}
