//GLOBAL VARIABLES
var isOpen;
var menuArray;
var topbarp;
var yposition;
var lineheight;
var linecolor1;
var fontofcolor;
var headconstant;
var headconstandlarge;
var bodyconstant;
var bodyconstantlarge;
var hfontsize;
var bfontsize;
var barheight;
var count;
var bottomup;
var addperitem;
var lineheight2;
var strDivs;
var wasAltered;

function initMenus (tbar) {//TELLS WHERE TO POSITION THE MENUS
	stayvis = 0;
        wasAltered = "";

	menuArray = new Array();
	isOpen = new Array();
	isOpen[0]="no";
	bottomup = "";
	for ( x = 1; x<50; x++) {
		menuArray[x] = new dhtmlMenu();
	}
	//If you edit backgcolor, you must also edit values within the css style sheet
	topbarp = tbar;
	yposition = topbarp+59;
	lineheight  = 1; // Line on top
	lineheight2 = 13; // Divider lines
	linecolor1 = "#CC9900";
	count = 0;
	backgcolor = "#000000";
	//This controls the color of the "divider" bars and font in IE/NS 3.0 only, to change the actual text color, change the
	//color in the stylesheet item A.menuitem
	fontofcolor = "#CC9900"; 
	fontoncolor = "#CC9900"; //Mouseovers

	//These control how much space the program leaves for each character within the width
	//you need to change these if you alter to font size to get the menus to space properly
	//within Netscape
	headconstant = 6;
	headconstantlarge = 5.6;
	bodyconstant = 8;
	bodyconstantlarge = 8;
	//These control the header and body font sizes in Netscape and IE 3.x respectively
	hfontsize= 2;
	bfontsize = 2;
	barheight = 20;
	var addperitem=20;
}

// automatically create the "whatbrowser" object to detect browser versions
whatbrowser = new BrowserCheck();

// function dhtmlMenu is used to create objects to hold one Menu to display
// dhtml menus store the status of use, as well as the style information to correctly
// position the menus
function dhtmlMenu ( used, height, xpos) {
	this.used = used;
	this.height = height;
	this.xpos = xpos;
	this.linkText = new Array();
	this.linkURL = new Array();
	this.targetFrame = new Array();
	this.maxlength = 0;
	this.usedlink = new Array();
	return true;
}

//Function addMenuHead searches for the first available index and places the information given
//as well as creating the arrays needed to store more links
function addMenuHead ( alinkText, alinkURL, atargetFrame) {
	var counter1 = 1;
	while ( menuArray[counter1].used != null ) {
		counter1++;
	}
	if (counter1 == 1) {
		menuArray[counter1].xpos = 0;
	}
	else {
		if (menuArray[(counter1 - 1)].linkText[1].length < 10) {
		menuArray[counter1].xpos = (menuArray[(counter1 - 1)].linkText[1].length)*headconstant + menuArray[(counter1-1)].xpos+15;
		}
		else {
		menuArray[counter1].xpos = (menuArray[(counter1 - 1)].linkText[1].length)*headconstantlarge + menuArray[(counter1-1)].xpos+15;
		}
	}
		
	//Assigning various attributes for this particular menu
	menuArray[counter1].height = addperitem;
	menuArray[counter1].used = "yes";
	menuArray[counter1 + 1].used = null;
	menuArray[counter1].linkText = new Array();
	menuArray[counter1].linkURL = new Array();
	menuArray[counter1].targetFrame = new Array();
	menuArray[counter1].usedlink = new Array();
	menuArray[counter1].linkText[1] = alinkText;
	menuArray[counter1].linkURL[1] = alinkURL;
	menuArray[counter1].targetFrame[1] = atargetFrame;
	menuArray[counter1].usedlink[1] = "yes";
	menuArray[counter1].usedlink[2] = null;
	menuArray[counter1].maxlength = menuArray[counter1].linkText[1].length;	
	
}


