var globMainMenuArr=new Array();
var globSubMenuArr=new Array();
var subMenuReady=false;
var activeSubMenu;
var firstMenuLeft=15;
var mainMenuSpacer=9;
var mainMenuTop=1;
var subMenuInitialTopmargin=1;



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="<a href='#' target='_self' onmouseover='parent.showSubmenu("+globMainMenuArr.length+")' onclick=\"parent.navigate('"+strUrl+"','"+strNewMenu+"','"+strId+"','"+strUcnt+"','"+strKind+"','"+strTarget+"')\" class='overMenu'>"+strTitle+"</a><img src='/gfx/spacer.gif' width='13' align=absMiddle><img src='/gfx/menuseperator.gif' width=1 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\">";
		tmpStr+="	<tr><td colspan=\"2\"><img src=\"/gfx/spacer.gif\" height=2></td></tr>";
		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+"')\" 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+"')\" class=\"UnderMenu\">"+globMainMenuArr[i].subMenu[ii].sTitle+"</a></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+="</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);
		
		parent.frames.contentsFrame.document.body.appendChild(newBack)
			newBack.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/gfx/semiBack.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/semiBack.png')"
			
			parent.frames.contentsFrame.document.body.appendChild(newBack)
		}
		
		newDiv.pngBack=newBack
		globMainMenuArr[i].subMenuObj=newDiv
	}
}


function showSubmenu(id){
	var intScrollY=0;
	if(!subMenuReady && !parent.frames.rightFrame.contentLoaded){
		setUpSubMenu();
		parent.frames.rightFrame.contentLoaded=true;
		parent.frames.rightFrame.menuLoaded=true;
	}
	
	activeSubMenu>-1?globMainMenuArr[activeSubMenu].subMenuObj.style.visibility="hidden":null;
	
		activeSubMenu>-1?globMainMenuArr[activeSubMenu].subMenuObj.pngBack.style.visibility="hidden":null;
	
	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 hideActiveSubMenu(time){
	if(time){
		window.setTimeout('activeSubMenu?activeSubMenu.style.visibility="hidden":null;',time);
	}else{
		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){
	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');
		
	}
}