/*
 * Menu
 */

if (!document.getElementById)
    document.getElementById = function() { return null; }
		
function initializeMenu() {
currentMenuId = getCookie("lcrMenuItem");
currentActuatorId = getCookie("lcrMenu");
var menuList = document.getElementById("menuList");
		// volgorde van elementen is in verschillende browsers verschillend
	for( var x = 0;x < menuList.childNodes.length; x++ ){
		if (menuList.childNodes[x].className == "menuBar") {		
			var menuBar = menuList.childNodes[x];
			for( var y = 0;y < menuBar.childNodes.length; y++ ){
				if (menuBar.childNodes[y].className == "actuator") {		
					var actuator = menuBar.childNodes[y];
						if (actuator.id == currentActuatorId) {
							actuator.style.background = "#536887";
						}
						actuator.onclick = function() {
							toonMenu(this.id);
						}
				}
				if (menuBar.childNodes[y].className == "menuItems") {		
					var menu = menuBar.childNodes[y];
					for( var z = 0;z < menu.childNodes.length; z++ ){
						if (menu.childNodes[z].childNodes[0]) {	
							if (menu.childNodes[z].childNodes[0].className == "menuItem") {		
							var menuItem = menu.childNodes[z].childNodes[0];
								if (menuItem.id == currentMenuId) {
									menuItem.style.background = "#536887";
								}
								menuItem.onclick = function() {
														doMenuItem(this.id);
								}
							}
						}
					}
				}
			}
		}
	}
}
function doMenuItem(currentMenuId) {
	setCookie("lcrMenuItem", currentMenuId);
}
function toonMenu(currentActuatorId) {
	var menuList = document.getElementById("menuList");
	for( var x = 0;x < menuList.childNodes.length; x++ ){
		if (menuList.childNodes[x].className == "menuBar") {
			var menuBar = menuList.childNodes[x];
			for( var y = 0;y < menuBar.childNodes.length; y++ ){
				if (menuBar.childNodes[y].className == "actuator") {		
					var actuator = menuBar.childNodes[y];
				}
				if (!(actuator == null)) {
						 setCookie("lcrMenu", currentActuatorId);
				}
				if (menuBar.childNodes[y].className == "menuItems") {		
					var menu = menuBar.childNodes[y];
				}
				if (!(menu == null)) {
					if (currentActuatorId == actuator.id) {
						var display = menu.style.display;
						menu.style.display = (display == "block") ? "none" : "block";
					} else {
						menu.style.display = "none" ;
					}
						// variabelen zijn niet lokaal binnen een loop
					menu = actuator = null;
				}
			}
		}
	}
}
// Cookies

function getCookie(cookieName)
{
	if (document.cookie.length>0){
	  cookieStart=document.cookie.indexOf(cookieName + "=");
	  if (cookieStart!=-1){ 
		cookieStart=cookieStart + cookieName.length+1 ;
		cookieEnd=document.cookie.indexOf(";",cookieStart);
			if (cookieEnd==-1) cookieEnd=document.cookie.length
				return unescape(document.cookie.substring(cookieStart,cookieEnd));
			} 
	  }
}

function setCookie(cookieName,value,expireDays)
{
	var expireDate=new Date();
	expireDate.setTime(expireDate.getTime()+(expireDays*24*3600*1000));
		// path is nodig anders komen er meerdere cookies met verschillend pad
	document.cookie=cookieName + "=" +escape(value) + ((expireDays==null) ? "" : "; expires="+expireDate) + "; path=/"
}

// Resize iFrame

function resizeFrame(iFrame) {
	if (iFrame.contentDocument && iFrame.contentDocument.body.offsetHeight) {
			// ns, Ff, Opera + 20 is nodig voor FireFox
		iFrame.height = iFrame.contentDocument.body.offsetHeight+20; 
	} else if (iFrame.Document && iFrame.Document.body.scrollHeight) {
		// ie syntax
		iFrame.height = iFrame.Document.body.scrollHeight;
	}
}
