////////////////////Please leave this notice//////////////////////
//								//
//	Dynamic JS Menu 1.0					//
//	By Pat Libby (Libbypa@maine.rr.com)			//
//	http://dragonsbane1.topcities.com			//
//	It works only with IE5.0(++) and Netscape6.0(++)	//
//	Free to use!						//
//								//
////////////////////Last modified 01-31-2003//////////////////////
//
// 01/20/2009 Customized to work with Civica

//	Modify following four lines to customize your menu
var tdColor="#FFFFFF";		// menu item text color
var tdBgColor="#223984";	// menu item background color
var hlColor="#FFCC00";		// highlight text color
var hlBgColor="#6699CC";//"#6c85b0";	// highlight background color
//	After change, modify same values in your theme/style.css and theme/style800x600.css file

////////////////////DO NOT MODIFY BELOW HERE//////////////////////
var md=2000;
var ti=-1;
var oTd=new Object;
oTd=null;

function changeBackground(obj, evt,cellNo)
{
    if (evt == 1) //mouseover
	{
	    if (cellNo == 0)//menu name cell
		{
			with (obj.nextSibling)
			{
		    	style.backgroundColor  = hlBgColor;
				style.color  = hlColor;
			}
		}	
		else //arrow cell
		{
			with (obj.previousSibling)
			{
				style.backgroundColor  = hlBgColor;
				style.color  = hlColor;
			}
		}
		with (obj)
		{
			style.backgroundColor  = hlBgColor;
			style.color = hlColor;
			style.cursor = 'hand';
		}
	}	
	else//mouseout	
	{
		if (cellNo == 0)
		{
		    with (obj.nextSibling)
			{
		    	style.backgroundColor  = tdBgColor;
				style.color  = tdColor;
			}
		}	
		else 
		{
			with(obj.previousSibling)
			{
				style.backgroundColor  = tdBgColor;
				style.color  = tdColor;
			}
		}
		with (obj)
		{
			style.backgroundColor  = tdBgColor;
			style.color = tdColor;
			style.cursor = '';
		}
	}	
}
function getAbsoluteLeft(obj)
{
	oLeft = obj.offsetLeft ;
	while(obj.offsetParent!=null) {
		oParent = obj.offsetParent;
		oLeft += oParent.offsetLeft ;
		obj = oParent;
	}
	return oLeft;
}

function getAbsoluteTop(obj)
{
	oTop = obj.offsetTop;
	while(obj.offsetParent!=null) {
		oParent = obj.offsetParent ;
		oTop += oParent.offsetTop ;
		obj = oParent;
	}
	return oTop;
}

function doMenu(td){
	clearTimeout(ti);
	td.style.backgroundColor=hlBgColor;
	td.style.color=hlColor;
	td.style.cursor = 'hand';
	var menuTop;
	var menuLeft;
	var menuHeight = 0;
	var menuWidth = 0;
	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;
				document.getElementById("td"+sT).style.cursor='hand';
				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];
	var selectBoxes = document.getElementsByTagName("select");
	if(document.getElementById(sT)!=null)
	{
		objID = document.getElementById(sT).id;
		level = objID.split("_");
		if (level.length > 2)
		{
			menuTop = getAbsoluteTop(td);  
			menuLeft = getAbsoluteLeft(td) + td.offsetWidth - 5;
		}
		else
		{
			menuTop = getAbsoluteTop(td) + td.offsetHeight; 
			// 01/20/2009 Customized to work with Civica
			// Civica centered the body and set limit to 840 px
			if (document.body.offsetWidth > 860) // 20 px more than Civica's 840 px width
			{
				menuLeft = getAbsoluteLeft(td) - ((document.body.offsetWidth - 860) /2); 
			}
			else
			{
				menuLeft = getAbsoluteLeft(td) - 2; 
			}
		}
		document.getElementById(sT).style.top = menuTop;
		document.getElementById(sT).style.left  = menuLeft;
		document.getElementById(sT).style.visibility="visible";
		menuHeight = parseInt(document.getElementById(sT).offsetHeight);
		//alert(document.getElementById(sT).offsetHeight);
		
		menuWidth =  parseInt(document.getElementById(sT).offsetWidth);
		//hide all select boxes 	
		for (x=0; x < selectBoxes.length; x++)
		{
			selectBoxes[x].style.visibility = 'visible';
			sTop = parseInt(getAbsoluteTop(selectBoxes[x]));
			sLeft = parseInt(getAbsoluteLeft(selectBoxes[x]));
			sRight = parseInt(selectBoxes[x].offsetWidth) + sLeft;
			sHeight = sTop + parseInt(selectBoxes[x].offsetHeight);
			mRight = menuWidth + parseInt(menuLeft);
			mHeight = menuHeight + parseInt(menuTop);
			pMenuTop = parseInt(getAbsoluteTop(td));
			pMenuLeft = parseInt(getAbsoluteLeft(td));
			pMenuRight = pMenuLeft + parseInt(td.offsetWidth);
			pMenuHeight = pMenuTop + parseInt(td.offsetHeight);
			if (mHeight < sTop && pMenuTop < sTop)
				selectBoxes[x].style.visibility = 'visible';
			else if (menuTop > sHeight && (pMenuRight < sLeft || pMenuLeft > sRight))	
				selectBoxes[x].style.visibility = 'visible';
			else if (mRight < sLeft && pMenuRight < sLeft)
				selectBoxes[x].style.visibility = 'visible';
			else if (menuLeft > sRight  && pMenuLeft > sRight)
				selectBoxes[x].style.visibility = 'visible';
			else	
				selectBoxes[x].style.visibility = 'hidden';
		}
	}
}

function clearMenu(){
	var elementID = event.srcElement.id ;
	if (elementID.indexOf("td_") == -1)
	{
		//visibility all select boxes
		var selectBoxes = document.getElementsByTagName("select");
		for (x=0; x < selectBoxes.length; x++)
			selectBoxes[x].style.visibility = 'visible';

		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){
	var sUrl = strURL.toLowerCase();
	if (strURL.indexOf("http://") != -1 || sUrl.indexOf(".doc") != - 1 || sUrl.indexOf(".pdf") != - 1)
		window.open(strURL);
	else if (strURL.indexOf("mailto") != -1)
	{
		index = strURL.indexOf("mailto");
		location.href = strURL.substring(index, strURL.length);
	}	
	else if (strURL.indexOf("javascript") != -1)
	{
		index = strURL.indexOf("javascript");
		location.href = strURL.substring(index, strURL.length);
	}
	else
	   location.href=strURL;
}

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 sH="<table class=\"menu\" id=\"mainmenu\" cellspacing=\"1\"  width=\"100%\" align=\"center\"><tr>";
var p=0;
var j=0;
while(eval("typeof(td_"+ ++j +")!=\"undefined\"")){
	sH+="<td width=\"142\" align=\"center\" class=\"menu\" id=\"td_"+j+"\" style=\"cursor:hand\" ";
	sH+=(eval("typeof(url_"+j+")!=\"undefined\""))?" onclick=\"runMenu('"+eval("url_"+j)+"')\">":" onmousedown=\"doMenu(this)\">";
	sH+=eval("td_"+j)+"</td>";
	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 width=\"142\" class=\"menu\" id=\"tbl"+sT+"\" cellspacing=\"1\" style=\"z-index:1\">";
	
	while (eval("typeof(td"+sT+"_"+ ++j +")!=\"undefined\"")){
		sH+="<tr><td class=\"menu\" id=\"td"+sT+"_"+j+"\" onmouseover=\"doMenu(this)\" ";
		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";



