/* -------------------- Please leave this notice --------------------
 *	DropDown Menu 1.2 (Free to use!)
 *	By Evgeny Novikov [java@aladin.ru] [http://java.skyteam.ru/]
 *	It works with IE5.0(++), Opera6.0(++), and Netscape6.0(++)
 *  V1.2: modified 2005-04-01 [http://www.melvinwallerjr.com/]
 *    changed table cell links to anchor links for accessibility
 *    added vertical/horizontal switching
 *    added ability to use images for main menu
 *    added multiple image handling (mouseout, selected, and mouseover)
 * ===================================================================
 * NOTE: The web document must call "menu_data.js" before it calls
 *       this script. The data file is required by this script.
 *       ------------------------------------------------------------
 *       There is no need to Edit this file, all values and settings
 *       should be defined in the 'menu_data.js' file.
 * ===================================================================
 */

window.onerror = null; // Generic Error Trapping
var md = 500;
var ti = -1;
var oTd = new Object;
oTd = null;

function doMenu(td) {
	clearTimeout(ti);
	td.style.backgroundColor = hlBgColor;
	td.style.color = hlColor;
	var i;
	var sT = "";
	var tda = new Array();
	tda = td.id.split("_");
	if (oTd != null) {
		var tdo = new Array();
		tdo = oTd.id.split("_");
		for (i=1; i < tdo.length; i++) {
			sT += "_" + tdo[i];
			if (tdo[i] != tda[i]) {
				document.getElementById("td" + sT).style.backgroundColor = tdBgColor;
				document.getElementById("td" + sT).style.color = tdColor;
				if (document.getElementById("tbl" + sT) != null) {
					document.getElementById("tbl" + sT).style.visibility = "hidden";
				}
			}
		}			
	}
	oTd = td;
	sT = "tbl";
	for (i=1; i < tda.length; i++) sT += "_" + tda[i];
	if (document.getElementById(sT) != null) {
		document.getElementById(sT).style.visibility = "visible";
	}

}

function clearMenu() {
	if (oTd != null) {
		var tdo = new Array();
		tdo = oTd.id.split("_");
		var sT = "";
		for (var i=1; i < tdo.length; i++) {
			sT += "_" + tdo[i];
			document.getElementById("td" + sT).style.backgroundColor = tdBgColor;
			document.getElementById("td" + sT).style.color = tdColor;
			if(document.getElementById("tbl" + sT) != null)
				document.getElementById("tbl" + sT).style.visibility = "hidden";
		}
		oTd = null;
	}
}

function runMenu(strURL) {
	location.href = strURL;
}

var tt = "";
var sT = "";
var pT = new Array();
var tA = new Array();

function getCoord(st,dir) {
	tA = st.split("_");
	if (tA.length > 2) {
		tA = tA.slice(0, -1);
		tt = tA.join("_");
		return "top:" + (document.getElementById("tbl" + tt).offsetTop
		 + document.getElementById("td" + st).offsetTop+4) + "px;left:"
		 + (document.getElementById("tbl" + tt).offsetLeft
		 + document.getElementById("td" + st).offsetWidth-2) + "px";
	}
	if (dir == "v") {
		return "top:" + (document.getElementById("mainmenu").offsetTop
		 + document.getElementById("td" + st).offsetTop+4) + "px;left:"
		 + (document.getElementById("mainmenu").offsetLeft
		 + document.getElementById("td" + st).offsetWidth-2) + "px";
	} else {
		return "top:" + (document.getElementById("mainmenu").offsetTop
		 + document.getElementById("td" + st).offsetHeight+1) + "px;left:"
		 + (document.getElementById("mainmenu").offsetLeft
		 + document.getElementById("td" + st).offsetLeft) + "px";
	}
}

/* buildMenu(dir, typ, sel)
 * buildMenu constructs the tables, the main menu and all sub-menus
 * dir value: 'h' = horizontal (default), 'v' = vertical
 * typ value: 't' = text (default), 'i' = images, 'm' = mouseover pairs
 * sel value: '#' = the 'td_' number as defined in the 'menu-data.js' file
 * Images are used only for the first level table, the one displayed in the page.
 *  for td_6 (6th image/link) to use the 'selected' image, then 'sel' would be 6.
 *  This will also require a third image 'IMAGENAME-2.gif' ('selected' version)
 */
