function menuObject(){
	this.dataObject = new menuDataObject();
	this.offsetId = 0;
	this.includeFrontPage = false;
	this.dataObject.offsetId = this.offsetId;
	this.dataObject.includeFrontPage = this.includeFrontPage;
	
	this.top=0;
	this.className=""
	this.mainMenuObjects = new Array();
	this.allMenuObjects = new Array();
	
	//EXTERNAL FUNCTIONS
	this.createMenu=__createMenu;
	this.createMenu2=__createMenu2;
	
	
	//INTERNAL FUNCTIONS	
	this.createSubMenu = __createSubMenu;
	this.createSubMenu2 = __createSubMenu2;
	
	return this;
}

function menuViewObject(){
	this.viewDivObj = null;
	this.viewTableObj = null;
	this.viewTdObj = null;
	
	this.childViewObj = null;
	this.parentViewObj = null;
	
	return this
}





function __createMenu(){
	var menuArr = this.dataObject.topMenues
	var retStr, divObj, i, vObj, tmp, isFirst=true;borderStyle=""
	
	
	for(i=0;i<menuArr.length;i++){ // all level 1 menues
		if(this.includeFrontPage || (!this.includeFrontPage && !menuArr[i].isFront)){
			divObj = document.createElement("DIV")
			document.body.appendChild(divObj)

				
				
				retStr = "<table border='0' style='' cellpadding='0' id='menuTbl_" + menuArr[i].id + "'><tr>"
			
				retStr += "<td style='cursor:hand;' class='" + this.className + "' onmouseOut='mainOut(" + menuArr[i].id + ",this)' onmouseOver='mainOver(" + menuArr[i].id + ",this)' id='menuCell_"+menuArr[i].id+"' onclick=\"document.location='" + menuArr[i].url + "&mid="+menuArr[i].id+"'\"><nobr>"+menuArr[i].title+"</nobr></td>"
				if(menuArr.length>i+1){
					retStr += "<td style='color:#fff'>|</td>"
				}
				
				
				retStr += "</tr></table>"
				divObj.innerHTML = retStr;
				divObj.style.visibility = "hidden";
				divObj.style.position="absolute";
				divObj.style.top=this.top
				divObj.style.height=10
				divObj.style.left="0"

			divObj.id = "mContainer_" + menuArr[i].id;	
			
			viewObj = this.mainMenuObjects[this.mainMenuObjects.length] = new menuViewObject()
			
			viewObj.viewDivObj = divObj;
			viewObj.viewTableObj = document.getElementById("menuTbl_" + menuArr[i].id)
			viewObj.viewTdObj = document.getElementById("menuCell_" + menuArr[i].id)
			this.allMenuObjects[this.allMenuObjects.length]=viewObj;
			//divObj;
			
			//Submenu
			this.createSubMenu(menuArr[i],viewObj)
			isFirst?isFirst=false:null;
		}
	}
}

function __createSubMenu(pObj,vObj){
	if(pObj.childs.length>0){
			var retStr="";
			var divObj, i, tmpMVO;
			divObj = document.createElement("DIV")
			document.body.appendChild(divObj)
			retStr = "<table border='0' class='subMenu' width=100% cellspacing='0' cellpadding='0' id='childMenuTbl_" + pObj.id + "'>"
			for(i=0;i<pObj.childs.length;i++){
				retStr += "<tr><td bgcolor='#FFFFFF' height=15 class='subMenu' onclick='document.location=\"" + pObj.childs[i].url + "&mid="+pObj.id+"&scid="+pObj.childs[i].id+"\"' onmouseOut='subOut(" + pObj.childs[i].id + ",this)' onmouseOver='subOver(" + pObj.childs[i].id + ",this)' id='childMenuCell_"+pObj.childs[i].id+"'>" + pObj.childs[i].title + "</td></tr>"
				//this.createSubMenu(pObj.childs[i]) //recurse
			}
			
			retStr += "</table>"
			
			divObj.innerHTML = retStr;
			divObj.style.visibility = "hidden";
			divObj.style.position="absolute";
			divObj.style.top="0"
			divObj.style.left="0"
			divObj.style.zIndex="1000"
			divObj.id = "childMenuContainer_" + pObj.id;	
			divObj.innerHTML = retStr;

			tmpMVO = new menuViewObject();
			tmpMVO.viewDivObj = divObj
			tmpMVO.viewTableObj = document.getElementById("childMenuTbl_" + pObj.id)
			
			vObj.childViewObj = tmpMVO;	
			this.allMenuObjects[this.allMenuObjects.length]=tmpMVO
		}
}