// Function addMenuItem will take the menu number, the link Text, the URL and the target frame
// and add them to the specified menu, in the first available location.
// It will also increase the height of the menu and will make the array for the next link null
function addMenuItem ( amenuHeader, alinkText, alinkURL, atargetFrame) {
	var counter1 = 1;
	var amenuNumber = -1;
	while ( menuArray[counter1].used != null ) {
		if (menuArray[counter1].linkText[1] == amenuHeader) {
			amenuNumber = counter1;
		} 
		counter1++;
	}
	if (amenuNumber == -1) {
		document.writeln("INVALID HEADER CODE - menu "+amenuHeader+" with text "+alinkText+" "+alinkURL+" Does not exist");
		document.writeln(" Please Check code");
		return;
	}
	
	menuArray[amenuNumber].height += addperitem;
	var counter2=2;
	while (menuArray[amenuNumber].usedlink[counter2] == "yes" ) {
		counter2++;
	}
	
	menuArray[amenuNumber].usedlink[counter2]= "yes";
	menuArray[amenuNumber].usedlink[counter2 + 1] = null;
	menuArray[amenuNumber].linkText[counter2] = alinkText;
	menuArray[amenuNumber].linkURL[counter2] = alinkURL;
	menuArray[amenuNumber].targetFrame[counter2] = atargetFrame;
	if ( menuArray[amenuNumber].linkText[counter2].length > menuArray[amenuNumber].maxlength) {
		menuArray[amenuNumber].maxlength = menuArray[amenuNumber].linkText[counter2].length ;
	}
	return;
}

	
	
