function menuObject(){
	this.dataObject = new menuDataObject();
	this.offsetId = 0;
	this.includeFrontPage = false;
	this.dataObject.offsetId = this.offsetId;
	this.dataObject.includeFrontPage = this.includeFrontPage;
	this.uId=0
	
	this.top=0;
	this.className=""
	this.mainMenuObjects = new Array();
	this.allMenuObjects = new Array();
	
	//EXTERNAL FUNCTIONS
	this.createMenu=__createMenu;
	
	
	//INTERNAL FUNCTIONS	
	this.createSubMenu = __createSubMenu;
	
	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;

	retStr = "<table border='0' cellspacing='0' width='80' cellpadding='0' id='menuTblMain'>";
	for(i=0;i<menuArr.length;i++){ // all level 1 menues
		if(this.includeFrontPage || (!this.includeFrontPage && !menuArr[i].isFront)){
				if(menuArr[i].childs.length<1){
					retStr += "<tr><td class='" + this.className + "' height=15 onmouseOut='mainOut(" + menuArr[i].id + ",this)' onmouseOver='mainOver(" + menuArr[i].id + ",0,this)' id='menuCell_"+menuArr[i].id+"' onclick=\"document.location='" + menuArr[i].url + "'\"><nobr>"+menuArr[i].title+"</nobr></td></tr>";
				}else{
					retStr += "<tr><td class='" + this.className + "' style='cursor:default;' height=15 onmouseOut='mainOut(" + menuArr[i].id + ",this)' onmouseOver='mainOver(" + menuArr[i].id + ",0,this)' id='menuCell_"+menuArr[i].id+"' aonclick=\"document.location='" + menuArr[i].url + "'\"><nobr>"+menuArr[i].title+"</nobr></td></tr>";
				}
				this.createSubMenu(menuArr[i],0)
			//Submenu
		}
	}
	retStr += "</table>";

	divObj = document.createElement("DIV")
	document.body.appendChild(divObj)		
	divObj.innerHTML = retStr;
	divObj.style.position="absolute";
	divObj.style.top=this.top;
	divObj.style.height=10;
	divObj.style.left="0";
	divObj.id = "menuContainer_" + this.uId;
		
	//this.allMenuObjects[this.allMenuObjects.length]=viewObj;
 	

		
}

function __createSubMenu(pObj,lvl){
	if(pObj.childs.length>0){
			var retStr="";
			var divObj, i, tmpLvl=lvl,className;
			divObj = document.createElement("DIV")
			document.body.appendChild(divObj)
			
			tmpLvl % 2 ? className="subMenu2":className="submenu";
			
			retStr = "<table border='0' class='" + className + "' width=100% cellspacing='0' cellpadding='0' id='childMenuTbl_" + pObj.id + "'>"
			for(i=0;i<pObj.childs.length;i++){
				if(pObj.childs[i].childs.length<1){
					retStr += "<tr><td bgcolor='#FFFFFF' height=15 class='" + className + "' onclick='document.location=\"" + pObj.childs[i].url + "\"' onmouseOut='mainOut(" + pObj.childs[i].id + ",this)' onmouseOver='mainOver(" + pObj.childs[i].id + "," + pObj.id + ",this)' id='childMenuCell_"+pObj.childs[i].id+"'>" + pObj.childs[i].title + "</td></tr>"				
				}else{
					retStr += "<tr><td bgcolor='#FFFFFF' height=15 class='" + className + "' style='cursor:default;' aonclick='document.location=\"" + pObj.childs[i].url + "\"' onmouseOut='mainOut(" + pObj.childs[i].id + ",this)' onmouseOver='mainOver(" + pObj.childs[i].id + "," + pObj.id + ",this)' id='childMenuCell_"+pObj.childs[i].id+"'>" + pObj.childs[i].title + "</td></tr>"				
				}
				this.createSubMenu(pObj.childs[i],tmpLvl+1)
			}
			retStr += "</table>"
			
			divObj.innerHTML = retStr;
			divObj.style.visibility = "hidden";
			divObj.style.display = "none";
			divObj.style.position="absolute";
			divObj.style.top="0"
			divObj.style.left="0"
			divObj.style.width="159"
			divObj.id = "menuContainer_" + pObj.id;	
	}
}
/*************************Functions for the display things ***************************************/
var menuTimer;

function mainOver(childId, ownId, obj){
	menuTimer?window.clearTimeout(menuTimer):null;
	childDivObj = document.getElementById("menuContainer_" + childId);
	ownDivObj = document.getElementById("menuContainer_" + ownId);
	ownTdObj = obj;
	
	if(ownDivObj.showingDiv){
		if(ownDivObj.showingDiv!=childDivObj)
			hideShowingDivs(ownDivObj.showingDiv)
	}

	ownTdObj.className += "Hover"
	
	leftOffset = parseInt(ownDivObj.style.left) + parseInt(ownTdObj.offsetWidth)+1
	topOffset = parseInt(ownTdObj.offsetTop) + parseInt(ownDivObj.style.top)-0
		
	if(childDivObj){		
		childDivObj.style.top=topOffset;
		childDivObj.style.left=leftOffset;
		childDivObj.style.visibility="visible";
		childDivObj.style.display = "block";
		ownDivObj.showingDiv=childDivObj;
	}
}
	

function mainOut(id, obj){	
	var childDivObj = document.getElementById("menuContainer_" + id);	
	obj.className=obj.className.toString().replace(/hover/gi,"")
	menuTimer = window.setTimeout('hideAllDivs()',500)
}


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_0"){
				oDivs[i].style.visibility="hidden";
				oDivs[i].style.display="none";
			}
		}
	}
}