var globMainMenuArr=new Array();
var globSubMenuArr=new Array();
var subMenuReady=false;
var activeSubMenu;
var activeMenu;
var selectedMenu;
var firstMenuLeft=60;
var mainMenuSpacer=0;
var mainMenuTop=44;
var subMenuInitialTopmargin=1;

var globTimer;
var globHideDelay=500;

function initVariables(){
globMainMenuArr=null
globMainMenuArr=new Array();

globSubMenuArr=null
globSubMenuArr=new Array();

subMenuReady=false;
}

function newMenuObj(strTitle,strUrl,strNewMenu,strId,strUcnt,strKind,strTarget,where){
	var newDiv;
	newDiv=where.document.createElement("div");
	newDiv.style.position="absolute";
	newDiv.style.visibility="hidden";
	newDiv.innerHTML="<img src='/gfx/spacer.gif' width='10'><a href='#' target='_self' onmouseout='parent.mainMouseOut("+globMainMenuArr.length+")' onmouseover='parent.mainMouseOver("+globMainMenuArr.length+")' onclick=\"parent.navigate('"+strUrl+"','"+strNewMenu+"','"+strId+"','"+strUcnt+"','"+strKind+"','"+strTarget+"',"+globMainMenuArr.length+")\" class='overMenu'><nobr>"+strTitle+"</nobr></a><img src='/gfx/spacer.gif' width='10'><img src='/gfx/menuseperator.gif' align=absmiddle>";
	
	newDiv.subMenu=new Array()
	

	globMainMenuArr[globMainMenuArr.length]=newDiv;
}

function newSubMenuObj(strTitle,url,newMenu,id,ucnt,kind,target){
	globMainMenuArr[globMainMenuArr.length-1].subMenu[globMainMenuArr[globMainMenuArr.length-1].subMenu.length]=new subMenuClass(strTitle,url,newMenu,id,ucnt,kind,target)
	//subMenuObj.sId=id;
}

function subMenuClass(strTitle,url,newMenu,id,ucnt,kind,target){
	this.sTitle=strTitle;
	this.sUrl=url;
	this.sNewMenu=newMenu;
	this.sId=id;
	this.sUcnt=ucnt;
	this.skind=kind;
	this.sTarget=target;
	return this
}

function setUpMenu(where){
	var i
	
	for(i=0 ; i<globMainMenuArr.length ; i++){
		where.document.body.appendChild(globMainMenuArr[i])
		if(i==0){
			globMainMenuArr[i].style.left=firstMenuLeft;
		}else{
			globMainMenuArr[i].style.left=parseInt(globMainMenuArr[i-1].style.left)+mainMenuSpacer+parseInt(globMainMenuArr[i-1].offsetWidth);
		}
		globMainMenuArr[i].style.top=mainMenuTop;
		globMainMenuArr[i].style.visibility="visible";
	}
}

function setUpSubMenu(){
	var tmpStr,newDiv,newDivId,i,ii,newBack;
	subMenuReady=true;
	for(i=0 ; i<globMainMenuArr.length ; i++){
		tmpStr="	<table width=\"121\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
		for(ii=0;ii<globMainMenuArr[i].subMenu.length;ii++){		
			tmpStr+="	  <tr> ";
			tmpStr+="	    <td width=\"8\" class=\"MenuUndermenuBG\"><img src=\"/gfx/transparent.gif\" width=\"1\" height=\"1\"></td>";
			tmpStr+="	    <td width=\"111\" class=\"MenuUndermenuBG\"><a target='_self' href=\"javascript:parent.navigate('"+globMainMenuArr[i].subMenu[ii].sUrl+"','"+globMainMenuArr[i].subMenu[ii].sNewMenu+"','"+globMainMenuArr[i].subMenu[ii].sId+"','"+globMainMenuArr[i].subMenu[ii].sUcnt+"','"+globMainMenuArr[i].subMenu[ii].sKind+"','"+globMainMenuArr[i].subMenu[ii].sTarget+"'," + i + ")\" onclick=\"parent.navigate('"+globMainMenuArr[i].subMenu[ii].sUrl+"','"+globMainMenuArr[i].subMenu[ii].sNewMenu+"','"+globMainMenuArr[i].subMenu[ii].sId+"','"+globMainMenuArr[i].subMenu[ii].sUcnt+"','"+globMainMenuArr[i].subMenu[ii].sKind+"','"+globMainMenuArr[i].subMenu[ii].sTarget+"', " + i + ")\" onmouseOver=\"parent.subMouseOver("+i+")\" onMouseOut=\"parent.subMouseOut("+i+")\" class=\"UnderMenu\"><nobr>"+globMainMenuArr[i].subMenu[ii].sTitle+"</nobr></a>&nbsp;</td>";
			tmpStr+="	  </tr>";
			tmpStr+="	  <tr>";
			tmpStr+="	    <td class=\"MenuUndermenuBG1pxline\" width=\"8\"><img src=\"/gfx/transparent.gif\" width=\"1\" height=\"1\"></td>";
			tmpStr+="	    <td class=\"MenuUndermenuBG1pxline\" width=\"111\"><img src=\"/gfx/transparent.gif\" width=\"1\" height=\"1\"></td>";
			tmpStr+="	  </tr>";
//			tmpStr+="	  <tr>";
//			tmpStr+="	    <td bgcolor=#000000 colspan=2><img src=\"/gfx/transparent.gif\" width=\"1\" height=\"1\"></td>";
//			tmpStr+="	  </tr>";
		}
		
		tmpStr+="</table>";
		newDiv=parent.frames.contentsFrame.document.createElement("div");
		
		newDiv.style.position="absolute";
		newDiv.style.visibility="hidden";
		//newDiv.id="sMenu_"+i
		newDiv.style.top=subMenuInitialTopmargin;
		newDiv.style.left=globMainMenuArr[i].style.left
		newDiv.innerHTML=tmpStr;
		newDiv.style.zIndex=200;
		parent.frames.contentsFrame.document.body.appendChild(newDiv)
		
		newBack=parent.frames.contentsFrame.document.createElement("div");
		newBack.style.position="absolute";
		newBack.style.visibility="hidden";
		

		newBack.style.left=newDiv.style.left;
		newBack.style.top=newDiv.style.top;
		newBack.style.zIndex=0;//newDiv.style.zIndex-1
		
		if (is.ie4){
			newBack.style.height=parseInt(newDiv.scrollHeight);
			newBack.style.width=parseInt(newDiv.scrollWidth)+1;
		
		parent.frames.contentsFrame.document.body.appendChild(newBack)
			newBack.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/gfx/semibackTT.png','scale')"
			newBack.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "scale"

		}else{
			newBack.style.height=parseInt(newDiv.offsetHeight);
			newBack.style.width=parseInt(newDiv.offsetWidth);
			newBack.innerHTML="<img src='/gfx/spacer.gif' height=100% width=100%>"
			newBack.style.backgroundImage="url('/gfx/semibackTT.png')"
			
			parent.frames.contentsFrame.document.body.appendChild(newBack)
		}
		
		newDiv.pngBack=newBack
		globMainMenuArr[i].subMenuObj=newDiv
	}
}

