
//<!--
	//Ben Maden t/a Matter Solutions
	//http://www.mattersolutions.com 


//<!--- If Mac Netscape, use 9px else use 8px for the menu text --->
var fntStyle = "font-family : Verdana; font-weight: 800; font-size : " + (isMac&&IE4 ? "9px" :  "9px") + "; text-decoration : none; color:" + dfltTxtColor + ";"
//<!--- <cf_array>  --->


//<!--- Once the window is done loading, start creating the menus --->
window.onload = startRunning
var arrcnt = 1
var DoneBuildingMenus=0;
function startRunning(){
	while(eval("window.arr" + arrcnt)) {
		
		tempMenu = "menu" + arrcnt
		tempArray = "arr" + arrcnt
		createMenus(tempMenu,tempArray,arrcnt);
		arrcnt++;
	}
	DoneBuildingMenus = 1;
}

function getObject(obj){
	var theObj
	if (typeof obj == "string"){
			theObj = eval(obj)
	}else{
		theObj = obj
	}
	return theObj
}

function overColor(myItem,myColor){
	myItem.style.backgroundColor = IEmouseOverColor;
	myItem.style.cursor = "hand";	
	//myItem.style.color = overTxtColor;	
	//myItem.style.fontWeight = "bold";
	window.event.srcElement.style.color = overTxtColor;
	//window.event.srcElement.style.fontWeight = "bold";
}

function outColor(myItem,bgColor){
	myItem.style.backgroundColor = bgColor;
	//myItem.style.fontWeight = "normal";
	window.event.srcElement.style.color = dfltTxtColor;
	// window.event.srcElement.style.fontWeight = "normal";
}

function createMenus(mymenu,myarray,arrindex){
	tempArray = eval(myarray);
	//<!--- No longer used. Passing in Text Mouseover color instead of background color. bgColor is global var --->
	//<!--- bgColor = (tempArray[0] ? tempArray[0]: defaultMenuColor); --->
	menuWidth = tempArray[0];
	mouseovercolor = tempArray[1];
	isSubMenu = tempArray[2];
	xpos = tempArray[3];
	ypos = specificY;
	myparent = tempArray[5];
  noOverColor = tempArray[4];
	x=6;	
	lnk = tempArray[x];
	txt = tempArray[x+1];
	subMenu=tempArray[x+2];
	//<!--- This will see if ther is a URL, if so setup href --->
	if (lnk){href = "HREF='" + lnk + "'"}else{href="";}

	//<!--- This will put a border above each entry --->
	//<!--- style = "STYLE='margin-bottom:" + borderWidth + "px;margin-right:" + borderWidth + "px;margin-left:" + borderWidth + "px; background-color:" + bgColor + "; width:" + menuWidth + "'" --->
	//<!--- style1 = "STYLE='margin-top:" + borderWidth + "px; margin-bottom:" + borderWidth + "px;margin-right:" + borderWidth + "px;margin-left:" + borderWidth + "px; background-color:" + bgColor + "; width:" + menuWidth + "'" --->
	//<!--- Dont want to have a margin on the right hand side --->
	if(noOverColor){
    var leftborderWidth = 5;
    var topborderWidth = 5;
    var rightborderWidth = 5;
    var bottomborderWidth = 5;
    style = "STYLE='margin-top:" + topborderWidth + "px;margin-bottom:" + bottomborderWidth + "px;margin-left:" + leftborderWidth + "px;margin-right:" + rightborderWidth + "px; background-color:" + bgColor + ";height : " + MenuHeight +"px; width:" + menuWidth + "px'"
    style1 = "STYLE='margin-top:" + topborderWidth + "px; margin-bottom:" + bottomborderWidth + "px;margin-left:" + rightborderWidth +"px;margin-right:" + rightborderWidth +  "px; background-color:" + bgColor + ";height :" + MenuHeight +"px;width:" + menuWidth + "px'"
  }
  else
  {
    style = "STYLE='margin-top:" + border + "px;margin-bottom:" + border + "px;margin-left:" + borderWidth + "px;margin-right:" + borderWidth + "px; background-color:" + bgColor + ";height : " + MenuHeight +"px; width:" + menuWidth + "px'"
    style1 = "STYLE='margin-top:" + borderWidth + "px; margin-bottom:" + border + "px;margin-left:" + borderWidth +"px;margin-right:" + borderWidth +  "px; background-color:" + bgColor + ";height :" + MenuHeight +"px;width:" + menuWidth + "px'"
  }

	cntr=0;
	//<!--- Clear parent will clear the timeout of the parent menu --->
	entry = "<DIV ID='" + mymenu + "' STYLE='margin-top: " + border + "px; margin-bottom: " + border + "px; position: absolute; visibility: hidden; width: " + menuWidth + "px; background-color: " + borderColor + ";' ONMOUSEOUT='hideMenu(this);hideParent(this);' ONMOUSEOVER='clearTimeout(this.tid);clearParent(this);'>"
	while (txt){
		cntr++;
 		
		if(subMenu){
			//<!--- Do the mouseover for submenu on SPAN not on URL. It works better --->
			entry = entry + "<A " + href + "Style='text-decoration : none';><FONT STYLE=\"" + fntStyle + "\"><SPAN ID='" + mymenu +"item" + cntr + "' " + (cntr==1?style1:style) + " ONMOUSEOVER=\"hideAllSubMenu('"+mymenu+"');showMenu('" + subMenu + "',this);overColor(this,'" + mouseovercolor + "');\" ONMOUSEOUT=\"hideMenu('" + subMenu + "');outColor(this,'" + bgColor + "');\">" + txt + "</SPAN></FONT></A>" 
		}else if(noOverColor){
      ypos = noOverColor;
			entry = entry + "<A " + href + "Style='text-decoration : none';><FONT STYLE=\"" + fntStyle + "\"><SPAN ID='" + mymenu +"item" + cntr + "' " + (cntr==1?style1:style) + " ID='item" + cntr + "'" + (cntr==1?style1:style) + ">" + txt + "</SPAN></FONT></A>"			
	//	}
		}else{
			entry = entry + "<A " + href + "Style='text-decoration : none';><FONT STYLE=\"" + fntStyle + "\"><SPAN ID='" + mymenu +"item" + cntr + "' " + (cntr==1?style1:style) + " ONMOUSEOVER='overColor(this,\"" + mouseovercolor + "\");' ONMOUSEOUT='outColor(this,\"" + bgColor + "\");' ID='item" + cntr + "'" + (cntr==1?style1:style) + ">" + txt + "</SPAN></FONT></A>"			
		}
		

		x+=3
		lnk = tempArray[x];
		txt = tempArray[x+1];
		subMenu=tempArray[x+2];
		//<!--- This will see if there is a URL, if so setup href --->
		if (lnk){href = "HREF='" + lnk + "'"}else{href=null;}
	}
	
  if(noOverColor){
  	entry = entry + "<SPAN vspace=0 style='margin-bottom=0;margin-top=0;margin-left=5px;margin-right=5px'><img src='/images/transp.gif' width='5' height = '1'></SPAN>"			
  }
  else
  {
	  entry = entry + "<SPAN vspace=0 style='margin-bottom=0;margin-top=0'><img src='/images/transp.gif' width='0' height = '1'></SPAN>"			
  }
		
	entry = entry + "</DIV>";
	window.document.body.insertAdjacentHTML("BeforeEnd",entry);
	
	moveto(mymenu,xpos,ypos);
	//<!--- Associate the parent menu with the submenu if there is one --->
	myparent ? document.all[mymenu].parent = eval(myparent) : null;
	document.all[mymenu].mouseovercolor = mouseovercolor;
}