function __createMenu2(){
	var menuArr = this.dataObject.topMenues
	var retStr="", divObj, i, vObj, tmp, isFirst=true;

	
	for(i=0;i<menuArr.length;i++){ // all level 1 menues
		isFirst?borderWidth=1:borderWidth=0;
		isFirst=false
		if(this.includeFrontPage || (!this.includeFrontPage && !menuArr[i].isFront)){
			retStr += "<table border='0' cellspacing='0' width=115 style='border-width:"+borderWidth+" 0 1 0; border-color:#c0c0c0; border-style:solid;' cellpadding='0' id='menuTblMain'>";
				if(menuArr[i].childs.length<1){
					retStr += "<tr><td class='" + this.className + "' style='font-weight:bold;border-bottom-width:0px; height:15px;' onmouseOut='mainOut2(" + menuArr[i].id + ",this)' onmouseOver='mainOver2(" + menuArr[i].id + ","+this.uId+",this)' id='menuCell_"+menuArr[i].id+"' onclick=\"document.location='" + menuArr[i].url + "&mid="+document.mid+"&scid=0'\">"+menuArr[i].title+"</td></tr>";
				}else{
					retStr += "<tr><td class='" + this.className + "' style='font-weight:bold; border-bottom-width:0px; height:15px;' height=15 onmouseOut='mainOut2(" + menuArr[i].id + ",this)' onmouseOver='mainOver2(" + menuArr[i].id + ","+this.uId+",this)' id='menuCell_"+menuArr[i].id+"' onclick=\"document.location='" + menuArr[i].url + "&mid="+document.mid+"&scid="+menuArr[i].id+"'\">"+menuArr[i].title+"</td></tr>";
				}
				
				if(menuArr[i].id==document.scid){
					retStr += this.createSubMenu2(menuArr[i],0,retStr)
				}
				
			retStr += "</table>";				
			//Submenu
		}
	}

	divObj = document.createElement("DIV")
			
	divObj.innerHTML = retStr;
	divObj.style.position="absolute";
	divObj.style.top=this.top;
	divObj.style.display="none"
	
	divObj.id = "menuContainer_" + this.uId;
	document.body.appendChild(divObj)
		
	//this.allMenuObjects[this.allMenuObjects.length]=viewObj;
 	

		
}

function __createSubMenu2(pObj,lvl,retStrt){
	var retStr="";
			var i, className="childmenu";
	if(pObj.childs.length>0){
			for(i=0;i<pObj.childs.length;i++){
				retStr += "<tr><td bgcolor='#FFFFFF' height=15 class='" + className + "' style='padding:0 0 5 15;' onclick='document.location=\"" + pObj.childs[i].url + "&mid="+document.mid+"&scid="+document.scid+"\"' onmouseOut='mainOut2(" + pObj.childs[i].id + ",this)' onmouseOver='mainOver2(" + pObj.childs[i].id + "," + pObj.id + ",this)' id='childMenuCell_"+pObj.childs[i].id+"'>" + pObj.childs[i].title + "</td></tr>"				
				retStr += this.createSubMenu2(pObj.childs[i],lvl+1,retStr)
			}
	}
	return retStr
}
/*************************Functions for the display things ***************************************/
var menuTimer;

function mainOver2(childId, ownId, obj){


	obj.className += "Hover"

}
	

function mainOut2(id, obj){	
	
	obj.className=obj.className.toString().replace(/hover/gi,"")
	
}


function hideShowingDivs(divObj){
	divObj.style.visibility="hidden";
	divObj.style.display="none";
	if(divObj.showingDiv)
		hideShowingDivs(divObj.showingDiv);
}

function hideAllDivs(id){
	oDivs = document.body.getElementsByTagName("DIV");
	for(i=0;i<oDivs.length;i++){
		if(oDivs[i].id.toString().indexOf("menuContainer_")>-1){
			oDivs[i].showingDiv=null;
			if(oDivs[i].id!="menuContainer_2"){
				oDivs[i].style.visibility="hidden";
				oDivs[i].style.display="none";
			}
		}
	}
}

/*************************Functions for the display things ***************************************/

document.menuTimer=null;
document.showingEl=null;
document.activeMainMenu=null;
document.useFilter=4
document.effectTime=0.2
document.filt = new Array()
document.filt[1] = "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=50,duration=0.2)"
document.filt[2] = "progid:DXImageTransform.Microsoft.RandomDissolve(duration=0.5)"
document.filt[3] = "progid:DXImageTransform.Microsoft.Slide(slidestyle=PUSH,Bands=2)"
document.filt[4] = "progid:DXImageTransform.Microsoft.Fade(Overlap=0.5,percent=11,Duration="+document.effectTime+")"
document.filt[5] = "progid:DXImageTransform.Microsoft.Checkerboard(Direction=right,SquaresX=50,SquaresY=50)"
document.filt[6] = "progid:DXImageTransform.Microsoft.Iris(irisstyle=circle,motion=in)"
document.filt[7] = "progid:DXImageTransform.Microsoft.Stretch(stretchstyle=SPIN)"
document.filt[8] = "progid:DXImageTransform.Microsoft.Opacity(opacity=10,style=0)"


