var ICONPATH='';
var LAYOUT=0;
var ARROW=1;
var SEPARATOR=1;
var MBORDER=1;
var MSHADOW=1;
var C_Shadow='#DBDBDB';
var C_Border='#666666';
var C_Background="#ffffff";
var C_subMenuBackground="#E3CEAF";		
var C_subMenuFont="#000000";
var C_Highlight='#6699bb';
var C_FontHighlight='#6699bb';
var C_subMenuHighlight='#000000';
var C_Font='#222222';
var supportDHTML=true;
var isOpera=false;
var isIE=false;
var isNS4=false;
var origWidth;
var origHeight;
var indexOfEntries=new Array;
var nEntries=0;
var activeImg='/lms/images/menu/arr2.gif';
var hiddenImg='/lms/images/menu/arr1.gif';
var noImg='/1.gif';
var iconWidth=20;
var delaytimer=0;
var hideMenu=null;

function checkBrowser(){
	var i,j;
	var version;
	var ua=window.navigator.userAgent.toLowerCase();
	if((i=ua.indexOf('hotjava'))!=-1) supportDHTML=false;
	else if((i=ua.indexOf('opera'))!=-1){
		version=parseFloat(ua.substr(i+6),4);
		if(version<5.02) supportDHTML=false;
		else{
			isOpera = true;
			if(version<7.0) onload=loadHandler;
		}
	}else if((i=ua.indexOf('msie'))!=-1){
		version=parseFloat('0'+ua.substr(i+5),10);
		if(version<4) supportDHTML=false;
		else isIE=true;
	}else if(typeof document.layers!="undefined"){
		isNS4=true;document.write("<style>");
		document.write("a{text-decoration:none}");
		document.write("</style>");
		onload=loadHandler;
		onresize=resizeHandler;
	}
};
			
function loadHandler(){
	if(isNS4||isOpera) {
		origWidth=this.innerWidth;origHeight=this.innerHeight;
		if (isOpera) resizeHandler();
	}
};

function resizeHandler(){
	if(this.innerWidth!=origWidth||this.innerHeight!=origHeight)document.location.reload();
	if(isOpera) setTimeout('resizeHandler()',800);
};

function dh(){
	if(hideMenu==null) return;
	for(var k=hideMenu.nvNodes-1;k>=hideMenu.hideIndex;k--){
		var j=hideMenu.visibleNodes[k];
		var obj="node"+j+"_n";
		var myObj = document.getElementById(obj);
		var isMainMenu = false;
		var myMainMenuTag = document.getElementById("node"+j+"_mm");
		if (myMainMenuTag){
		myMainMenuTag.style.color = hideMenu.C_Font;
		setBC(obj,hideMenu.C_Background);
		isMainMenu = true;
		}else{
			var mySubMenuFontTag = document.getElementById("node"+j+"_sm");
			if (mySubMenuFontTag){
			setBC(obj,hideMenu.C_subMenuBackground);
			}
			isMainMenu = false;
		}
		if(hideMenu.ARROW){
			obj="node"+j+"_w";
			var myObj2 = document.getElementById(obj);
			if (isMainMenu){
			setBC(obj,hideMenu.C_Background);
			}else{
			setBC(obj,hideMenu.C_subMenuBackground);
			}
			obj_img="node"+j+"_w_img";
			document.getElementById(obj_img).src=indexOfEntries[j].activeImg;
		}
		for(var i=0;i<indexOfEntries[j].nChildren;i++)hideNode(indexOfEntries[j].children[i]);
	}
	hideMenu.nvNodes=hideMenu.hideIndex;
	hideMenu=null;
};

