/*----------------------------------------------------
// dropmenu.js 
// drop menu configurable width variables in the body
// of the calling html
//--------------------------------------------------*/

var br;
var tdID = 0;
var menus = new Array()
var DesignWidth = 780;
if(document.all) { br="IE"; }
if(!document.all && document.getElementById) { br="MOZ";}

//*---------------------------------------------------
// shows the drop down menu
// expected arg is active div
//--------------------------------------------------*/
function showDDNav(menu)
{
	if(br == "MOZ")
	{
   		document.getElementById(menu).style.visibility = "visible";
	}
 	if(br == "IE")
 	{
 		//theObj= eval(menu);
		//theObj.style.visibility = 'visible';
		document.getElementById(menu).style.visibility = 'visible';
	}
}

//*---------------------------------------------------
// hides the drop down menu
// expected arg is active div
//--------------------------------------------------*/
function hideDDNav(menu)
{
	if(br == "MOZ")
	{
  		document.getElementById(menu).style.visibility = "hidden";
 	}
 	if(br == "IE")
 	{
  		document.getElementById(menu).style.visibility = 'hidden';
 	}
}

//*---------------------------------------------------
// hides drop down menu when menu is active
// expected arg is active menu
//--------------------------------------------------*/
//function hideDiv(divID){
//	if(br == "MOZ"){
//		document.getElementById(divID).style.visibility = "hidden";
//	}
//	if(br == "IE"){
//		//divID = "document.all['" + divID + "']";
//		theObj=eval(divID);
//		theObj.style.visibility = 'hidden';
//	}
//}

//*---------------------------------------------------
// highlight menuitem
// expected arg is active menuitem
//--------------------------------------------------*/
function divOver(did)
{
	if(br == "MOZ")
	{
		document.getElementById(did).style.backgroundColor="#"+mouseoverbg;
		document.getElementById(did).style.color="#"+mouseovercolor;
		document.getElementById(did).style.cursor = mouseovercursor;
	}
	if(br == "IE")
	{
		did = "document.all['" + did + "']";
		theObj=eval(did);
		theObj.style.backgroundColor = "#" + mouseoverbg;
		theObj.style.color="#"+mouseovercolor;
		theObj.style.cursor = mouseovercursor;
	}
}

//*---------------------------------------------------
// highlight off menuitem
// expected arg is active menuitem
//--------------------------------------------------*/
function divOut(tdID)
{
	if(br == "MOZ")
	{
		document.getElementById(tdID).style.backgroundColor="#"+background;
		//document.getElementById(tdID).style.color="#"+color;
	}
	if(br == "IE")
	{
		tdID = "document.all['" + tdID + "']";
		theObj=eval(tdID);
		theObj.style.backgroundColor="#"+background;
		//theObj.style.color="#"+color;
	}
}

//*---------------------------------------------------
// highlight on menuitem in netscape
// expected arg is active menuitem
//--------------------------------------------------*/
function menuOver()
{
	var args, theMenu;
	args = menuOver.arguments;
	theMenu = eval(args[0]);
	theMenu.bgColor="#"+mouseoverbg;
	theMenu.Color="#"+mouseovercolor;
}

//*---------------------------------------------------
// highlight off menuitem in netscape
// expected arg is active menuitem
//--------------------------------------------------*/
function menuOut()
{
	var args, theMenu;
	args = menuOut.arguments;
	theMenu = eval(args[0]);
	theMenu.bgColor="#"+background;
}


//*---------------------------------------------------
// goes to specified url
// expected arg is url
//--------------------------------------------------*/
function gotoUrl(url)
{
    var test = /^httpq/;
    if (url.match(test))
	{
		//window.open(url);
		top.location.href = url;
	} else {
	   top.location.href = url;
	}
}

//---------------------------------------------------
// build the divs for IE and MOZ
// expected args are 'div name','x in menudata aray',
// 'menu left coord','arrow alignment','top in pixels'
//--------------------------------------------------
function doDiv()
{
	args = doDiv.arguments;
	var divID = args[0];
	var x = args[1];
	var divLeft = args[2];
	var divTop = args[3];
	var width = args[4];
	
	objDiv = "<div id=\"" + divID + "\" style=\"position:absolute; filter:alpha(opacity=" + opacity + "); -moz-opacity:0." + opacity + "; left:" + divLeft +"px; top:"+ divTop +"px; width:"+width+"px; z-index:0; background-color: #"+background+"; visibility:hidden; border-style: "+border_style+"; border-width: "+border_width+"; border-color: #"+border_color+"; padding: 2px;\" onMouseover=\"showDDNav('" + divID + "')\"  onMouseout=\"hideDDNav('" + divID + "')\">"
	menus[x] = divID;
	if (image)
	{ 
		objDiv += "<div id=\"arrow\" style=\"position:relative; filter:alpha(opacity=" + opacity + "); -moz-opacity:0." + opacity + "; background-color:#"+background+"; width:"+width+"px;\"><img src="+imgsrc+" width=\""+imgwidth+"\" height=\""+imgheight+"\" border=\"" + imgborder + "\" align=\"" + imgposition + "\"><br clear=\"left\"></div>"
	}
	
	for (y = 0; y < 15; y++)
	{
		if(menuData[x][y][0]!=null)
		{
			if ((line && (y > 0)) || image)
			{
				objDiv += "<div id=\"line\" style=\"position:relative; filter:alpha(opacity=" + opacity + "); -moz-opacity:0." + opacity + "; background-color:#"+background+"; width:"+width+"px; padding: 1px;\"><img src=\""+linesrc+"\" width=\""+width+"\" height=\""+lineheight+"\" border=\""+lineborder+"\"></div>";
			}
			objDiv += "<div id=\"x" + tdID + "\" onClick=\"gotoUrl('" + menuData[x][y][1] + "')\"; style=\"position:relative; text-align:right; filter:alpha(opacity="+opacity+"); -moz-opacity:0."+opacity+"; background-color:#"+background+";\" width:"+width+"px; height:"+height+"px; onMouseover=\"divOver('x" + tdID + "')\" onMouseout=\"divOut('x" + tdID + "')\"><span class=\"dropmenu\" target=\"_top\">"+ menuData[x][y][0] +"</span></div>"
			tdID ++;
		}
	}
	objDiv +="</div>";
	//alert(objDiv);
	document.write(objDiv);
}


// ---------------------------------------------------
// Align the menu if needed by a centered page
// ---------------------------------------------------
function MoveDropDowns()
{
	width = document.body.clientWidth;
	if (width > DesignWidth)
	{
		for (y = 1; y < 15; y++)
		{
			if(menus[y])
			{
				var oldWidth = document.getElementById(menus[y]).style.left;
				// the three lines of bs below are just to convert to an Integer for IE on a Mac and Safari
				var test = /(\d+)/;
			    var results = oldWidth.match(test);
			    var ow = results[0] * 1;
			    
				var newWidth = ow + (width - DesignWidth) / 2;
				//alert (menus[y] + ': (' + ow + '): ' + newWidth);
				
				document.getElementById(menus[y]).style.left = newWidth + 'px';
			}
		}
	}
}