function mainOver(id, obj){
	var subDiv, dObj
	if(document.menuTimer){window.clearTimeout(document.menuTimer);document.menuTimer=null}
	subDiv=document.getElementById("childMenuContainer_"+id);
	
	if(document.showingEl && document.showingEl!=subDiv){
		document.showingEl.style.visibility="hidden";
		tmpId = document.showingEl.id.toString().replace(/childMenuContainer_/gi,"")
		__mainOut(tmpId, "menuCell_"+tmpId)
	}
	

	obj.className.toString().indexOf("Hover")==-1?obj.className+="Hover":null;
	document.activeMainMenu = obj
	dObj = document.getElementById("mContainer_"+id)
	
	
	
	if(!dObj.oldZ){
		dObj.oldZ = dObj.style.zIndex;
		dObj.style.zIndex = dObj.style.zIndex + 2
	}
	
	if(subDiv && document.showingEl!=subDiv){
		if(document.all){
			subDiv.style.filter='progid:DXImageTransform.Microsoft.Fade(Overlap=0.5,percent=11,Duration=0.2) alpha(opacity=90) progid:DXImageTransform.Microsoft.Shadow(color="#000000",Direction=135,Strength=1)';
			subDiv.filters[0].apply();
			
			
			subDiv.style.visibility="visible";
			subDiv.filters[0].play();
			
			
			
			



		}else{
			subDiv.style.visibility="visible";
			subDiv.style.opacity=0.0;
			setOpIn(99,10,subDiv.id)
		}
		
		
	}
	subDiv?document.showingEl=subDiv:null;
}



function setOpIn(end,jmp,objId){
	obj=document.getElementById(objId)
	if(end<=obj.style.opacity*100+jmp){
		obj.style.opacity=end/100;
	}else{
		obj.style.opacity=parseFloat(obj.style.opacity)+(parseFloat((jmp/100)));
		window.setTimeout("setOpIn("+end+","+jmp+",'"+objId+"')",30)
	}
}

function setOpOut(end,jmp,objId){
	obj=document.getElementById(objId)
	if(obj.style.opacity*100-jmp<=end){
		obj.style.opacity=end/100;
		obj.style.visibility="hidden";
	}else{
		obj.style.opacity=parseFloat(obj.style.opacity)-(parseFloat((jmp/100)));
		window.setTimeout("setOpOut("+end+","+jmp+",'"+objId+"')",30)
	}
}

function mainOut(id, obj){	
	var dObj

	
	document.menuTimer=window.setTimeout("__mainOut('"+id+"','"+obj.id+"')",500)	
	if(!document.getElementById("childMenuContainer_"+id)){
		obj.className=obj.className.toString().replace(/Hover/gi,"")
		dObj = document.getElementById("mContainer_" + id)
		dObj.style.zIndex = dObj.oldZ
		dObj.oldZ=null;
	}
}

function __mainOut(id,obj){
	var dObj, obj2
	document.getElementById(obj).className=document.getElementById(obj).className.toString().replace(/Hover/gi,"")

	
	subDiv=document.getElementById("childMenuContainer_"+id);
	if(subDiv){
		dObj = document.getElementById("mContainer_" + id)
		dObj.style.zIndex = dObj.oldZ
		dObj.oldZ=null;
		if(document.all){
			subDiv.filters[0].apply();
			subDiv.style.visibility="hidden"
			subDiv.filters[0].play();
		}else{
			setOpOut(0,10,subDiv.id)
		}
	}
	document.showingEl=null
}

function subOver(id, obj){
	if(document.menuTimer){window.clearTimeout(document.menuTimer);document.menuTimer=null}
	obj.className="subMenuHover"
}

function subOut(id, obj){
	obj.className="subMenu"
	document.menuTimer=window.setTimeout("__subOut('"+id+"','"+obj.id+"')",500)	
}

function __subOut(id, obj){
	subDiv=document.showingEl //document.getElementById("childMenuContainer_"+id);
		if(subDiv){
		if(document.all){
			subDiv.filters[0].apply();
			subDiv.style.visibility="hidden"
			subDiv.filters[0].play();
		}else{
			setOpOut(0,10,subDiv.id)
		}
	}
	document.showingEl=null
	document.activeMainMenu.className=document.activeMainMenu.className.toString().replace(/Hover/gi,"")
		
		dObj = document.getElementById("mContainer_" + document.activeMainMenu.id.replace(/menuCell_/gi,""))
		dObj.style.zIndex = dObj.oldZ
		dObj.oldZ=null;
}