function mEvent(id, action){
	var cMenu=indexOfEntries[id];
	var rMenu=findRoot(cMenu);
	if(hideMenu!=null&&hideMenu!=rMenu){
		setTimeout("dh()", 200);
	}
	hideMenu=rMenu;
	if(action == "t"){
		rMenu.hideIndex=1;
		setTimeout("dh()", 200);
	}else if(action == "o"){
		rMenu.hideIndex=rMenu.nvNodes;
		for(var i=0;i<rMenu.nvNodes;i++){
			if(indexOfEntries[rMenu.visibleNodes[i]]==cMenu.parentObj){
				if(rMenu.nvNodes>(i+1)){
					rMenu.hideIndex=i+1;
					if(rMenu.visibleNodes[i+1]==id)rMenu.hideIndex++;
					if(rMenu.hideIndex<rMenu.nvNodes){
						dh();
					}
				}
				if(rMenu.visibleNodes[rMenu.nvNodes-1]!=id)rMenu.visibleNodes[rMenu.nvNodes++]=id;
				rMenu.hideIndex=rMenu.nvNodes;break;
			}
		}
		var obj="node"+id+"_n";
		var setMainBG = true
		
		var myMenuFontTag = document.getElementById("node"+id+"_mm");
		if (myMenuFontTag){
		myMenuFontTag.style.color = rMenu.C_FontHighlight;
		setMainBG = false	
		}
		//if(document.all){
			if (setMainBG){		
			setBC(obj,rMenu.C_Highlight);
			}
		//}
		//var mySubMenuFontTag = document.getElementById("node"+id+"_sm");
		//if (mySubMenuFontTag){
		//mySubMenuFontTag.style.color = "white"
		//}

		if(rMenu.ARROW){obj="node"+id+"_w";
		if (setMainBG){
		setBC(obj,rMenu.C_Highlight);
		}
		obj_img="node"+id+"_w_img";
		document.getElementById(obj_img).src=cMenu.hiddenImg;
		}
		for(i=0;i<cMenu.nChildren;i++)showNode(cMenu.children[i]);
	}
};

function rootObj(){
	this.LAYOUT=LAYOUT;
	this.ARROW=ARROW;
	this.SEPARATOR=SEPARATOR;
	this.MBORDER=MBORDER;
	this.MSHADOW=MSHADOW;
	this.C_Shadow=C_Shadow;
	this.C_Border=C_Border;
	this.C_Background=C_Background;
	this.C_subMenuFont=C_subMenuFont; 
	this.C_subMenuBackground=C_subMenuBackground;
	this.C_subMenuHighlight=C_subMenuHighlight;	
	this.C_Highlight=C_Highlight;
	this.C_FontHighlight=C_FontHighlight;
	this.C_Font=C_Font;
	this.id=nEntries;indexOfEntries[nEntries]=this;
	nEntries++;
	this.level=0;
	this.children=new Array;
	this.nChildren=0;
	this.visibleNodes=new Array;
	this.nvNodes=0;this.hideIndex=0;
	this.cTop=0;
	this.cLeft=0;
};

function addMenuRoot(){
	return (new rootObj());
};

function NodeObj(n,h){
	this.id=nEntries;
	indexOfEntries[nEntries]=this;
	nEntries++;
	this.desc=n;
	this.link=h;
	this.level=0;
	this.parentObj=null;
	this.sID="";
	this.bID="";
	this.nID="";
	this.wID="";
	this.activeImg="";
	this.hiddenImg="";
	this.children=new Array;
	this.nChildren=0;
	this.cTop=0;
	this.cLeft=0;
};

function addNode(d,h){
	return (new NodeObj(d, h));
};

function addChild(node, child){
	node.children[node.nChildren]=child;
	child.parentObj=node;
	child.level=node.level+1;
	node.nChildren++;
	return child;
};

function getL(e){
	var el=document.getElementById(e);
	var x=el.offsetLeft;
	var parent=el.offsetParent;
	while(parent&&parent!=document.body){
		x+=parent.offsetLeft;
		parent=parent.offsetParent;
	};
	return x;
};

function getT(e){
	var el=document.getElementById(e);
	var y=el.offsetTop;
	var parent=el.offsetParent;
	while(parent && parent!=document.body){
		y+=parent.offsetTop;
		parent=parent.offsetParent;
	};
	return y;
};

function getH(obj){
	return document.getElementById(obj).offsetHeight;
};

function getW(obj){
	return document.getElementById(obj).offsetWidth;
};

function setH(obj, len){
    document.getElementById(obj).style.height=len;
};

function setW(obj, wid){
    document.getElementById(obj).style.width=wid;
};

function setBC(obj,c){
	document.getElementById(obj).style.backgroundColor=c;
};

function move(obj,x,y){
    document.getElementById(obj).style.left=x;
    document.getElementById(obj).style.top=y;
};

function showObj(obj){
    document.getElementById(obj).style.visibility="visible";
};

function hideObj(obj){
    document.getElementById(obj).style.visibility="hidden";
};

function setNode(menuRoot,n,w,h){
	if(menuRoot.MSHADOW) setW(n.sID, w+2+iconWidth);
	if(menuRoot.MBORDER) setW(n.bID, w+2+iconWidth);
	setW(n.nID, w);
	if(menuRoot.ARROW) setW(n.wID, iconWidth);
	if(menuRoot.MSHADOW) setH(n.sID, h+2);
	if(menuRoot.MBORDER) setH(n.bID, h+2);
	setH(n.nID, h);
	if(menuRoot.ARROW) setH(n.wID, h);
};

