/* --- JavaScript --- */
/* --- uitklapmenu IE5/6 --- */

/* --- Based on Suckerfish Dropdowns (A List Apart): http://www.alistapart.com/articles/dropdowns --- */

var allDropMenus = new Array();	// alle dropdown-menu's (id's) - onMouseOver
var allPullMenus = new Array("pulldownMenu");	// alle pulldown-menu's (id's) - onClick
var allFAQs = new Array();	// alle uitklapbare vraag/antwoord-overzichten

var allDynamicMenus = new Array();

var hoverClass = "jsHover";
var unfoldClass = "unfold";
var currentNode

allOnLoad = function() {
	// alle functies die bij onLoad aangeroepen moeten worden
	initDropMenus();
	initPullMenus();
	initFAQs();
	setFixArray();
}

allOnResize = function() {
	// alle functies die bij onResize aangeroepen moeten worden
	resizeFix();
}

allOnBlur = function() {
	// alle functies die bij onBlur aangeroepen moeten worden
	resizeFix();
}

function initDropMenus() {
	// dropdown-menu's worden dynamisch ingelezen
	for (m=0; m<allDropMenus.length; m++) {
		if (document.all && document.getElementById) {
			navRoot = document.getElementById(allDropMenus[m]);
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName == "LI") {
					node.onmouseover = function() {
						this.className = appendClass(this.className, hoverClass);
					}
					node.onmouseout = function() {
						this.className = restoreClass(this.className, hoverClass);
					}
				}
			}
		}
	}
}

function initPullMenus() {
	// pulldownmenu's worden dynamisch ingelezen
	for (m=0; m<allPullMenus.length; m++) {
		if (document.getElementById) {
			navRoot = document.getElementById(allPullMenus[m]);
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName == "LI") {
					node.onclick = function() {
						if (!this.unfold) {
							this.className = appendClass(this.className, hoverClass);
							this.unfold = true;
						}
						else {
							this.className = restoreClass(this.className, hoverClass);
							this.unfold = false;
						}
					}
					node.onmouseover = function() {
						if (this.timerOn) {
							clearTimeout(this.timeOut);
							this.timeOut = null;
							this.timerOn = false;
						}
						if (this.unfold) {
							this.className = appendClass(this.className, hoverClass);
						}
					}
					node.onmouseout = function() {
						currentNode = this;
						this.timeOut = setTimeout('currentNode.className = restoreClass(currentNode.className, hoverClass)', 100);
						this.timerOn = true;
						this.unfold = false;
					}
					node.onblur = function() {
						currentNode = this;
						this.timeOut = setTimeout('currentNode.className = restoreClass(currentNode.className, hoverClass)', 100);
						this.timerOn = true;
						this.unfold = false;
					}
				}
			}
		}
	}
}

function appendClass(nodeClass, addClass) {
	// voeg class toe aan className van node
	return nodeClass + " " + addClass;
}

function restoreClass(nodeClass, deleteClass) {
	// verwijder class uit className van node
	if (nodeClass.length == deleteClass.length) {
		return nodeClass.replace(deleteClass, "");
	}
	else {
		return nodeClass.replace(" " + deleteClass, "");
	}
}

function initFAQs() {
	// FAQ's worden dynamisch ingelezen
	for (m=0; m<allFAQs.length; m++) {
		if (document.getElementById) {
			navRoot = document.getElementById(allFAQs[m]);
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName == "LI") {
					node.className = restoreClass(node.className, unfoldClass);
					node.onclick = function() {
						if (!this.unfold) {
							this.className = appendClass(this.className, unfoldClass);
							this.unfold = true;
						}
						else {
							this.className = restoreClass(this.className, hoverClass);
							this.className = restoreClass(this.className, unfoldClass);
							this.unfold = false;
						}
					}
					node.onmouseover = function() {
						this.className = appendClass(this.className, hoverClass);
					}
					node.onmouseout = function() {
						this.className = restoreClass(this.className, hoverClass);
					}
				}
			}
		}
	}
}

function setFixArray() {
	// maakt allDynamicMenus gereed voor gebruik in resizeFix()
	for (d=0; d<allDropMenus.length; d++) {
		allDynamicMenus[allDynamicMenus.length] = allDropMenus[d];
	}
	for (p=0; p<allPullMenus.length; p++) {
		allDynamicMenus[allDynamicMenus.length] = allPullMenus[p];
	}
	for (f=0; p<allFAQs.length; f++) {
		allDynamicMenus[allDynamicMenus.length] = allFAQs[f];
	}
}

function resizeFix() {
	// fix voor resize-bug
	for (m=0; m<allDynamicMenus.length; m++) {
		if (document.all && document.getElementById) {
			navRoot = document.getElementById(allDynamicMenus[m]);
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName == "LI") {
					node.className = restoreClass(node.className,hoverClass);
					node.className = appendClass(node.className, hoverClass);
					node.className = restoreClass(node.className,hoverClass);
					return false;
				}
			}
		}
	}
}

/* --- functie-aanroep --- */
//window.onload = allOnLoad;
//window.onresize = allOnResize;
//window.onblur = allOnBlur;

Event.observe(window, 'resize', allOnResize);
Event.observe(window, 'blur', allOnBlur);