var selLink;
function buildMenu(dir, typ, sel) {
	selLink = sel;
	if (document.getElementById) {
		var sH = "\<table class=\"menu\" id=\"mainmenu\" border=\"1\"";
		sH += " cellspacing=\"0\" cellpadding=\"0\" summary=\"Main Menu\">\<tr>";
		var p = 0;
		var j = 0;
		while (eval("typeof(td_" + ++j + ")!=\"undefined\"")) {
			if (dir == "v") sH += "\<tr>";
			sH += "\<td id=\"td_" + j + "\"";
			if (sel == j && typ == "t") sH += " class=\"sel\"";
			sH += " onmouseover=\"doMenu(this);\"";
			sH += " onmouseout=\"ti=setTimeout('clearMenu()',md);\"";
			sH += ">\<a";
			if (sel == j && typ == "t") sH += " class=\"sel\"";
			sH += (eval("typeof(url_" + j + ")!=\"undefined\""))?
			 " href=\"" + eval("url_" + j) + "\"" : "";
			if ( (typ == "i" || typ == "m")
			 && eval("typeof(pic_" + j + ")!=\"undefined\"")
			 && eval("typeof(wth_" + j + ")!=\"undefined\"")
			 && eval("typeof(hgt_" + j + ")!=\"undefined\"") ) {
				if (sel != j && typ == "m") {
					sH += " onmouseover=\"Chng('" + eval("pic_" + j) + "','1');\"";
					sH += " onfocus=\"Chng('" + eval("pic_" + j) + "','1');\"";
					sH += " onmouseout=\"Chng('" + eval("pic_" + j) + "','0');\"";
					sH += " onblur=\"Chng('" + eval("pic_" + j) + "','0');\"";
				}
				sH += "><img name=\"" + eval("pic_" + j);
				sH += "\" src=\"" + imgs + eval("pic_" + j);
				if (sel != j) { sH += "-0.gif" } else { sH += "-2.gif" }
				sH += "\" width=\"" + eval("wth_" + j);
				sH += "\" height=\"" + eval("hgt_" + j);
				sH += "\" alt=\"" + eval("td_" + j) + "\" />";
			} else {
				sH += ">" + eval("td_" + j);
			}	
			sH += "\</a>\</td>";
			if (dir == "v") sH += "\</tr>";
			if (eval("typeof(td_" + j + "_1)!=\"undefined\""))
				pT[p++] = "_" + j;
		}
		sH += "</tr></table>";
		document.write(sH);
		for (var q=0; typeof(pT[q]) != "undefined"; q++){
			sT = pT[q];
			sH = "";
			j = 0;
			sH += "\<table class=\"menu\" id=\"tbl" + sT + "\" style=\"";
			sH += getCoord(sT, dir) + "\" width=\"" + cellWidth;
			sH += "\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"";
			sH += " summary=\"Links for: " + eval("td" + sT) + "\">";
			while (eval("typeof(td" + sT + "_" + ++j + ")!=\"undefined\"")){
				sH += "\<tr>\<td id=\"td" + sT + "_" + j + "\"";
				sH += " onmouseover=\"doMenu(this)\"";
				sH += " onmouseout=\"ti=setTimeout('clearMenu()',md)\">\<a";
				sH += (eval("typeof(url" + sT + "_" + j + ")!=\"undefined\""))?
				 " href=\"" + eval("url" + sT + "_" + j) + "\">" : ">";
				sH += eval("td" + sT + "_" + j);
				sH += "\</a>\</td>\</tr>";
				if (eval("typeof(td" + sT + "_" + j + "_1)!=\"undefined\""))
					pT[p++] = sT + "_" + j;
			}
			sH += "</table>";
			document.write(sH);
		}
		document.getElementById("mainmenu").style.visibility = "visible";
	} else document.write("<p>This page uses DHTML and DOM,"
	 + "but your browser doesn't support them.</p>");
}

// MouseOver Image Handling Functions
if (document.images) { // Image preloader, checks for MouseOver image handling
	var n = 0;
	while (n < pics.length) {
		eval(pics[n] + "0=new Image(" + pics[(n+1)] + "," + pics[(n+2)] + ");");
		eval(pics[n] + "0.src='" + imgs + pics[n] + "-0.gif'");
		eval(pics[n] + "1=new Image(" + pics[(n+1)] + "," + pics[(n+2)] + ");");
		eval(pics[n] + "1.src='" + imgs + pics[n] + "-1.gif'");
		n += 3;
	}
}
function Chng(Pct,Type) {
	// Pct: Is the name of the image (followed by a type number)
	// This is also the HTML 'name' of the image.
	// Type: 0 = mouseOut, 1 = mouseOver
	if (document.images) document[Pct].src = eval(Pct + Type + ".src");
}