// Function renderMenu will render the menus that are specificed in the menuArray
// This function must be completely different for Netscape and IE.
function renderMenu() {
	
	// THIS CODE IS NETSCAPE NAVIGATOR 4.0 SPECIFIC
	if ((whatbrowser.ns) && (!whatbrowser.ns6) && (!whatbrowser.opera))  {
		barheight=24;
		//strHTML will be used to store the entire string to write within netscape
		var strHTML ="";
		var strLayers ="";
		var counter3 = 1;
		var widthofdoc = "100%";
		var lastxpos;
		
		strHTML += "<layer top='"+topbarp+"' left='0' height='"+barheight+"' bgcolor='"+backgcolor+"'><table noresize width=100% class='tablehead' border='0' cellpadding='0' cellspacing='0' height='"+barheight+"' bgcolor='"+backgcolor+"' valign='top' align='left'><tr>";
		while ( menuArray[counter3].used  ==	"yes" ) {
		var linkcounter = 1;
			var idofDiv="aa" + counter3;
			var newzindex = counter3+25
			var objheight = menuArray[counter3].height;
			var objwidth = menuArray[counter3].maxlength*bodyconstantlarge+5;
			//These statements output the layer that holds all the information about the menu currently being rendered
			varnewZindex = counter3 + 25;
			strLayers += "<layer name='"+idofDiv+"' bgcolor='"+backgcolor+"'  visibility='hide'  top='"+yposition+"' left='"+menuArray[counter3].xpos+"' width='"+objwidth+"' height='"+(menuArray[counter3].height-20)+"' zIndex='"+varnewZindex+"' onMouseOver='showbottom(\""+idofDiv+"\")' onMouseOut='hidebottom(\""+idofDiv+"\")'>";
			lastxpos = menuArray[counter3].xpos;
			while ( menuArray[counter3].usedlink[linkcounter] == "yes" ) {
				
				var linkAdd= menuArray[counter3].linkURL[linkcounter];
				var targetAdd = menuArray[counter3].targetFrame[linkcounter];
				var wrlinkText = menuArray[counter3].linkText[linkcounter];
				if ( linkcounter==1 ) {
					if (menuArray[counter3].height != addperitem) {
					strHTML += "<td nowrap valign='top' align='left'>&nbsp;<font  color='"+fontofcolor+"' size='"+hfontsize+"'><a class='menuheader' href='"+linkAdd+"' target='"+targetAdd+"' onMouseOver='showtop(\""+idofDiv+"\")' onMouseOut='hidetop(\""+idofDiv+"\")'>"+wrlinkText+"</a>&nbsp;&nbsp;|&nbsp;</font></td>";
					}
					else {
					strHTML += "<td nowrap valign='top' align='left'>&nbsp;<font  color='"+fontofcolor+"' size='"+hfontsize+"'><a class='menuheader' href='"+linkAdd+"' target='"+targetAdd+"'>"+wrlinkText+"</a>&nbsp;&nbsp;|&nbsp;</font></td>";
					}
				}
				else {
					if (linkcounter==2) {
						strDivs += "<span class='linething'><img src='images/wt_thing.gif' height='"+lineheight+"' width='"+objwidth+"'></span><br>";
					}
					if (targetAdd == "NOLINK" ) {
						strLayers += "<span class='menuitem'>&nbsp;<font  color='"+fontofcolor+"' size='"+bfontsize+"'><span class='menuitem' >"+wrlinkText+"</span></font></span><br>";
					}
					else if (targetAdd == "LINE" ) {
						strLayers += "<img src='images/wt_thing2.gif' height='"+lineheight2+"' width='"+objwidth+"'><br>";	
					}
					else {
						strLayers += "<span class='menuitem'>&nbsp;<font  color='"+fontofcolor+"' size='"+bfontsize+"'><a class='menuitem' href='"+linkAdd+"' target='"+targetAdd+"' >"+wrlinkText+"</a></font></span><br>";
					}	
				}
				linkcounter++;
			}
			counter3++;
			strLayers +="<span class='menuitem'><br></span></layer>";
			
			
		}
		var widthofimg = self.innerWidth - lastxpos - 150 ;
		strHTML += "<td align='right' bgcolor='#000000' valign='top' width='100%'><img width='"+widthofimg+"' height='1' src='images/attachments/wt_blank_16.gif'> </td></tr></table></layer>";
		strHTML += "<br clear='all'>"		
		document.open();
		document.writeln(strHTML);
		document.writeln(strLayers);
		document.close();
	}
	


	// This Code is IE and AOL 4.0+, Netscape 6.0 Specific (NO IE PowerMac)
	else if ( (!(whatbrowser.ismac) && (whatbrowser.ie)) ||  (whatbrowser.ns6) )  {
		var counter3 = 1; //THIS PART WRITES THE HEADINGS
		strHTML = "";
		strDivs = "";
		strHTML = strHTML +  "<table class='tablehead' id='menutable' name='menutable' border='0' width='100%' cellpadding='0' cellspacing='0' height='"+barheight+"' bgcolor='"+backgcolor+"' valign='top' align='left'><tr>";
		while ( menuArray[counter3].used != null ) {
			var linkcounter = 1;
			var idofDiv="aba" + counter3;
			var idofTD ="bba" + counter3;
			var objwidth = menuArray[counter3].maxlength*bodyconstantlarge+15;
			arnewZindex = counter3 + 25;							
			while ( menuArray[counter3].usedlink[linkcounter] == "yes" ) {
				var linkAdd= menuArray[counter3].linkURL[linkcounter];
				var targetAdd = menuArray[counter3].targetFrame[linkcounter];
				var wrlinkText = menuArray[counter3].linkText[linkcounter];
				if ( linkcounter==1 ) {
					strHTML = strHTML + "<td nowrap valign='top' align='left'><span id='" + idofTD + "'   style='position:relative;'> &nbsp;<a class='menuheader' onMouseOver='showtop(\""+idofDiv+"\")' onMouseOut='hidetop(\""+idofDiv+"\")' href='"+linkAdd+"' target='"+targetAdd+"' >"+wrlinkText+"&nbsp;&nbsp;|&nbsp;<\/a><\/span><\/td>";
				}
				else {
				}
				linkcounter++;
			}
			
			counter3++;
		}
		strHTML =  strHTML + "<td width='100%'><img height='2' width='20' src='images/wt_blank_16.gif'>&nbsp;<\/td><\/tr><\/table>"
		strHTML =  strHTML + "<br clear='all'>"
		document.writeln(strHTML);
		counter3 = 1; //THIS PART WRITES THE MENUS THEMSELVES
		while ( menuArray[counter3].used != null ) {
			var linkcounter = 1;
			var idofDiv="aba" + counter3;
			var idofTD ="bba" + counter3;
				
			var Divleft = menuArray[counter3].xpos - 1;
			if (Divleft <= 0) {
				Divleft = 0;
			}
			if ((whatbrowser.ns6) && !(whatbrowser.opera)) {
				var Divtop = yposition - 3;
			}
			else {
				var Divtop = yposition;
			}
			var objwidth = menuArray[counter3].maxlength*bodyconstantlarge+15;
			arnewZindex = counter3 + 25;
			//This layerwrite outputs the span that holds all the information about the menu currently being rendered
			if (menuArray[counter3].height != addperitem) {
			strDivs += "<span  id='" + idofDiv + "' style='position:absolute; left:"+Divleft+"; top:"+Divtop+"; height:"+(menuArray[counter3].height-20)+"; width:"+objwidth+"; z-index:"+arnewZindex+"; visibility:hidden; color:#"+fontofcolor+"; background-color:"+backgcolor+";' onMouseOver='showbottom(\""+idofDiv+"\")' onMouseOut='hidebottom(\""+idofDiv+"\")'>";
			}
			else {
			strDivs += "<span  id='" + idofDiv + "' style='position:absolute; left:0; top:0; height:0;width:0; visibility:hidden;'></span>";
			}
										
			while ( menuArray[counter3].usedlink[linkcounter] == "yes" ) {
				var linkAdd= menuArray[counter3].linkURL[linkcounter];
				var targetAdd = menuArray[counter3].targetFrame[linkcounter];
				var wrlinkText = menuArray[counter3].linkText[linkcounter];
				var idofA = "c" + counter3 + "b" + linkcounter;
				if ( linkcounter==1 ) {
				}
				else {
					if (linkcounter==2) {
						strDivs += "<span class='linething'><img src='images/wt_thing.gif' height='"+lineheight+"' width='"+objwidth+"'></span><br>";
					}
					if (targetAdd == "NOLINK" ) {
					strDivs += "<span class='menuitem'>&nbsp;<font color='"+fontofcolor+"' size='"+bfontsize+"'><span class='menuitem'>"+wrlinkText+"</span></font></span><br>";	
					}
					else if (targetAdd == "LINE" ) {
					strDivs += "<img src='images/wt_thing2.gif' height='"+lineheight2+"' width='"+objwidth+"'><br>";	
					}
					else {
						if (whatbrowser.ie5) {
						strDivs += "<span class='menuitem'>&nbsp;<font color='"+fontofcolor+"' size='"+bfontsize+"'><a id='"+idofA+"' class='menuitem' href='"+linkAdd+"' target='"+targetAdd+"' onMouseOver='window.event.srcElement.style.color=\""+fontoncolor+"\";' onMouseOut='window.event.srcElement.style.color=\""+fontofcolor+"\";' >"+wrlinkText+"</a></font></span><br>";
						}
						else {
						strDivs += "<span class='menuitem'>&nbsp;<font color='"+fontofcolor+"' size='"+bfontsize+"'><a id='"+idofA+"' class='ie4menuitem' href='"+linkAdd+"' target='"+targetAdd+"'>"+wrlinkText+"</a></font></span><br>";
						}
					}
				}
				linkcounter++;
			}
			strDivs += "<span class='menuitem'><br></span></span>";
			counter3++;
		}
		
		document.writeln(strDivs);
		
	}


	//This code will display in version 3.0 browsers that do not support the various methods above 
	// Only the links will be outputted across the top of the Screen
	else {
		
		//strHTML will be used to store the entire string to write within version 3.0 browsers
		var strHTML ="";
		var counter3 = 1;
		strHTML += "<table bgcolor="+backgcolor+"  border='0' width='100%' cellpadding='0' cellspacing='0' class='menuitem' valign='top' align='left' width=100%> <tr>";
		
		while ( menuArray[counter3].used  ==	"yes" ) {
		
			var linkcounter = 1;
			//These statements output the table data
			while ( menuArray[counter3].usedlink[linkcounter] == "yes" ) {
				
				var linkAdd= menuArray[counter3].linkURL[linkcounter];
				var targetAdd = menuArray[counter3].targetFrame[linkcounter];
				var wrlinkText = menuArray[counter3].linkText[linkcounter];
				if ( linkcounter==1 ) {
					strHTML += "<td nowrap><a class='menuheader' href='"+linkAdd+"' target='"+targetAdd+"' ><font color='white'>"+wrlinkText+"<\/font><\/a><font color='white'>   | &nbsp;<\/font><\/td>";
				}
				else {
					//The remainder of the links are ignored in version 3.0 browsers, only the "Menuheader" is seen
				}
				linkcounter++;
			}
			counter3++;	
		}
		strHTML += " <td width=100%>&nbsp;<img width='20' src='images/attachments/wt_blank_16.gif'></td>";
		strHTML += " <\/tr><\/table>";
		strHTML += "<br clear='all'><br>";
		document.open();
		document.write(strHTML);
		document.close();
	}
	return true;
}
			
			 
//Function browserCheck() checks the browser

