/* -------------------- 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) + "px;left:"
		 + (document.getElementById("mainmenu").offsetLeft
		 + document.getElementById("td" + st).offsetWidth+1) + "px";
	} else {
		return "top:" + (document.getElementById("mainmenu").offsetTop
		 + document.getElementById("td" + st).offsetHeight+2) + "px;left:"
		 + (document.getElementById("mainmenu").offsetLeft
		 + document.getElementById("td" + st).offsetLeft) + "px";
	}
}

/* buildMenu(dir, typ, arw, sel)
 * buildMenu constructs the tables, the main menu and all sub-menus
 * dir: 'h' = horizontal (default), 'v' = vertical
 * typ: 't' = text (default), 'i' = images, 'm' = mouseover pairs
 *      'tb' = text & bullets, 'ib' = images & bullets, 'mb' = mouseover & bullets
 * arw: HTML string to use for an arrow, indicating another menu of links
 *      Can be contextual, '}' suggested default, or the HTML for an image
 * sel: '#' = 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)
 */
function buildMenu(dir, typ, arw, sel) {
	if (arw == "") arw = "}";
	if (document.getElementById) {
		var sH = "<table class=\"menu\" id=\"mainmenu\" border=\"1\"";
		sH += " cellspacing=\"0\" cellpadding=\"0\" summary=\"Main Menu\"><tbody>";
		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) sH += " class=\"sel\"";
			sH += " onmouseover=\"doMenu(this);\"";
			sH += " onmouseout=\"ti=setTimeout('clearMenu()',md);\">";
			sH += "<a";
			sH += (eval("typeof(url_" + j + ")!=\"undefined\""))?
			 " href=\"" + eval("url_" + j) + "\"" 
			 : " href=\"javascript:void(null);\" style=\"cursor: default;\"";
			if ( (typ == "i" || typ == "m" || typ == "ib" || typ == "mb")
			 && eval("typeof(pic_" + j + ")!=\"undefined\"")
			 && eval("typeof(wth_" + j + ")!=\"undefined\"")
			 && eval("typeof(hgt_" + j + ")!=\"undefined\"") ) {
				if (typ == "m" || typ == "mb") {
					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');\"";
					var picsrc = eval("pic_" + j);
					if (sel == j) eval(picsrc + "0.src='" + imgs + picsrc + "-2.gif';");
				}
				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 {
				if (typ == "tb") {
					sH += " class=\"";
					sH += (eval("typeof(bul_" + j + ")!=\"undefined\""))? eval("bul_" + j)
					 : (eval("typeof(td" + sT + "_" + j + "_1)!=\"undefined\""))? "folder" : "web";
					sH += (sel == j)? " sel\">" : "\">";
				} else sH += (sel == j)? " class=\"sel\">" : ">";
				sH += eval("td_" + j);
			}	
			sH += "</a></td>";
			if (dir == "v") sH += "</tr>";
			if (eval("typeof(td_" + j + "_1)!=\"undefined\""))
				pT[p++] = "_" + j;
		}
		sH += "</tr></tbody></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 + "\"";
			sH += " style=\"" + getCoord(sT, dir) + "\"";
			if (cellWidth > 0 && cellWidth != "auto") sH += " width=\"" + cellWidth + "\"";
			sH += " border=\"1\" cellspacing=\"0\" cellpadding=\"0\"";
			sH += " summary=\"Links for: " + eval("td" + sT) + "\"><tbody>";
			while (eval("typeof(td" + sT + "_" + ++j + ")!=\"undefined\"")){
				sH += "<tr><td id=\"td" + sT + "_" + j + "\"";
				sH += " onmouseover=\"doMenu(this)\"";
				sH += " onmouseout=\"ti=setTimeout('clearMenu()',md)\">";
				sH += (eval("typeof(url" + sT + "_" + j + ")!=\"undefined\""))?
				 "<a href=\"" + eval("url" + sT + "_" + j) + "\"" : "<a";
				if (eval("typeof(bul" + sT + "_" + j + ")!=\"undefined\"")
				 && (typ == "tb" || typ == "ib" || typ == "mb")) {
				 	sH += " class=\"" + eval("bul" + sT + "_" + j) + "\">";
					if (eval("bul" + sT + "_" + j) == "folder" && arw != "0") {
						sH += "<b class=\"a\">" + arw + "</b>";
					}
				} else if (typ == "tb" || typ == "ib" || typ == "mb") {
					if (eval("typeof(td" + sT + "_" + j + "_1)!=\"undefined\"")) {
					 	sH += " class=\"folder\">";
						if (arw != "0") sH += "<b class=\"a\">" + arw + "</b>";
					} else {
					 	sH += " class=\"web\">";
					}
				} else {
					sH += ">";
					if (eval("typeof(td" + sT + "_" + j + "_1)!=\"undefined\"") && arw != "0") {
						sH += "<b class=\"a\">" + arw + "</b>";
					}
				}
				sH += eval("td" + sT + "_" + j);
				sH += "</a></td></tr>";
				if (eval("typeof(td" + sT + "_" + j + "_1)!=\"undefined\""))
					pT[p++] = sT + "_" + j;
			}
			sH += "</tbody></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");
}

