//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.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 lastTimeout = "";

// added by Rudi to resolve issues with Netscape 4 in Mac
var NaN;

function showMenu(menu,x,y)
{
	if (allready)
	{
		hideSubs();		
		
		//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("hideMenu();",2000);
	
	
		// 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;
		}
		
		//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);
		if (menu.indexOf("sub") == -1)
		{
			menuID = menu.substr(4,menu.length - 1);
			x = aryMenu[menuID-1][2];
			y = aryMenu[menuID-1][3];
		}
		else
		{
			menuID = menu.substr(3,menu.length - 1);
			x = arySub[menuID][2];
			y = arySub[menuID][3];
		}
		
		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";
			}
		}
	}
	prevMenu = menu;
}

function hideSubs()
{
	if (allready) {
	if (is.ie4up || is.ns4up) {
		j = 1
		while (j <= numSubs)
		{
			myLyr = eval(doc + arySub[j][1] + sty);
			//myLyr.top = 0;
			//myLyr.left = 0;
			myLyr.visibility = "hidden";
			j++;
		}
	}
	}
	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";
			//myLyr.top = 0;
			//myLyr.left = 0;
			j++;
		}
		hideSubs();
	}
	}
	return true;
}

function hideMenuOne(menu)
{
	if (menu != "" && allready) {
	if (is.ie4up || is.ns4up) {
		myLyr = eval(doc + menu + sty);
		myLyr.visibility = "hidden";
		//myLyr.top = 0;
		//myLyr.left = 0;
	}
	}
}

function changeColor(menu)
{	
	clearTimeout(lastTimeout);
	lastTimeout = setTimeout("hideMenu();",2000);	
}

function changeText(menu)
{	
	menu.className = "textBlue";
}
function changeTextBack(menu)
{	
	menu.className = "textWhite";
}

function writeMenus()
{
	j = 0;
	while (j <= numMenus)
	{
		document.write("<div 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;
		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);'><A class='textWhite' onmouseout='changeTextBack(this);'");
			document.write(" HREF='" + aryMenu[j][k+2] + "'");
			SubMenuID = parseInt(aryMenu[j][k+1],10);
			if ((SubMenuID > 0) && (SubMenuID != NaN))
			{
				document.write(" onmouseover='showMenu(\"" + arySub[SubMenuID][1] + "\",");
				document.write(arySub[SubMenuID][2] + "," + arySub[SubMenuID][3] + "); changeText(this);'");
			}
			else
				document.write(" onmouseover='hideSubs(); changeText(this);'");
			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] + "\"," + arySub[j][2] + "," + arySub[j][3] + ");'");
		document.write(" onMouseOut='hideMenuOne(\"" + arySub[j][1] + "\");'>");
		document.write("<TABLE CELLPADDING='0' CELLSPACING='0' BORDER='0' WIDTH='140' class='mainmenu'>");
		k = 4;
		while (k <= (arySub[j].length-1))
		{
			document.write("<TR>");
			document.write("<TD class='white' id='" + arySub[j][1] + "sub" + k + "' name='" + arySub[j][1] + "sub" + k + "' ");
			document.write("onMouseOver='changeColor(this);'><A class='textWhite' onmouseout='changeTextBack(this);' onmouseover='changeText(this);'");
			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[0]
	arySub[numSubs][1] = "sub" + arguments[0]
	j = 2;
	while (j <= arguments.length)
	{		
		arySub[numSubs][j] = arguments[j-1];
		j++;
	}
}

function SCOREswapImgRestore() { //v3.0
  var i,x,a=document.SCOREsr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function SCOREpreloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.SCOREp) d.SCOREp=new Array();
    var i,j=d.SCOREp.length,a=SCOREpreloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.SCOREp[j]=new Image; d.SCOREp[j++].src=a[i];}}
}

function SCOREfindObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=SCOREfindObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function SCOREswapImage() { //v3.0
  var i,j=0,x,a=SCOREswapImage.arguments; document.SCOREsr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=SCOREfindObj(a[i]))!=null){document.SCOREsr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function startup()
{
	//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)
	
	if(is.ns4) {
		//alert("Netscape 4!");
		doc = "document.";
		sty = "";
		htm = ".document";
		xdiff = -8;
		ydiff = -4;
	}
	else if (is.ns6up)
	{
		//alert("Netscape 6!");
		doc = 'document.getElementById("';
		sty = '").style';
		htm = "";
		xdiff = 0;
		ydiff = 8;
	}
	else if(is.ie4up) {
		//alert("IE!");
		doc = "document.all.";
		sty = ".style";
		htm = "";
		xdiff = 0;
		ydiff = 8;
	}

	//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;
	SCOREpreloadImages('images/productsb.jpg','images/servicesb.jpg','images/trainingb.gif','images/chemicalb.jpg','images/powerb.jpg','images/lifesciences_b.jpg','images/contractorb.jpg','images/refiningb.jpg','images/gasb.jpg','images/foodb.jpg','images/aboutb.gif','images/contactb.gif','images/sitemapb.gif','images/privacyb.jpg','images/industriesb.jpg','images/plantb.jpg');
}