function showMenu (mymenu,myparent) {
  if (!DoneBuildingMenus) {return false}
	localMenu = getObject(mymenu);
	//<!--- This will hide all menus unless the current menu is a subMenu --->
	if (!localMenu.parent){ hideAll(); }
	//<!--- Set the location of the Sub menu --->
	if (localMenu.parent){
    //moveto(localMenu,getx(localMenu.parent) + localMenu.parent.clientWidth + borderWidth + 2,(myparent.offsetTop + gety(localMenu.parent)));
    moveto(localMenu,borderWidth + 2,(myparent.offsetTop + gety(localMenu.parent)));
    //moveto(localMenu,(localMenu.parent.clientWidth/2),82);
  } 
	localMenu.style.visibility = 'visible';
  return true;
} 


function hideMenu (mymenu) {

  if (!DoneBuildingMenus) {return false}
	if (typeof mymenu == "string"){
		hold = mymenu;
		document.all[hold].tid = setTimeout('document.all[hold].style.visibility = \'hidden\';', 500);
	}else{
		menu = eval(mymenu);
		menu.tid = setTimeout('menu.style.visibility = \'hidden\'', 500);
	}
	return true;
}

function hideParent(mymenu){
	if (mymenu.parent != null){
		localMenu = getObject(mymenu.parent);
		localMenu.tid = setTimeout('localMenu.style.visibility = \'hidden\'', 500);

		if (localMenu.parent != null){
			PPlocalMenu = getObject(mymenu.parent.parent);
			PPlocalMenu.tid = setTimeout('PPlocalMenu.style.visibility = \'hidden\'', 500);
		}
	}
}

function hideAll() {
	for(i=1; i<arrcnt; i++) {
		document.all["menu" + i].style.visibility = "hidden";
		clearTimeout(eval(document.all["menu" + i].tid));
	}	
}

function hideAllSubMenu(mymenu) {
//<!--- This function will loop through all available menus and see if the menu being --->
//<!--- displayed is listed as a parent to current menu. If it is, then this will hide the --->
//<!--- current menu (current to the loop) --->
//<!--- The purpose for this is so that all sub menu's are cleared before another is shown. --->
	for(i=1; i<arrcnt; i++) {
		currentMenu = eval("menu" + i)
		localMenu = getObject(mymenu);
		if (currentMenu.parent && (currentMenu.parent.id == localMenu.id)){
			currentMenu.style.visibility = "hidden";
			clearTimeout(currentMenu.tid);
		}

	}//<!--- for --->
}//<!--- hideAllSubMenu --->

function clearParent(mymenu){
	localMenu = getObject(mymenu.parent)
	if (localMenu){
		clearTimeout(localMenu.tid);

		PPlocalMenu = getObject(localMenu.parent)
		if (PPlocalMenu){
			clearTimeout(PPlocalMenu.tid);
		}
	}
}

function moveto(mymenu,x,y){
	localMenu = getObject(mymenu);
//  var winWidth = localMenu.parent.clientWidth;
  // localMenu.style.pixelRight = x; 
	// localMenu.style.pixelLeft = x; // window.width.value / 2; //x+480; 
  localMenu.style.pixelLeft = x;
  //window.status = "x="+x+" and y="+y; //window.width.value;
	localMenu.style.pixelTop = y; 
}

function getx(mymenu){ return mymenu.style.pixelLeft;}
function gety(mymenu){return mymenu.style.pixelTop;}

function debug(data){
	myform.mytext.value = (debugcnt++) + " " + data + "\n" + myform.mytext.value;
}
debugcnt=0;