function moveNode(menuRoot,n,l,t,w){
	if(menuRoot.MSHADOW) move(n.sID, l+2, t+2);
	if(menuRoot.MBORDER) move(n.bID, l, t);
	move(n.nID, l+1, t+1);
	if(menuRoot.ARROW) move(n.wID, l+w+1, t+1);
};

function showNode(n){
	var menuRoot=findRoot(n);
	if(menuRoot.MSHADOW) showObj(n.sID);
	if(menuRoot.MBORDER) showObj(n.bID);
	showObj(n.nID);
	if(menuRoot.ARROW) showObj(n.wID);
};

function hideNode(n){
	var menuRoot=findRoot(n);
	if(menuRoot.MSHADOW) hideObj(n.sID);
	if(menuRoot.MBORDER) hideObj(n.bID);
	hideObj(n.nID);
	if(menuRoot.ARROW) hideObj(n.wID);
};

function findRoot(obj){
	var r=obj.parentObj;
	while(r.level!=0) r=r.parentObj;
	return r;
};

function drawNode(obj){
	var menuRoot=findRoot(obj);
	var docW="";
	var j="node"+obj.id+"_";
	obj.nID=j+"n";
	if(menuRoot.MSHADOW) obj.sID=j+"s";
	if(menuRoot.MBORDER) obj.bID=j+"b";
	if(menuRoot.ARROW) obj.wID=j+"w";
	var e=" onmouseover='mEvent(\""+obj.id+"\",\"o\");' onmouseout='mEvent(\""+obj.id+"\",\"t\");' ";
	if (obj.level<=1){
		if(menuRoot.MSHADOW)docW+="<div id='"+j+"s' style='position:absolute;z-index:"+(obj.level*110+1)+";visibility:hidden;background-color:"+menuRoot.C_Shadow+";'></div>";
		if(menuRoot.MBORDER)docW+="<div id='"+j+"b' style='position:absolute;z-index:"+(obj.level*110+2)+";visibility:hidden;background-color:"+menuRoot.C_Border+";' "+e+"onclick='window.open(\""+obj.link+"\",\"_top\");return false;'></div>";
		docW+="<div id='"+j+"n' style='position:absolute;z-index:"+(obj.level*110+3)+";visibility:hidden;background-color:"+menuRoot.C_Background+";'"+e+"onclick='window.open(\""+obj.link+"\",\"_top\");return false;' nowrap>";
	}else{
		if(menuRoot.MSHADOW)docW+="<div id='"+j+"s' style='position:absolute;z-index:"+(obj.level*110+1)+";visibility:hidden;background-color:"+menuRoot.C_Shadow+";'></div>";
		if(menuRoot.MBORDER)docW+="<div id='"+j+"b' style='position:absolute;z-index:"+(obj.level*110+2)+";visibility:hidden;background-color:#000000;'"+e+"onclick='window.open(\""+obj.link+"\",\"_top\");return false;'></div>";
		docW+="<div id='"+j+"n' style='position:absolute;z-index:"+(obj.level*110+3)+";visibility:hidden;background-color:"+menuRoot.C_subMenuBackground+";'"+e+"onclick='window.open(\""+obj.link+"\",\"_top\");return false;' nowrap>";
	}	
	docW+="&nbsp;<A ";
	docW+="style=\"text-decoration:none;\"";
	docW+=" href=\""+obj.link+"\">";
	if (obj.level<=1){
		docW+="<font color="+menuRoot.C_Font+" id='"+j+"mm'>";
	}else{
		docW+="<font color="+menuRoot.C_subMenuFont+" id='"+j+"sm'>";
	}
	docW+=obj.desc;
	docW+="</font></A>&nbsp;";
	var imgg="<img id='"+j+"w_img' name='"+j+"w_img' width=12 height=12 src="+ICONPATH;
    if(obj.nChildren>0){
		if(menuRoot.LAYOUT==0&&obj.level==1){
				imgg+=activeImg;obj.activeImg=ICONPATH+activeImg;obj.hiddenImg=ICONPATH+hiddenImg;
		}else{
				imgg+=hiddenImg;obj.activeImg=ICONPATH+hiddenImg;obj.hiddenImg=ICONPATH+activeImg;
		}
	}else{
        imgg+=noImg;
        obj.activeImg=ICONPATH+noImg;
        obj.hiddenImg=ICONPATH+noImg;
	}
	imgg+=" border=0>";
	docW+="</div>";
	if(menuRoot.ARROW){
		if (obj.level<=1){
			docW+="<div id='"+j+"w' style='position:absolute;z-index:"+(obj.level*110+3)+";visibility:hidden;background-color:"+menuRoot.C_Background+";' "+e+"onclick='window.open(\""+obj.link+"\",\"_top\");return false;' align=center>"+imgg+"</div>";
		}else{
			docW+="<div id='"+j+"w' style='position:absolute;z-index:"+(obj.level*110+3)+";visibility:hidden;background-color:"+menuRoot.C_subMenuBackground+";' "+e+"onclick='window.open(\""+obj.link+"\",\"_top\");return false;' align=center>"+imgg+"</div>";
		}
	}
	//if(document.getElementById("mainDDM")){
	//    document.getElementById("mainDDM").innerHTML = document.getElementById("mainDDM").innerHTML+docW;
	//}else{
	    document.write(docW);
	//}
};