function subMouseOver(id){
	globTimer?window.clearTimeout(globTimer):null;
}

function subMouseOut(id){
	hideIt(id);
}

function mainMouseOver(id){
	showSubmenu(id)
}

function mainMouseOut(id){
	hideIt(id)
}

function showSubmenu(id){
	globTimer?window.clearTimeout(globTimer):null;
	var intScrollY=0;
	if(!subMenuReady && !parent.frames.rightFrame.contentLoaded){
		setUpSubMenu();
		parent.frames.rightFrame.contentLoaded=true;
		parent.frames.rightFrame.menuLoaded=true;
	}
	
	//activeSubMenu?activeSubMenu.style.visibility="hidden":null;
	//activeSubMenu?activeSubMenu.pngBack.style.visibility="hidden":null;
	hideActiveSubMenu()
	
//		globMainMenuArr[id].style.backgroundImage="url(/gfx/topMenuBackground.gif)"
		activeMenu=globMainMenuArr[id]
				
	if(globMainMenuArr[id].subMenu.length<=0){
		return false;
	}else{
		globMainMenuArr[id].subMenuObj.style.visibility="visible"
		globMainMenuArr[id].subMenuObj.pngBack.style.visibility="visible";

		if(is.ns6){
			intScrollY=parent.frames.contentsFrame.pageYOffset;
		}else{
			intScrollY=parent.frames.contentsFrame.document.body.scrollTop
		}

		
		globMainMenuArr[id].subMenuObj.style.top=subMenuInitialTopmargin+intScrollY;
		globMainMenuArr[id].subMenuObj.pngBack.style.top=subMenuInitialTopmargin+intScrollY;
		activeSubMenu=id;
		
	}
}
function hideIt(){
	globTimer=window.setTimeout("hideActiveSubMenu()",globHideDelay)
}

function hideActiveSubMenu(id){
		//activeMenu!=selectedMenu?activeMenu.style.backgroundImage="url(/gfx/spacer.gif)":null;
		activeSubMenu>-1?globMainMenuArr[activeSubMenu].subMenuObj.style.visibility="hidden":null;
		activeSubMenu>-1?globMainMenuArr[activeSubMenu].subMenuObj.pngBack.style.visibility="hidden":null;
	
}

function navigate(itemUrl,newMenu,itemId,ucnt,menuKind,target,menuId){
	activeSubMenu=-1;
	if(newMenu=="y"){
		parent.frames.menuFrame.document.location="/mod_inc/?P=menu&backbut=true&parentOffset="+itemId;
		parent.frames.contentsFrame.document.location=itemUrl;
	}else{
		parent.hideActiveSubMenu(0);
		eval('parent.frames.'+target+'.document.location=itemUrl');
	}
	selectedMenu?selectedMenu.style.backgroundImage="url(/gfx/spacer.gif)":null;
	selectedMenu=globMainMenuArr[menuId]
	//selectedMenu.style.backgroundImage="url(/gfx/topMenuBackground.gif)"
}