////////////////////Please leave this notice////////////////////
//
//	DropDown Menu 1.0
//	By Evgeny Novikov (anfy@msn.com)
//	http://java.skyteam.ru
//	It works only with IE5.0(++) and Netscape6.0(++)
//	Free to use!
//
////////////////////Last modified 2002-03-05////////////////////
// add a hack on centering from job@Lordofhosts.com 9/29/06 //
////////////////////////////////////////////////////////////////

//	Modify following four lines to customize your menu
var tdColor="#FFFFFF";		// menu item text color
var tdBgColor="#993366";	// menu item background color
var hlColor="#000000";		// highlight text color
var hlBgColor="#FFFFBB";	// highlight background color
//	After change, modify same values in your *.css file

var mainmenuWidth = 0; // centering
var mainmenupad = 14; // centering, Important: number of left+right padding pixels listed in css
var centermenu = 1; // centering, 1=center menu on screen, otherwise align per css
var menuposx = 0; // centering

var md=500; // msec timeout for mouseout of menu
var ti=-1;
var oTd=new Object;
oTd=null;

window.onresize=menuPosn; // centering

function menuPosn(){ // centering
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth-16; // subtract scrollbar width
			// winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth-20;
			// winH = document.body.offsetHeight;
		}
	}

	menuposx=(winW-mainmenuWidth)/2;

	if (centermenu == 1) {
		document.getElementById("mainmenu").style.left=menuposx+"px";
	}

	// loop over all top level menu items, td_1, td_2... td_n where j runs from 1 to n
	var p=0; // used to list top level menu, "mainmenu"
	var j=0; // used to loop over td's in table
	while(eval("typeof(td_"+ ++j +")!=\"undefined\"")){
		if (eval("typeof(td_"+j+"_1)!=\"undefined\""))
			pT[p++]="_"+j;
	}

	// loop over all top level menus that have submenus
	// each submenu table has a class of "menu" and a class id of "tbl_j"
	for(var q=0;typeof(pT[q])!="undefined";q++){
		sT=pT[q];
		sH="";
		j=0;
		while (eval("typeof(td"+sT+"_"+ ++j +")!=\"undefined\"")){
			if (eval("typeof(td"+sT+"_"+j+"_1)!=\"undefined\""))
				pT[p++]=sT+"_"+j;
		}
		if (centermenu == 1) {
			document.getElementById("tbl"+sT).style.left=getCoordx(sT)+"px";
		}
	}
}

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){
	parent.location.href=strURL; // escape embedded frames
}

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

function getCoord(st){
	tA=st.split("_");
	if(tA.length>2){
		tA=tA.slice(0,-1);
		tt=tA.join("_");
		return (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\">";
	}
	return (document.getElementById("mainmenu").offsetTop+document.getElementById("td"+st).offsetHeight-2)+"px;left:"+
		  (document.getElementById("mainmenu").offsetLeft+document.getElementById("td"+st).offsetLeft+5)+"px\">";
}

var jlast = 0; // centering, find the last column in mainmenu

function getCoordx(st){ // centering
	tA=st.split("_");
	if(tA.length>2){
		tA=tA.slice(0,-1);
		tt=tA.join("_");
		return (document.getElementById("tbl"+tt).offsetLeft+document.getElementById("td"+st).offsetWidth-2);
	}
	return (document.getElementById("mainmenu").offsetLeft+document.getElementById("td"+st).offsetLeft+5);
}

var sH="<table class=\"menu\" id=\"mainmenu\" cellspacing=\"0\"><tr>";
var p=0; // used to list top level menus that have submenus
var j=0; // used to loop over td's
// loop over all top level menu items, td_1, td_2... td_n where j runs from 1 to n
while(eval("typeof(td_"+ ++j +")!=\"undefined\"")){
	jlast = j; // centering

	sH+="<td id=\"td_"+j+"\" onmouseover=\"doMenu(this)\" onmouseout=\"ti=setTimeout('clearMenu()',md)\"";
	sH+=(eval("typeof(url_"+j+")!=\"undefined\""))?" onclick=\"runMenu('"+eval("url_"+j)+"')\">":">";
	sH+=eval("td_"+j)+"</td>";  // sets sH+=td_j</td>, giving menu title like "Contact Us"</td>
	if (eval("typeof(td_"+j+"_1)!=\"undefined\""))
		pT[p++]="_"+j;
}

//if top menu cell j is the third cell having a submenu, then pT[3] = "_j"

sH+="</tr></table>";
document.write(sH);


mainmenuWidth = document.getElementById("td_"+jlast).offsetLeft+mainmenupad;  // centering

if (parseInt(navigator.appVersion)>3) { // centering
	if (navigator.appName=="Netscape") {
		winW = window.innerWidth-16; // subtract scrollbar width
		winH = window.innerHeight;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		winW = document.body.offsetWidth-20;
		winH = document.body.offsetHeight;
	}
}

menuposx=(winW-mainmenuWidth)/2; // centering

if (centermenu == 1) {
	document.getElementById("mainmenu").style.left=menuposx+"px";
}

//loop over all top level menus that have submenus
// each submenu table has a class of "menu" and a class id of "tbl_j"
for(var q=0;typeof(pT[q])!="undefined";q++){

	sT=pT[q];
	sH="";
	j=0;
	sH+="<table class=\"menu\" id=\"tbl"+sT+"\" cellspacing=\"0\" style=\"top:"+getCoord(sT);
	while (eval("typeof(td"+sT+"_"+ ++j +")!=\"undefined\"")){
		sH+="<tr><td id=\"td"+sT+"_"+j+"\" onmouseover=\"doMenu(this)\" onmouseout=\"ti=setTimeout('clearMenu()',md)\"";
		sH+=(eval("typeof(url"+sT+"_"+j+")!=\"undefined\""))?" onclick=\"runMenu('"+eval("url"+sT+"_"+j)+"')\">":">";
		sH+=eval("td"+sT+"_"+j)+"</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";
