menuCount=1;
menuList=[];
buildList=[];

arrStr="<img src=/jeremy//%22/nav/m_arrow.gif/%22 style=\"width:16;height:7;clip:rect(0px 0px 16px 7px);\">";

function buildMenus(){
	if(!MSDOM&&!GECKO) return false;
	beingCreated=true;
	while(eval("window.menuArray"+menuCount)){
		makeMenu(false,menuCount);
		menuCount++;
	}
	for(menuCount=0;menuCount<buildList.length;menuCount+=2){
		makeMenu(buildList[menuCount],buildList[menuCount+1]);
	}
	areCreated=true;
	beingCreated=false;   
}

function makeMenu(parMenu,mCount){
	D=document;
	nMenu=D.createElement("div");
	nMenu.setup=menuSetup;
	nMenu.setup(parMenu,mCount);
}

function menuSetup(parMenu,mCount){
	D=document;
    
	this.array=eval("menuArray"+mCount);
	this.childList=[];
	this.num=mCount;
	this.parMenu=parMenu;
	this.overMenu=false;
	this.buttonSetup=buttonSetup;
	this.hide=hide;
	this.hideAll=hideAll;
	this.id="menu"+mCount;
	this.className=menuClassName
	this.noWrap=true;
	menuList[menuList.length]=this.id;
	D.body.appendChild(this);
	this.buttonSetup();
}

function buttonSetup(){
	for(i=1;i<this.array.length;i++){
		D=document;
		nSpan=D.createElement("div");
		with(nSpan){
			id=this.id+"span"+i;
			if(i==this.array.length-1) className="last";
			/*with(style){
				width= "100%"//(GECKO)?menuWidth-(2*menuPadding+2*borderWidth+7):menuWidth-(2*menuBorderWidth);
				height=(GECKO)?menuHeight-(2*menuPadding+2*borderWidth):menuHeight;
				backgroundColor=(this.parMenu)?menuBgColorDn:menuBgColorUp;
                borderWidth=0;
				borderStyle="none";
			    fontFamily=menuTextFace;
				fontSize=menuTextSize;
				color=(this.parMenu)?menuTextColorDn:menuTextColorUp;
				padding=menuPadding;
				paddingLeft=menuPadding+5;
				lineHeight=menuHeight-(2*menuPadding)+"px";
				margin=0;
				zIndex=100;
			    fontVariant=menuTextVariant;
			}*/
			innerHTML=this.array[i][0];
		}
		nSpan.setup=itemSetup;
		nSpan.setup(this.parMenu);
		nSpan.href=this.array[i][1];
		nSpan.txOver=this.array[i][2];
		nSpan.parMenu=this.id;
		nSpan.childMenu=false;
		if(this.array[i][3]){
			nSpan.childMenu=this.id+"_"+this.array[i][3];
            nSpan.style.backgroundImage = "url('/nav/m_arrow.gif')";
            nSpan.style.backgroundRepeat= "no-repeat";
            nSpan.style.backgroundAlign = "right";
            nSpan.style.backgroundPositionX = "100%";
            nSpan.style.backgroundPositionY = "50%";
			this.childList[this.childList.length]=this.id+"_"+this.array[i][3];
			buildList[buildList.length]=this.id;
			buildList[buildList.length]=this.num+"_"+this.array[i][3];
		}
		this.appendChild(nSpan);
	}
}

function itemSetup(flyout){
	this.onmouseout=menuUp;
	this.onmouseover=menuDn;
	this.onclick=clicked;
}

function openMenu(menu, parentObj){
    if(NS4) return;
    if(!areCreated||beingCreated) return;
	OM=document.getElementById(menu);
    
    if(!OM) return;
  
	positionMenus();
    OM.style.visibility="visible";
  
}

function closeMenu(menu){
	if(NS4) return;
	if(!areCreated||beingCreated) return;
	setTimeout("hideMenu('"+menu+"')",100);
}

function hideMenu(menu){
	MO=document.getElementById(menu);
    
    if(!MO) return false;
    if(!MO.overMenu){
        
		MO.hide();
	}
}

function positionMenus(){
	var dW=(MSDOM)?document.body.clientWidth:window.innerWidth;
	leftEdge= parseInt((dW-pageWidth)/2);
    topEdge = document.getElementById("top_nav").offsetTop;

	if(leftEdge<0) leftEdge=10;
	for(i=0;i<menuList.length;i++){
		MO=document.getElementById(menuList[i]);
		if(IE4) {
			MO.style.pixelLeft=MO.array[0][0]+leftEdge;
			MO.style.pixelTop=MO.array[0][1]+topEdge;
		} else {
			topoff=MO.array[0][1]+topEdge;
			leftoff=MO.array[0][0]+leftEdge;
			MO.style.top=topoff+"px";
			MO.style.left=leftoff+"px";
		}
	}
}

function hide(){
	keepItOpen=false;
    
	for(i=0;i<this.childList.length;i++){
		MM=document.getElementById(this.childList[i]);
        
		if(MM.overMenu) keepItOpen=true;
	}
	if(!keepItOpen){
		this.style.visibility="hidden";
		if(this.childList.length) this.hideAll;
		else if(this.parMenu){
			MM=document.getElementById(this.parMenu);
			if(!MM.overMenu) setTimeout("hideMenu('"+MM.id+"')",100);
		}
	}
}

function hideAllMenus(){
    
    for(var x = 1; x < all_menus.length; x++){
      
      var root_menu = document.getElementById("menu"+x);
      
      try
      {   
          root_menu.hide();
         
      }
      catch(e)
      {
      }
   }
   
}
function hideAll(){
    alert("hideAll()"+this);
	for(k=0;k<this.childList.length;k++){
		MA=document.getElementById(this.childList[k]);
		MA.overMenu=false;
		closeMenu(this.childList[k]);
	}
}

function menuUp(){
	parMenu=document.getElementById(this.parMenu);
    
	parMenu.overMenu=false;
	with(this.style){
		color="#660000";
	}
	closeMenu(parMenu.id);
	
	if(this.childMenu) closeMenu(this.childMenu);
}

var str_menu_to_open;
function menuDn(){
	D=document;
    
	parMenu=D.getElementById(this.parMenu);
	parMenu.overMenu=true;
	with(this.style){
		color="#666666"
	}
	if(this.childMenu){
        str_menu_to_open = this.childMenu;
            
			setTimeout("openMenu(str_menu_to_open);",110)
		}
	window.status=this.txOver;
}

function clicked(){
	if(this.href.indexOf("JavaScript:")!= -1) eval(this.href);
	else window.location.href=this.href;
}

//onerror=function(){return true;}
