	menuAction = false;

	//timer to correcly place the body background (fix for XP theme)
	setInterval("rePositionBackground()", 100);

	function findXpos(obj){
		var curleft = 0;
		if (obj.offsetParent){
		
			while (obj.offsetParent){
			
				curleft += obj.offsetLeft;
				obj = obj.offsetParent;
			}

		}else if (obj.x){

			curleft += obj.x;
		}

		return curleft;
	}

	function findYpos(obj){
		var curtop = 0;		
		if (obj.offsetParent){

			while (obj.offsetParent){

				curtop += obj.offsetTop;
				obj = obj.offsetParent;
			}

		}else if (obj.y){

			curtop += obj.y;
		}

		return curtop;
	}

	function rePositionBackground(){
		
		if(document.getElementById("footer")){

			originX = findXpos(document.getElementById("footer"));
			var x = originX - 1;
			document.getElementById("pagebody").style.backgroundPosition = (x + "px 0px");	
		}
	}

	function reShapePage() {
		
		if(document.getElementById("footer")){

			navbottom = document.getElementById("navbottom");
			footer_div = document.getElementById("footer");
			page_div = document.getElementById("page");

			footerY = findYpos(footer_div);		
			navEnd = parseFloat(navbottom.value);	
			
			rePositionBackground();

			if(footerY < navEnd){
				
				footer_div.style.margin = (0 + "px auto");
				footer_div.style.marginTop = (-30 + "px");
				page_div.style.height = ((navEnd + 55) + "px");
			}	
		}
	}

	function MenuEnding(id){
		
		navbottom = document.getElementById("navbottom");
		theSubMenuBottom = document.getElementById("navend_" + id);
		
		if(document.getElementById("navend_" + id)){

			bottom = findYpos(theSubMenuBottom)+ theSubMenuBottom.offsetHeight;
				
			if(bottom > navbottom.value){
				
				navbottom.value = bottom;
			}
		}
		//window.alert(id + "=" + (Ypos + height));
	}

	function openMenu(newPath){	

		navpath = document.getElementById("navpath");
		navaction = document.getElementById("navaction");	

		//verwijder menubottom en vraag opnieuw op van hoofdmenu
		document.getElementById("navbottom").value = 0;
		MenuEnding(0);
		
		if(menuAction){
			clearTimeout(menuAction);
		}
		
		//menupath dat nu open is
		oldPath = navpath.value;
		
		closeItems(oldPath,newPath);		
		openItems(oldPath,newPath);
		reShapePage();

		navpath.value = newPath;
		navaction.value = "open";

		menuAction = setTimeout("isOpen()",1000);
	}

	function closeMenu(){

		navaction = document.getElementById("navaction");		
		navaction.value = "close";
		
		reShapePage();
	}

	function isOpen(){

		navaction = document.getElementById("navaction");	
		
		//indien laaste menuaction en sluitopdracht is
		if(navaction.value == "close"){
			
			oldPath = document.getElementById("navpath").value;

			//openMenu("0#0");
			closeItems(oldPath,"0#0")

			//verwijder menubottom en vraag opnieuw op van hoofdmenu
			document.getElementById("navbottom").value = 0;
			MenuEnding(0);
		}
	}

	function openItems(oldPath,newPath){

		//maak array			
		itemString = newPath;
		itemArray = itemString.split("|");

		i = 0
		while(i < itemArray.length){

			varString = itemArray[i];
			varArray = varString.split("#");

			parent_id = varArray[0];
			id = varArray[1];

			//alleen weergeven indien layer bestaat en nog niet zichtbaar
			if((document.getElementById("nav_" + id))&&(document.getElementById("nav_" + id).style.display != "")){				
				
				backFrame = document.getElementById('naviframe_' + id);
				theSubMenu = document.getElementById("nav_" + id);

				theSubMenu.style.display = "";
				theSubMenu.style.visibility = "visible";	
				
				if(backFrame.style.width){
					//werkt niet in Firefox
					backFrame.style.width = theSubMenu.offsetWidth;
					backFrame.style.height = theSubMenu.offsetHeight;
				}

				backFrame.width = theSubMenu.offsetWidth;
				backFrame.height = theSubMenu.offsetHeight;
				backFrame.style.zIndex = theSubMenu.style.zIndex - 1;
				backFrame.style.display = "";
				backFrame.style.visibility = "visible";	
				//window.alert(theSubMenu.style.zIndex);
			}
			
			//geef bottom van menu door indien geopend
			if((document.getElementById("nav_" + id))&&(document.getElementById("nav_" + id).style.display == "")){

				//geef einde van menu door
				MenuEnding(id);
			}

			//alleen indien deze bestaat
			if(document.getElementById("navitem_" + id)){

				theClass = document.getElementById("navitem_" + id);

				if((theClass.className == menu_class1)||(theClass.className == menu_class2)){
						
					var useClass = menu_class2;

				}else{
					
					var useClass = submenu_class2;
				}

				theClass.className = useClass;
			}

			//alleen indien deze bestaat
			if(document.getElementById("navitem_" + parent_id)){
				
				theClass = document.getElementById("navitem_" + parent_id);

				if((theClass.className == menu_class1)||(theClass.className == menu_class2)){
					
					var useClass = menu_class2;

				}else{
					
					var useClass = submenu_class2;
				}

				theClass.className = useClass;
			}

			i++;
		}
	}

	function closeItems(oldPath,newPath){

		//maak array			
		itemString = oldPath;
		itemArray = itemString.split("|");

		i = 0
		while(i < itemArray.length){
			
			varString = itemArray[i];
			varArray = varString.split("#");
			
			parent_id = varArray[0];
			id = varArray[1];

			pathPart = parent_id + "#" + id;
			matchPart = "|" + newPath + "|";
			matchRegExp = new RegExp("/\|" + pathPart + "\|/");

			//alleen sluiten indien item niet in het nieuwe navpath weergeven moet worden
			if(!matchPart.match(matchRegExp)){				
				
				//alleen submenu verbergen indien deze bestaat
				if(document.getElementById('nav_' + id)){	
					
					document.getElementById('nav_' + id).style.display = "none";
					document.getElementById('nav_' + id).style.visibility = "hidden";
					document.getElementById('naviframe_' + id).style.display = "none";
				}
			
				//alleen indien deze bestaat
				if(document.getElementById('navitem_' + id)){	
					
					///if(typeof(navPath[id]) == 'undefined'){
		
						theClass = document.getElementById("navitem_" + id);						

						if((theClass.className == menu_class1)||(theClass.className == menu_class2)){
							
							var useClass = menu_class1;

						}else{
							
							var useClass = submenu_class1;
						}

						theClass.className = useClass;
					//}
				}

				//alleen indien deze bestaat
				if(document.getElementById('navitem_' + parent_id)){

					//if(typeof(navPath[parent_id]) == 'undefined'){
					
						theClass = document.getElementById("navitem_" + parent_id);
						
						if((theClass.className == menu_class1)||(theClass.className == menu_class2)){
							
							var useClass = menu_class1;

						}else{
							
							var useClass = submenu_class1;
						}

						theClass.className = useClass;
					//}
				}
			}
			i++;
		}
	}