function generateCode(node){
	drawNode(node);
	for(var i=0;i<node.nChildren;i++) generateCode(node.children[i]);
};

function displayAll(menuRoot){
   if(document.getElementById("BEGIN"+menuRoot.id)){
    	var ll=getL("BEGIN"+menuRoot.id);
    	var tt=getT("BEGIN"+menuRoot.id);
    	if((delaytimer++)<10&&(ll<=0||tt<=0)){
    	    displayAll(menuRoot);
    	}else{
    		menuRoot.cLeft=ll+1;
    		menuRoot.cTop=tt-1;
    		if(menuRoot.LAYOUT==0){
    			for(var i=0;i<menuRoot.nChildren;i++){
    				var obj=menuRoot.children[i];
    				var w=getW(obj.nID);
    				var h=getH(obj.nID);
    				setNode(menuRoot,obj,w,h);
    				moveNode(menuRoot,obj,ll,menuRoot.cTop,w);
    				obj.cTop=h+1+menuRoot.cTop;
    				obj.cLeft=ll;
    				ll+=w+1+iconWidth;
    				moveAll(menuRoot,obj);
    			}
    		}else moveAll(menuRoot,menuRoot);
    		for(i=0;i<menuRoot.nChildren;i++)showNode(menuRoot.children[i]);
    		menuRoot.visibleNodes[menuRoot.nvNodes++]=menuRoot.id;
    	}
	}//else{
	   // alert("error: could not find element BEGIN"+menuRoot.id)
	//}
};

function moveAll(menuRoot,node){
	var wid=0;
	for(var i=0;i<node.nChildren;i++){
		var w=getW(node.children[i].nID);
		if(wid<w) wid=w;
	}
	var hh=node.cTop;
	for(i=0;i<node.nChildren;i++){
    	var obj=node.children[i];
    	var h=getH(obj.nID);
    	setNode(menuRoot,obj,wid,h);
    	moveNode(menuRoot,obj,node.cLeft-20,hh,wid);
	    //obj.cTop=hh+3;
	    obj.cTop=hh+10;
	    //obj.cLeft=node.cLeft+iconWidth+wid-3;
        //SUB MENU OFFSET
        obj.cLeft=node.cLeft+iconWidth+50-wid//-150;
    	hh+=h+menuRoot.SEPARATOR;
	}
	for(i=0;i<node.nChildren;i++) moveAll(menuRoot,node.children[i]);
};

function initializeDocument(menuRoot){
	var docW="";
	docW+="<span id='BEGIN"+menuRoot.id+"' style='visibility:hidden;z-index:0;'>&nbsp;</span>"+"<span style='visibility:hidden;z-index:0;' nowrap>";
	var totalUniqueNodes = 0;
	for(i=0;i<menuRoot.nChildren;i++){
		if(docW.indexOf(menuRoot.children[i].desc)==-1){
		    totalUniqueNodes++;
			//do not create node if it already exists
			//this fixes the bug of when a page is submitted to itself, and you end up with double menus.
			docW+="<span style='position:relative;visibility:hidden;' nowrap>&nbsp;"+menuRoot.children[i].desc+"&nbsp;<img src='"+ICONPATH+activeImg+"' width="+(iconWidth+menuRoot.MBORDER)+" border=0 height=1></span>";
			if(menuRoot.LAYOUT!=0&&i!=(menuRoot.nChildren-1)) docW+="<br>";
		} else {
			menuRoot.nChildren=totalUniqueNodes;
		}
	}
	docW+="</span>";
	//if(document.getElementById("mainDDM")){
	    //document.getElementById("mainDDM").innerHTML = docW;
	//}else{
      document.write("<div style='position:absolute;top:75px;left:0px;background-color:transparent;width:100%;height:23px;' class='normalText'>");
	    document.write(docW);
      document.write("</div>");
	//}
	
	for(i=0;i<menuRoot.nChildren;i++)generateCode(menuRoot.children[i]);
	displayAll(menuRoot);	
};

checkBrowser();

//--------------------------------------------------

