//Menu Code Copyright 2001 by Harold Blackorby/SCORE Interactive
//May not be reused without permission or copyright

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.ns2 = (this.ns && (this.major == 3));
  this.ns3 = (this.ns && (this.major == 3));
  this.ns4b = (this.ns && (this.minor < 4.04));
  this.ns4up = (this.ns && (this.major >= 4));
  this.ns4 = (this.ns && (this.major == 4));
  this.ns6up = (this.ns && (this.major >= 5));
  this.ie = (agent.indexOf("msie") != -1);
  this.ie3 = (this.ie && (this.major == 2));
  this.ie4up = (this.ie && (this.major >= 4));
  this.ie5up = (this.ie && (this.major >= 5));
  this.op3 = (agent.indexOf("opera") != -1);
  this.win = (agent.indexOf("win")!=-1);
  this.mac = (agent.indexOf("mac")!=-1);
  this.unix = (agent.indexOf("x11")!=-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 aryIntroText = new Array(8);
var lastTimeout = "";
var bgcolor = "#FFFFFF";
var rollcolor = "#EFEFEF";
var loaded = true;
var section =  "";

var to1;

function loadImages() {
	loaded = true;
	startup();
}

function checkPage()
{
	y = 0;
	if (internalPage)
		y = -40;
	else
		y = -9;
	return y;
}

function checkRes()
{
	x = 0;
//	if (screen_width != 1024)
//		x = -10;
//	if (screen_width == 1024 && internalPage)
//		x = -1;
//	if (screen_width > 1024)
//		x = 0;
//	if (screen_width < 800)
//		x = 0;
//	if(internalPage)
//		x = x + 0;
	if (screen_width == 800 && screen_height == 600) 
		x = -10;
	return x;
}

function roll(obj) {
	if (loaded)
	{
		hideAll();
		clearcolor(obj);
		y = checkPage();
		x = checkRes();
		switch (obj)
		{
			case "menu1" :
				showMenu(obj,153+x,203+y);
				break;
			case "menu2" :
				showMenu(obj,153+x,229+y);
				break;
			case "menu3" :
				showMenu(obj,153+x,254+y);
				break;
			case "menu4" :
				showMenu(obj,153+x,279+y);
				break;
			case "menu5" :
				showMenu(obj,153+x,305+y);
				break;
			case "menu6" :
				showMenu(obj,153+x,329+y);
				break;
			case "menu7" :
				showMenu(obj,153+x,355+y);
				break;
		}
	}	
}

function clearcolor(obj){
}

function rollBack(obj) {
}

function showMenu(menu,x,y)
{
	if (allready)
	{
		hideSubs();
		
		//Basically if a new menu isn't opened in so many seconds, it hides all menus.
		//You can change the number of seconds (default 2) by changing the miliseconds below
//		clearTimeout(lastTimeout);
//		lastTimeout = setTimeout("hideMenu2()",6000);
		clearTimeout(to1);
		to1 = setTimeout("hideMenu2()",6000);

		
		//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;
		}

//		alert(available_width + " X " + screen_width);
//		alert(screen_width);

		if (screen_width > 800)
		{
			available_width = available_width - 1024;
			if (available_width < 0)
				available_width = 0;
			xoffset = parseInt(available_width / 2,10) + 122;
		}
		else
		{
			available_width = screen_width - 760;
			if (available_width < 0)
				available_width = 0;
			xoffset = parseInt(available_width / 2,10) + 122;
		}
		
		// Hide the previous menu if this menu isn't a submenu
		if (menu.indexOf("sub") == -1)
		{
			hideMenu();
			prevMenu = menu;
		}
		else if (prevSubMenu != "")
		{
			hideMenuOne(prevSubMenu);
			prevSubMenu = menu;
		}
		
		if (x == "" || x == null)
			x = 0;
		if (y == "" || y == null)
			y = 0;
	
		else if (is.ie4up || is.ns4up)
		{
			myLyr = eval(doc + menu + sty);
			if (myLyr)
			{
				myLyr.top = y + ydiff;
				myLyr.left = x + xdiff + xoffset;
				myLyr.visibility = "visible";
			}
		}
	}
	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 closeFlashMenu()
{
	//window.document.menus.setVariable("change","1");
	if(is.ie4up)
	{
		window.document.menus.setVariable("change","1");
	}
//		var myFlash = document.getElementById("menus").SetVariable("change", "1"); 

}
function hideMenu2()
{
	if (allready) {
	if (is.ie4up || is.ns4up) {
		j = 0;
		while (j <= numMenus)
		{
			myLyr = eval(doc + aryMenu[j][1] + sty);
			if (myLyr.visibility == "visible")
				closeFlashMenu();
			myLyr.visibility = "hidden";
			j++;
		}
		hideSubs();
		clearcolor('');
	}
	}
	return true;
}
function hideMenuTwo()
{	
	to1 = setTimeout("hideMenu2()",300);
	return true;
}

function hideMenu()
{	
	if (allready) {
	if (is.ie4up || is.ns4up) {
		j = 0;
		while (j <= numMenus)
		{
			myLyr = eval(doc + aryMenu[j][1] + sty);
			myLyr.visibility = "hidden";
			j++;
		}
		hideSubs();
		clearcolor('');
	}
	}
	return true;
}
function hideAll()
{
	hideMenu();
}

function hideMenuOne(menu)
{
	if (menu != "" && allready) {
	if (is.ie4up || is.ns4up) {
		myLyr = eval(doc + menu + sty);
		myLyr.visibility = "hidden";
	}
	}
}

function changeColor(menu)
{	
//	clearTimeout(lastTimeout);
//	lastTimeout = setTimeout("hideMenu2()",6000);
	clearTimeout(to1);
	to1 = setTimeout("hideMenu2()",6000);

	if (allready) {
	if (is.ie4up || is.ns4up) {
		menu = menu.id;	
		myLyr = eval(doc + menu + sty);
		myLyr.background = rollcolor;
		if (is.ns4up) {
			myLyr.backgroundColor = rollcolor;
		}
	}
	}
}

function changeColorBack(menu)
{
	if (allready) {
	if (is.ie4up || is.ns4up) {
		menu = menu.id;
		myLyr = eval(doc + menu + sty);
		myLyr.background = bgcolor;
		if (is.ns4up) {
			myLyr.backgroundColor = bgcolor;
		}
	}
	}
}

function writeMenus()
{
	j = 0;
	while (j <= numMenus)
	{
		document.write("<div onmouseover='clearTimeout(to1);' onmouseout='hideMenuTwo();' name='" + aryMenu[j][1] + "' id='" + aryMenu[j][1] + "' class='menu'>");
		document.write("<TABLE CELLPADDING='0' CELLSPACING='0' BORDER='0' WIDTH='140' class='mainmenu'>");
		k = 4;
//		document.write("<TR><TD bgcolor='#FFFFFF'><table border=0 cellpadding=0 cellspacing=0><tr><td>&nbsp;</td><td style='color:#92A0A6; font-size:10px;'>" + aryIntroText[j+1] + "</td><td>&nbsp;</td></tr></table></td></TR>");
		document.write("<TR><TD height='1' bgcolor='#92A0A6'><img src='http://www.oceanfutures.org/graphics/blank.gif' width='140' height='1'></td></TR>");
//		document.write("<TR><TD height='1' background='../graphics/thESource/dottedline.gif'><img src='../graphics/blank.gif' width='140' border=0 height='1'></td></TR>");
		while (k <= (aryMenu[j].length-1))
		{
			if (k!=4)
			{
				document.write("<TR><TD height='1' background='../graphics/thESource/dottedline.gif'><img src='../graphics/blank.gif' width='140' border=0 height='1'></td></TR>");	
			}
				
			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);' onMouseOut='changeColorBack(this);' onclick='location.href=\"" + aryMenu[j][k+2] + "\";'><table border=0 cellpadding=0 cellspacing=0><tr><td width=5>&nbsp;</td><td width=128><div class='textWhite'><A style='color:#1A388A; text-decoration: none;'");
			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></div></td><td width=7 valign=bottom><img valign=bottom src='../graphics/thESource/arrow_whitebg.gif' border=0></td></tr></table></TD></TR>");		
		//	document.write("<TR><TD height='1' background='../graphics/thESource/dottedline.gif'><img src='../graphics/blank.gif' width='140' border=0 height='1'></td></TR>");
			k = k + 3;
		}
		document.write("<TR><TD height='1' bgcolor='#92A0A6'><img src='http://www.oceanfutures.org/graphics/blank.gif' width='140' height='1'></td></TR>");
		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();'>");
		document.write("<TABLE CELLPADDING='0' CELLSPACING='0' BORDER='0' WIDTH='140' class='submenu' bgcolor='#336091'>");
		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' style='color: white;'");
			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 4, Netscape 6, and IE.
	//You can also specify a xdifferency and a ydifference to
	//add to the x and y coordinates (to compensate for browser differences)
	loaded = true;
	
	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.ns4) {
		//alert("Netscape 4!");
		doc = "document.";
		sty = "";
		htm = ".document";
		xdiff = -8;	
		ydiff = 14;
	}
	else if (is.ns6up || is.ie5up)
	{
		//alert("W3C");
		doc = 'document.getElementById("';
		sty = '").style';
		htm = "";
		xdiff = -0;
		ydiff = 14;
	}
	else if(is.ie4up) {
		//alert("IE!");
		doc = "document.all.";
		sty = ".style";
		htm = "";
		if (is.mac)
		{
			ydiff = 10;
		}
		else
			ydiff = 14;

		xdiff = 0;		

	}
	//Ensures that the menus work in NS 4. Must be done for each menu.
	if (is.ns4)
	{
		j = 0;
		while (j <= numMenus)
		{
			myLyr = eval(doc + aryMenu[j][1] + sty);
			j++;
		}
	}
	allready=true;
}