function BrowserCheck() {
	var b = navigator.appName;
	if (b=="Netscape") this.b = "ns";
	else if (b=="Microsoft Internet Explorer") this.b = "ie";
	else this.b = b;
	this.v = parseInt(navigator.appVersion);
	this.ns = (this.b=="ns" && this.v>=4);
	this.ns6 = (this.b=="ns" && this.v>=5);
	this.ie = (this.b=="ie" && this.v>=4);
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0);
	this.opera = (navigator.userAgent.indexOf('Opera')>0);
	//if (this.opera) {
	//	this.ns6 = (this.b=="ns" && this.v>=4);
	//}
	this.ismac = (navigator.platform.indexOf('mac')>0);
	if (this.ie5) this.v = 5;
	this.min = (this.ns||this.ie);
	return true;
}





function showtop(id) {
        wasAltered = "";

	if (count != 0) {
		for (x=count-1; x >= 0; x--) {
			if (isOpen[x] != id) {
				hidebottom(isOpen[x]);
			}
		}
		count = 0;
	}
	
	if (whatbrowser.ns && !(whatbrowser.ns6)) {
		var mylayer2 = eval ("document."+id);
		mylayer2.visibility = "show";
	}
	else if (whatbrowser.ie) {
		if (window.event.srcElement.offsetLeft) {
			var tempinshow = window.event.srcElement.offsetLeft + window.event.srcElement.offsetParent.offsetLeft - 5;
			if (tempinshow < 0 ) {
				tempinshow = 0;
			}
			document.all[id].style.left = tempinshow;
		}
		document.all[id].style.visibility = "visible";
	}
	else if (whatbrowser.ns6) {
		document.getElementById(id).style.visibility="visible";

	} 
	bottomup = "";
	isOpen[count] = id;
	count++;
	return true;
}

