var speed = 10;
var timeout = 30;
var maxHeightMenu = 234;
var maxHeightRelpad = 65;
var timeoutId = -2;
var animTimeout = 0;
var oldClass = new Array();
var currentMenuId = -1;

function menuInit () {
	objMenu = document.getElementById('balkmenu');
	
	maxHeightMenu   = objMenu.offsetHeight;

	if (home!=true) {
		// 1) hoogte van relatief pad en menu zetten
		objMenu.style.height= "1px";
		
		objRelpad = document.getElementById('balkrelpad');
		maxHeightRelpad = objRelpad.offsetHeight;
		

		// 2) selecteren items in relatief pad
		objAs = document.getElementById('relpad').getElementsByTagName("A");
		
		
		if (objAs.length>1) {
			// als meer dan een pagina is gevonden, deze items selecteren (blokje ervoor zetten)
	     		for (i=1;i<objAs.length;i++) {
				menuSelect( parseInt(objAs.item(i).id.substr(1)) );
			} 
		} 
	} else {
		menuSelect(-1);	// op homepage (-1) het homepage blokje selecteren
		objOpvul = document.getElementById('opvulondermenu');
		objOpvul.style.height = (47+maxHeightMenu)+"px";
	}
}

// selecteren en openklappen van de vaste items (deel van init)
function menuSelect(id) {
	objLI = getLI(id);
	
	if (objLI) {	
		objLI.className = "block";
		oldClass75053 = "block";
		objUL = getParentUL(objLI);
		if (objUL!=0) {	
			currentMenuId = id;
		}
	}
}

// Highlight functie (zoek _o afbeelding voor mouseover/out effect)
// ------------------------------------------------------------------
function highlight (id) {
    obj = document.getElementById(id);
    if ( obj.src.substr(obj.src.length-6).toLowerCase() == "_o.gif" ) {
        obj.src = obj.src.substr(0,obj.src.length-6) + ".gif"
    } else {
        obj.src = obj.src.substr(0,obj.src.length-4) + "_o.gif"    
    }
}
// mouse over voor menu items
function menuOver (id) {
	// if (id==currentMenuId) return;

	if (currentMenuId!=0) {
		currentMenuLI = getLI(currentMenuId)
		currentMenuUL = getParentUL(currentMenuLI);
		currentMenuLI.className= oldClass[currentMenuId];		
		if (currentMenuUL!=0) {			
			currentMenuUL.style.visibility  = "hidden";
			currentMenuUL.style.display  = "none";
		}
	}
			
	objLI = getLI(id);	
	objUL = getParentUL(objLI);
	
	
	oldClass75053 = objLI.className;
	if (objUL!=0) {	
		objLI.className = "arrow";	
		objUL.style.visibility = "visible";
		objUL.style.display = "block";
		currentMenuId = id;
	} else {
		objLI.className = "block";	
	}
}

// mouse out voor menu items
function menuOut (id) {
	objLI = getLI(id);	
	if (objLI.className!='arrow') objLI.className = oldClass75053;
}

// hulpfunctie zoeken naar een LI
function getLI(id) {
	objLI = document.getElementById('m'+id);
	return (objLI);
}

// hulpfunctie voor zoeken naar onderliggende UL
function getParentUL(objLi) {
	objULs = objLi.getElementsByTagName("UL");

	if (objULs.length>0) {
		objUL = objULs[0];		
		return(objUL);
	} else {
		return(0);
	}
}




// Openklappen van de menu div (en verbergen relpad)
function menuOpen() {
	// window.status = "menuOpen" 
	menuTimedAnimate(-1,'balkrelpad',maxHeightRelpad);
}

function menuStayOpen () {
	// window.status = "menuStayopen" 
	if (timeoutId!=-2) menuTimedAnimate(1,'balkmenu',maxHeightMenu);
}

function menuClose () {
	// window.status = "menuClose";
	if (timeoutId==0) {
		// window.status = "menuCloset";
		timeoutId = window.setTimeout ("menuTimedAnimate(-1,'balkmenu',999999999)",500);
		// menuTimedAnimate(-1,'balkmenu',999999999)
	}
}

function menuTimedAnimate(dir,id,maxheight) {
	window.clearTimeout(animTimeout);
	window.clearTimeout(timeoutId);
	obj = document.getElementById(id);
	h = parseInt(obj.style.height.replace("px",""));
	if (isNaN(h)) h = obj.offsetHeight;

	if (isNaN(h))
	{
		if (id=='balkrelpad')
		{
			h = maxHeightRelpad;
		}
		else
		{
			h = 10;
		}
	}

	h = h + (dir * speed);

	// alert(h);
	// window.status = "menuTimedAnimate("+dir+","+id+","+maxheight+"); h="+h;
	// alert ("menuTimedAnimate("+dir+","+id+","+maxheight+"); h="+h+ " style.height = " + obj.style.height );
	
	
	if (h>0 && h<=maxheight) {
		obj.style.height = h +"px" ; 
		animTimeout  = window.setTimeout ("menuTimedAnimate("+dir+",'"+id+"',"+maxheight+")",timeout);
	} else {
		if (dir==-1) {
			obj.style.height = 1 ; 
			if (id=='balkrelpad') {
				animTimeout  = window.setTimeout ("menuTimedAnimate(1,'balkmenu',maxHeightMenu);",timeout);
				document.getElementById('balkmenu').style.visibility = 'visible';
				document.getElementById('balkrelpad').style.visibility = 'hidden';
				menuOver(currentMenuId);
			}
			if (id=='balkmenu') {
				animTimeout  = window.setTimeout ("menuTimedAnimate(1,'balkrelpad',maxHeightRelpad);",timeout);
				document.getElementById('balkrelpad').style.visibility = 'visible';
				document.getElementById('balkmenu').style.visibility = 'hidden';
			}
		} else {
			if (id=='balkrelpad') { 
				document.getElementById('balkmenu').style.visibility = 'hidden';
				obj.style.height = maxHeightRelpad+"px";
				timeoutId = -2;
			}
			if (id=='balkmenu') { 
				document.getElementById('balkrelpad').style.visibility = 'hidden';
				obj.style.height = maxHeightMenu+"px";
				timeoutId = 0;
			}
		}
	}
}

function initDivs() {

            try {
                        objMenuLink = document.getElementById('openmenulink');
                            addEvent(objMenuLink, 'click', menuOpen);
            }
            catch(e) {}

            try {
                        objMenuBalk = document.getElementById('balkmenu');
                        addEvent(objMenuBalk, 'mouseout', menuClose);
                        addEvent(objMenuBalk, 'mouseover', menuStayOpen);
             }
            catch(e) {}

            try {
                        objMenu = document.getElementById('mainmenu');
              for(x in objMenu.childNodes) {
                if (objMenu.childNodes[x].tagName=='LI') {
                                      el = objMenu.childNodes[x];
                                      s=String(el.id);
                                                addEvent(el, 'mouseout', new Function("menuOut("+s.substring(s.length,1)+");menuStayOpen();"));
                                                addEvent(el, 'mouseover', new Function("menuOver("+s.substring(s.length,1)+");menuStayOpen();"));
                                    }
                        }
            }

            catch(e) {}

}