var oTarget = document;
// addLoadEvent(collapseMenu);
addLoadEvent(prepareMenu);

function collapseMenu(node) {
	if (!document.getElementById) return false;
	if (!document.getElementById("menu")) return false;
	if (!node) node = document.getElementById("menu");

	if (node.childNodes.length > 0) {
		for (var i=0; i<node.childNodes.length; i++) {
			var child = node.childNodes[i];
			if (child.nodeName == "UL") {
				if (i!=0) child.style.display = "none"; // **** de if stond er niet
			}
			collapseMenu(child);
		}
	}
}

function prepareMenu() {
	if (!document.getElementById || !document.getElementsByTagName) return false;
	if (!document.getElementById("menu")) return false;

	var links = document.getElementById("menu").getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {		
		links[i].onclick = function() {
			toggleMenu(this.parentNode.getElementsByTagName("UL")[0], this);
			return false;
		}
	}
}

function toggleMenu(node, link) {
	if (!document.getElementById) return false;
	if (!link) return false;
	if (node){
		if (node.parentNode.parentNode.id == "menu") {
			hideTopLevels();
		}
		
		if (node.style.display == "") {
			Effect.BlindUp(node, {duration: 0.5});
		} else {
			Effect.BlindDown(node, {duration: 0.5});
		}
		if (link.href!="#") setTimeout("oTarget.location.href = '" + link.href + "';", 500);
	} else {
		oTarget.location.href = link.href;
	}
}

function hideTopLevels() {
	if (!document.getElementById) return false;
	if (!(node = document.getElementById("menu"))) return false;	
	
	if (node.childNodes.length > 0) {
		for (var i=0; i<node.childNodes.length; i++) {
			var child = node.childNodes[i];
			for(var j=0; j<child.childNodes.length; j++) {
				var grandchild = child.childNodes[j];
				if (grandchild.nodeName == "UL") {
					if (grandchild.style.display == '') {
						Effect.BlindUp(grandchild, {duration: 0.2});
					}
				}
			}
		}		
	}
}

function retard(href){
	alert(href);
	return false;	
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') { 
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}