function showbottom(id) {
	
	if (count != 0 && (!(whatbrowser.opera))) {
		for (x=count-1; x >= 0; x--) {
			if (isOpen[x] != id) {
				hidebottom(isOpen[x]);
			}
		}
		count = 0;
	}

	bottomup = id;
	
	isOpen[count] = id;
	count++;
	if (whatbrowser.ns  && !(whatbrowser.ns6)) {
		var mylayer2 = eval ("document."+id);
		mylayer2.visibility = "show";
	}
	else if (whatbrowser.ns6) {
		if ((!(whatbrowser.opera)) || (document.getElementById(id).style.visibility == "visible")) {
			document.getElementById(id).style.visibility="visible";
		}
	} 
	else	{
		document.all[id].style.visibility = "visible";
	}

	return true;
}

function hidetop(id) {
        wasAltered = id;
	functionpass = "hidetop1('"+id+"')";
	setTimeout(functionpass,400);
	return true;
}

function hidetop1(id) {
        if (wasAltered != id ) {
		return true;
	}
	var x1 = 0;
	if (count != 0 ) {
		for (x=count-1; x >= 0; x--) {
			if (bottomup != isOpen[x]) {
				if (x != (count -1) || id == isOpen[x]) {
					hidebottom(isOpen[x]);
				}
			}
		}
		
	}
	return true;
}

function hidebottom(id) {
	
	count--;
	if (whatbrowser.ns  && !(whatbrowser.ns6)) {
		var mylayer2 = eval ("document."+id);
		mylayer2.visibility = "hide";
	}
	else if (whatbrowser.ns6) {
		document.getElementById(id).style.visibility="hidden";

	} 
	else if (whatbrowser.ie) document.all[id].style.visibility = "hidden";
	if (bottomup == id) {
		bottomup = "";
	}
	return true;
}

function writeLinks(menuTitle, menuClass) {
	var counter3 = 1;
	var amenuNumber = -1;
	if (menuClass == null) {
		menuClass = "sabstyle";
	}

	
	while ( menuArray[counter3].used != null ) {
		if (menuArray[counter3].linkText[1] == menuTitle) {
			amenuNumber = counter3;
		} 
		counter3++;
	}
	if (amenuNumber < 1) {
		document.writeln("INVALID HEADER TITLE- menu "+amenuHeader+" with text "+alinkText+" "+alinkURL+" Does not exist");
		document.writeln(" Please Check code");
		return;
	}
		
	var linkcounter = 2;
	var strHTML = "";
	while ( menuArray[amenuNumber].usedlink[linkcounter] == "yes" ) {
		var linkAdd= menuArray[amenuNumber].linkURL[linkcounter];
		var targetAdd = menuArray[amenuNumber].targetFrame[linkcounter];
		var wrlinkText = menuArray[amenuNumber].linkText[linkcounter];
if (targetAdd == "NOLINK" ) {
			strHTML += "<span class='"+menuClass+"' >"+wrlinkText+"</span><br>";
		}
		else if (targetAdd == "LINE" ) {
			strHTML += "<br>";	
		}
		else {
			strHTML += "<span class='"+menuClass+"'><img src='images/arrow.gif'><a class='"+menuClass+"' href='"+linkAdd+"' target='"+targetAdd+"' >"+wrlinkText+"</a></span><br>";
		}			
		linkcounter++;
	}
	document.open();
	document.writeln(strHTML);
	document.close();
}




initMenus(60);

