var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && ! document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;
var isIE5Mac = (navigator.userAgent.indexOf("Mac") != -1 && isIE5);
var debugMode = false;
var deb = new scriptDebugger();
var fades = new Array();
var fadeCounter = 0;
var zoomWindow;
var days = new Array("Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag");
var months = new Array("januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december");
var clockTopLayer = 1;
var clockFadeId = getNewFadeId();
var mozileInterface;
var MSIEFixLoaded;
var inited = false;

if(!window.Node){
	var Node = {
		ELEMENT_NODE: 1,
		ATTRIBUTE_NODE: 2,
		TEXT_NODE: 3,
		COMMENT_NODE: 8,
		DOCUMENT_NODE: 9,
		DOCUMENT_FRAGMENT_NODE: 11
	}
}

function getDOMObject(str){
  if (document.all){
    return(document.all[str]);
  }else if (document.getElementById) {
    return(document.getElementById(str));
  }
}

function cmsZoom(i, iw, ih, title){
	var lx, ly, options;
	window.focus();
	if (zoomWindow != null){
		zoomWindow.close();
	}
	lX = parseInt((window.screen.width - (iw + 8)) / 2); 
	lY = parseInt((window.screen.height - (ih + 27))/2);
	options = "innerwidth=" + iw + ", innerheight=" + ih+", width = " + iw + ", height = " + ih
	options += ", left = " + lX + ", top = " + lY + "resizable=no, scrollbars=no, toolbar=no, menubar=no, statusbar=no";
	zoomWindow = window.open("/cms/zoomimage.php?id=" + i + "&title=" + title, "zoomWindow", options);
}

function noOp(){
}

function writeEmail(name, machine){
	document.write("<a href=:\"mailto:" + name + "@" + machine + "\">");
	document.write(name + "@" + machine + "</a>");
}

function printVersion(page){
	this.printWindow = window.open(page + "?print=true", "printWindow", "width=800,height=600,status=no,resizable=yes,scrollbars=yes");
}

function showFullScreen(page){
	options = "width="+(window.screen.width-8)+",height="+(window.screen.height-26)+",resizable=no,left=0,top=0,scrollbars=no, alwaysRaise=yes, fullScreen=yes";
	fsWindow = window.open(page,"fsWindow",options);
}

function setOpacity(id, x){
	if(getDOMObject(id).filters && getDOMObject(id).filters.alpha){
		getDOMObject(id).filters.alpha.opacity = x;
		return(true);
	}else if(getDOMObject(id).style.MozOpacity != null){
		getDOMObject(id).style.MozOpacity = 0.01 * x;
		return(true)
    }
	return(false);
}

function getNewFadeId(){
	fadeCounter += 1;
	fades[fadeCounter] = true;
	return(fadeCounter);
}

function cancelFade(id){
	fades[id] = false;
}

function fadeOut(layer, x, step, fadeId){
	if(fades[fadeId]){
		if(!(x < 0) && setOpacity(layer, x)){
			x -= step;
			window.setTimeout("fadeOut(\"" + layer + "\", " + x + ", " + step + ", " + fadeId + ")", 40);
		}else{
			setOpacity(layer, 0);
			getDOMObject(layer).style.visibility = "hidden";
			setOpacity(layer, 100);
		}
	}
}

function getDOMX(id){
	var x = 0;
	if(getDOMObject(id)){
	// nn4up ---------------
		if (isNS4){
			if ( getDOMObject(id) != window )			x = getDOMObject(id).pageX;
		}
	// gk, iemac, iewin ---------------
		else{
			currentX = 0;
			if ( getDOMObject(id).offsetParent ){
				object = getDOMObject(id);
				while ( object.offsetParent ){
					currentX += object.offsetLeft;
					object = object.offsetParent;
				}
			}else if ( getDOMObject(id).x ){
				currentX += getDOMObject(id).x;
			}
			x = currentX;
			if (isIE5Mac){
				x += parseInt( "0" + document.body.currentStyle.marginLeft, 10  );
			}
		}
	}
	return x;
}

function getDOMY(id){
	var x = 0;
	if(getDOMObject(id)){
	// nn4up ---------------
		if (isNS4){
			if ( getDOMObject(id) != window )			x = getDOMObject(id).pageY;
		}
	// gk, iemac, iewin ---------------
		else{
			currentX = 0;
			if ( getDOMObject(id).offsetParent ){
				object = getDOMObject(id);
				var IECorrection = 0;
				while ( object.offsetParent ){
					currentX += object.offsetTop;
					object = object.offsetParent;
				}
			}else if ( getDOMObject(id).y ){
				currentX += getDOMObject(id).y;
			}
			x = currentX;
			if ( isIE5Mac){
				x += parseInt( "0" + document.body.currentStyle.marginLeft, 10  );
			}
		}
	}
	return x;
}

function getWindowHeight(){
	if(window.innerHeight){
		return(window.innerHeight);
	}else{
		if(document.documentElement.clientHeight){
			return(document.documentElement.clientHeight);
		}else{
			return(document.body.offsetHeight);
		}
	}
}

function getWindowWidth(){
	if(window.innerWidth){
		return(window.innerWidth);
	}else{
		if(document.documentElement.clientWidth){
			return(document.documentElement.clientWidth);
		}else{
			return(width = document.body.offsetWidth);
		}
	}
}

function scriptDebugger(){
  this.anchorIndex = 0;
  if(debugMode){
    this.debugWindow = window.open("", "debugWindow", "width=400,height=350,status=no,resizable=yes,scrollbars=yes");
	  this.debugWindow.document.write("<html><body>\n");
	}
	
	this.alert = function(str){
	  if(debugMode){
	    this.anchorIndex++;
		  this.debugWindow.document.write("<a name=\"" + this.anchorIndex + "\"></a>" + str + "<br>\n");
			this.debugWindow.scrollTo(0, 10000);
		}
	}
	
	this.evtAlert = function(str){
	  if(debugMode){
	    this.anchorIndex++;
	    this.debugWindow.document.write("<a name=\"" + this.anchorIndex + "\"></a><font color=\"#ff0000\">" + str + "</font><br>\n");
			this.debugWindow.scrollTo(0, 10000);
		}
	}
}

function StretchDiv(DomId, top, right, bottom, left){
	this.id = DomId;
	this.t = top;
	this.r = right;
	this.b = bottom;
	this.l = left;
  	this.stretchX = !(left < 0 || right < 0);
	this.stretchY = !(top < 0 || bottom < 0);
	this.showId = function(){
		alert(this.id);
	}
 
	this.setMargins = function(top, right, bottom, left){
		this.t = top;
		this.r = right;
		this.b = bottom;
		this.l = left;
		this.stretchX = !(left == "" || right == "");
		this.stretchY = !(top == "" || bottom == "");
		if(getDOMObject(this.id).style.left){
			getDOMObject(this.id).style.left = left.toString() + "px";
		}else{
			getDOMObject(this.id).style.right = right.toString() + "px";
		}
		if(getDOMObject(this.id).style.top){
			getDOMObject(this.id).style.top = top.toString() + "px";
		}else{
			getDOMObject(this.id).style.bottom = bottom.toString() + "px";
		}
		this.stretch();
	}

	this.stretch = function(){
		var width, height, additional;
		additional = 0;
		additional += ((navigator.appVersion.indexOf("MSIE") != -1) && (navigator.appVersion.indexOf("MSIE 8") == -1)) ? -4 : 0;
		if(this.stretchX){
			width = getWindowWidth() - (this.l + this.r) + additional;
			getDOMObject(this.id).style.width = width.toString() + "px";
		}
		if(this.stretchY){
			height = getWindowHeight() - (this.t + this.b) + additional;
			getDOMObject(this.id).style.height = height.toString() + "px";
		}
		return(true);
	}

	this.addToEventList = function(x){
		var oldHandler = window.onresize;
		function newHandler(){
			x.stretch();
		}
		if(oldHandler){
			window.onresize = function(){ oldHandler(); newHandler(); };
		}else{
			window.onresize = function(){ newHandler(); };
		}
	}
  
	this.addToEventList(this);
	this.stretch();
}

function Menu(id, topNormalClass, topHoverClass, expZ, collZ, menuNormalClass, menuHoverClass, disabledClass){
//	this.childCounter = 0;
	this.id = id;
	this.children = new Array();
	this.childCounter = 0;
	this.menusAreExpanded = false;
	this.normalClass = topNormalClass;
	this.hoverClass = topHoverClass;
	this.childNormalClass = menuNormalClass;
	this.childHoverClass = menuHoverClass;
	this.disabledClass = disabledClass;
	this.expandedZ = expZ;
	this.collapsedZ = collZ;
	this.isTopLevel = true;
	this.XPos = getDOMX("this.id");
	this.YPos = getDOMY("this.id");
	this.icons = new Array();
	this.arrows = new Array();
	
	this.addChild = function(menuObj){
		deb.alert("top addChild (currentCounter = " + this.childCounter + ")");
		this.children = this.children.concat(menuObj);
//		this.children[this.childCounter] = menuObj;
//		this.childCounter++;
	}
	
	this.getArrow = function(status){
		return(this.arrows[status].src);
	}
	
	this.setArrows = function(normalUrl, hoverUrl){
		this.arrows["normal"] = new Image();
		this.arrows["normal"].src = normalUrl;
		this.arrows["hover"] = new Image();
		this.arrows["hover"].src = hoverUrl;
	}
	
	this.addIcon = function(name, normalURL, hoverURL){
		this.icons[name] = new menuIcon(name, normalURL, hoverURL);
	}
	
	this.getIconImage = function(name, status){
		if(this.icons[name]){
			return(this.icons[name].getImage(status));
		}
		return(null);
	}
	
	this.getTopClass = function(state){
		switch(state){
			case "hover" :
				return(this.hoverClass);
				break;
			default: 
				return(this.normalClass);
				break;
		}
	}

	this.getSubClass = function(state){
		switch(state){
			case "hover" :
				return(this.childHoverClass);
				break;
			case "disabled" :
				return(this.disabledClass);
				break;
			default: 
				return(this.childNormalClass);
				break;
		}
	}

	
	this.getZIndex = function(state){
		switch(state){
			case "expanded" : return(this.expandedZ);
			default : return(this.collapsedZ);
		}
	}
	
	this.collapseChildren = function(){
		deb.alert("top collapseChildren");
		for(var i in this.children){
			this.children[i].collapse();
		}
		this.menusAreExpanded = false;
	}
	
	this.collapseAll = function(){
		this.collapseChildren();
	}

	this.getMenusExpanded = function(){
		deb.alert("top getMenusExpanded");
		deb.alert("&nbsp;&nbsp;menusAreExpanded status = " + this.menusAreExpanded);
		return(this.menusAreExpanded);
	}
	
	this.setMenusExpanded = function(){
		deb.alert("top setMenusExpanded")
		this.menusAreExpanded = true;
		deb.alert("&nbsp;&nbsp;menusAreExpanded status = " + this.menusAreExpanded);
	}
	
	this.getItemById = function(id){
		var x;
		for(var i in this.children){
			x = this.children[i].getItemById(id);
			if(x != null){
				return(x);
			}
		}
		return(null);
	}
	
	this.getItemsByUrl = function(url){
		deb.alert("top getItemsByUrl: getting " + url);
		var items = new Array();
		for(var i in this.children){
			items = items.concat(this.children[i].getItemsByUrl(url));
		}
		return(items);
	}
	
	this.reposition = function(){
		deb.alert("top reposition");
		for(var i in this.children){
			this.children[i].reposition();
		}
	}
	
	this.resize = function(){
		if((getDOMX(this.id) != this.XPos) || (getDOMY(this.id) != this.YPos)){
			this.reposition();
		}
	}
	
	this.addToEventList = function(thisObject){
		var oldClickHandler = document.onclick;
		var oldBlurHandler = document.onblur;
		function newHandler(){
			thisObject.collapseAll();
		}
		if(oldClickHandler){
			document.onclick = function(){oldClickHandler(); newHandler();};
		}else{
			document.onclick = function(){newHandler();};
		}
		if(oldBlurHandler){
			document.onblur = function(){oldBlurHandler(); newHandler();};
		}else{
			document.onblur = function(){newHandler();};
		}
		var oldResizeHandler = window.onresize;
		function newResizeHandler(){
			thisObject.resize();
		}
		if(oldResizeHandler){
			window.onresize = function(){oldResizeHandler(); newResizeHandler();};
		}else{
			window.onresize = function(){newResizeHandler();};
		}
	}
	
	this.addToEventList(this);
}

function menuIcon(name, normalImage, hoverImage){
	this.name = name;
	this.images = new Array();
	
	this.getImage = function(status){
		if(this.images[status] != null){
			return(this.images[status].src);
		}
		return(null)
	}
	
	this.setImage = function(status, imageURL){
		if(this.images[status] == null){
			this.images[status] = new Image();
		}
		this.images[status].src = imageURL;
	}
	
	this.setImage("normal", normalImage);
	this.setImage("hover", hoverImage);
}

function SubMenu(parentMenu, baseId, disabled, id, icon){
	this.type = "subMenu";
	this.baseId = baseId;
	this.layerId = baseId + "Layer";
	this.buttonId = baseId + "Button";
	this.parentMenu = parentMenu;
	this.id = id;
	this.icon = icon;
	this.iconElement = null;
	this.disabled = (disabled == true);
//	if(this.parentMenu.isTopLevel){
//		this.positionerId = baseId + "Button";
//	}else{
		this.positionerId = baseId + "Pos";
//	}
	this.isExpanded = false;
	this.children = new Array();
	this.fadeId = 0;
	this.isTopLevel = false;
	this.parentMenu.addChild(this);
	getDOMObject(this.layerId).style.visibility = "hidden";
	this.additional = 0;
//	this.additional += ((navigator.appName.indexOf("Internet Explorer") != -1) && (navigator.userAgent.indexOf("Opera") == -1)) ? 1 : 0;
//	this.additional += ((navigator.appName.indexOf("Internet Explorer") != -1) && (navigator.userAgent.indexOf("Opera") != -1)) ? -1 : 0;
//	this.additional += ((!this.parentMenu.isTopLevel) && (navigator.appName.indexOf("Internet Explorer") != -1) && (navigator.userAgent.indexOf("Opera") == -1)) ? -3 : 0;
	this.addTop = this.additional;
	this.addLeft = this.additional;
//	addLeft += (this.parentMenu.isTopLevel && (navigator.appName.indexOf("Internet Explorer") != -1) && (navigator.userAgent.indexOf("Opera") == -1)) ? -1 : 0;
//	addLeft += (navigator.userAgent.indexOf("Gecko") != -1 && this.parentMenu.isTopLevel) ? -1 : 0;
//	this.addTop += ((!this.parentMenu.isTopLevel) && (navigator.userAgent.indexOf("Gecko") != -1)) ? -1 : 0;
//	alert(getStyle(this.layerId, "right"));
	this.baseTop = getDOMY(this.layerId) + this.addTop;
	this.baseLeft = getDOMX(this.layerId) + this.addLeft;

	this.position = function(){
		getDOMObject(this.layerId).style.left = (getDOMX(this.positionerId) + this.baseLeft) + "px";
		getDOMObject(this.layerId).style.top = (getDOMY(this.positionerId) + this.baseTop) + "px";
	}
	
	this.reposition = function(){
		deb.alert("sub " + this.id + " reposition");
		this.position();
		for(var i in this.children){
			this.children[i].reposition();
		}
	}
	
	this.click = function(e){
		if(!this.disabled){
			if(this.parentMenu.isTopLevel){
				if(this.isExpanded){
					this.parentMenu.collapseChildren();
				}else{
					this.expand();
				}
			}
		}
		if(!e){
			var e = window.event;
		}
		if(window.event){
			window.event.cancelBubble = true;
		}
		if(e.stopPropagation){
			e.stopPropagation();
		}
		return(false);
	}
	
	this.expand = function(){
		deb.alert("expand");
		cancelFade(this.fadeId);
		this.parentMenu.collapseChildren();
		getDOMObject(this.layerId).style.zIndex = this.getZIndex("expanded");
		setOpacity(this.layerId, 100);
		getDOMObject(this.layerId).style.visibility = "visible";
		this.isExpanded = true;
		this.setMenusExpanded();
		if(MSIEFixLoaded === true){
			fixTableStyleInheritance(getDOMObject(this.buttonId));
		}
	}
	
	this.collapseChildren = function(){
		for(var i in this.children){
			this.children[i].collapse();
		}
	}
	
	this.collapse = function(){
		deb.alert("sub collapse");
		this.collapseChildren();
		if(this.isExpanded){
			getDOMObject(this.layerId).style.zIndex = this.getZIndex("collapsed");
			this.cancelFade = false;
			this.isExpanded = false;
			getDOMObject(this.buttonId).className = this.getClass("normal");
			this.showIcon("normal");
			this.showArrow("normal");
			this.fadeId = getNewFadeId();
			fadeOut(this.layerId, 100, 10, this.fadeId);
		}
		if(MSIEFixLoaded === true){
			fixTableStyleInheritance(getDOMObject(this.buttonId));
		}
	}
	
	this.collapseAll = function(){
		this.parentMenu.collapseAll();
	}
	
	this.setMenusExpanded = function(){
		deb.alert("sub setMenusExpanded");
		this.parentMenu.setMenusExpanded();
	}
	
	this.getMenusExpanded = function(){
		return(this.parentMenu.getMenusExpanded());
	}
	
	this.addChild = function(menuObj){
		this.children = this.children.concat(menuObj);
	}
	
	this.getClass = function(state){
		if(this.parentMenu.isTopLevel){
			return(this.parentMenu.getTopClass(state));
		}
		return(this.parentMenu.getSubClass(state));
	}
	
	this.getSubClass = function(state){
		return(this.parentMenu.getSubClass(state));
	}
	
	this.getZIndex = function(state){
		return(this.parentMenu.getZIndex(state));
	}
	
	this.mouseOver = function(){
		if(!this.disabled && (this.parentMenu.isTopLevel || this.parentMenu.isExpanded)){
			try{
				getDOMObject(this.buttonId).className = this.getClass("hover");
				this.showIcon("hover");
				this.showArrow("hover");
				if(this.parentMenu.getMenusExpanded() && !this.isExpanded){
					this.expand();
				}
			}catch(e){
				deb.alert(e);
			}
		}
		if(MSIEFixLoaded === true){
			fixTableStyleInheritance(getDOMObject(this.buttonId));
		}
	}
	
	this.mouseOut = function(){
		if(!this.isExpanded && !this.disabled){
			getDOMObject(this.buttonId).className = this.getClass("normal");
			this.showIcon("normal");
			this.showArrow("normal");
		}
		if(MSIEFixLoaded === true){
			fixTableStyleInheritance(getDOMObject(this.buttonId));
		}
	}
	
	this.enable = function(){
		getDOMObject(this.buttonId).className = this.getClass("normal");
		this.disabled = false;
	}
	
	this.disable = function(){
		getDOMObject(this.buttonId).className = this.getClass("disabled");
		this.disabled = true;
	}
	
	this.getItemById = function(id){
		deb.alert("sub getItemById comparing: " + id + " to " + this.id);
		var x;
		if(id == this.id){
			return(this);
		}
		for(var i in this.children){
			x = this.children[i].getItemById(id);
			if(x != null){
				return(x);
			}
		}
		return(null);
	}
	
	this.getItemsByUrl = function(url){
		deb.alert("sub getItemsByUrl getting: " + url);
		var x;
		var items = new Array();
		for(var i in this.children){
			x = this.children[i].getItemsByUrl(url);
			if(x != null){
				items = items.concat(x);
			}
		
		}
		return(items);
	}

	this.getText = function(){
		return(getDOMObject(this.baseId + "Text").innerHTML);
	}
	
	this.setText = function(text){
		getDOMObject(this.baseId + "Text").innerHTML = text;
		this.parentMenu.reposition();
	}
	
	this.showIcon = function(status){
		if(this.icon != null){
			if(this.iconElement == null){
				this.iconElement = document.createElement("img");
				this.iconElement.setAttribute("class", "menuIcon");
				this.iconElement.setAttribute("id", this.baseId + "IconImage");
				getDOMObject(this.baseId + "Icon").appendChild(this.iconElement);
			}
			this.iconElement.src = this.getIconImage(this.icon, status);
			this.parentMenu.reposition();	// TODO kijken of dit wel efficient genoeg is of dat iconen gewoon altijd dezelfde grootte moeten hebben
		}
	}
	
	this.setIcon = function(name){
		this.icon = name;
		this.showIcon("normal");
	}
	
	this.removeIcon = function(){
		this.icon = null;
		if(this.iconElement != null){
			getDOMObject(this.baseId + "Icon").removeChild(this.iconElement);
		}
	}
	
	this.getIconImage = function(name, status){
		return(this.parentMenu.getIconImage(name, status));
	}
	
	this.showArrow = function(status){
		var arrow = this.getArrow(status);
		if((getDOMObject(this.positionerId).nodeName.toLowerCase() == "img") && (arrow != null)){
			getDOMObject(this.positionerId).src = arrow;
		}
	}
	
	this.getArrow = function(status){
		return(this.parentMenu.getArrow(status));
	}

	this.addEvents = function(x){
		eval("function " + this.buttonId + "OnHandler(){ x.mouseOver(); }");
		eval("getDOMObject(this.buttonId).onmouseover = function(){ " + this.buttonId + "OnHandler(); };");
		eval("function " + this.buttonId + "OffHandler(){ x.mouseOut(); }");
		eval("getDOMObject(this.buttonId).onmouseout = function(){ " + this.buttonId + "OffHandler(); };");
		eval("function " + this.buttonId + "ClickHandler(event){ x.click(event); }");
		eval("getDOMObject(this.buttonId).onclick = function(event){ " + this.buttonId + "ClickHandler(event); };");
	}

	this.position();
	if(this.disabled){
		getDOMObject(this.buttonId).className = this.getClass("disabled");
	}
	this.showIcon("normal");
	this.addEvents(this);  
}

function MenuLink(parentMenu, baseId, URL, disabled, id, icon){
	this.type = "menuLink";
	this.baseId = baseId;
	this.buttonId = baseId + "Button";
	this.parentMenu = parentMenu;
	this.URL = URL;
	this.id = id;
	this.disabled = (disabled == true);
	this.parentMenu.addChild(this);
	this.icon = icon;
	this.iconElement = null;
	if(getDOMObject(this.baseId + "Href") && getDOMObject(this.baseId + "Href").hasAttribute && getDOMObject(this.baseId + "Href").hasAttribute("href")){
		getDOMObject(this.baseId + "Href").removeAttribute("href");
	}

	this.getClass = function(state){
		if(this.parentMenu.isTopLevel){
			return(this.parentMenu.getTopClass(state));
		}
		return(this.parentMenu.getSubClass(state));
	}
	
	this.getSubClass = function(state){
		return(this.parentMenu.getSubClass(state));
	}
	
	this.collapse = function(){
	}
	
	this.reposition = function(){
	}
	
	this.mouseOver = function(){
		var menusExpanded = this.parentMenu.getMenusExpanded();
		if(!this.disabled && (this.parentMenu.isTopLevel || this.parentMenu.isExpanded)){
			try{
				getDOMObject(this.buttonId).className = this.getClass("hover");
				this.showIcon("hover");
				window.status = this.URL;
				this.parentMenu.collapseChildren();
				if(this.parentMenu.isTopLevel && menusExpanded){
					this.parentMenu.setMenusExpanded();
				}
			}catch(e){}
		}
		if(MSIEFixLoaded === true){
			fixTableStyleInheritance(getDOMObject(this.buttonId));
		}
	}
	
	this.mouseOut = function(){
		if(!this.disabled){
			try{
				getDOMObject(this.buttonId).className = this.getClass("normal");
				this.showIcon("normal");
				window.status = "";
			}catch(e){}
		}
		if(MSIEFixLoaded === true){
			fixTableStyleInheritance(getDOMObject(this.buttonId));
		}
	}
	
	this.click = function(e){
		if(!this.disabled){
			try{
				if(this.URL.substr(0, 11) == "javascript:"){
					eval(this.URL.substr(11));
					getDOMObject(this.buttonId).className = this.getClass("normal");
					this.parentMenu.collapseAll();
				}else{
					document.location.href = this.URL;
				}
				this.showIcon("normal");
				window.status = "";
			}catch(e){}
		}
		if(!e){
			var e = window.event;
		}
		if(window.event){
			window.event.cancelBubble = true;
		}
		if(e.stopPropagation){
			e.stopPropagation();
		}
		return(false);
	}
	
	this.getItemById = function(id){
		deb.alert("link getItemById comparing: " + id + " to " + this.id);
		if(id == this.id){
			return(this);
		}else{
			return(null);
		}
	}
	
	this.getItemsByUrl = function(url){
		deb.alert("link getItemsByUrl comparing " + url + " to " + this.URL);
		if(url == this.URL){
			deb.alert("  returning object");
			return(this);
		}else{
			return(null);
		}
	}
	
	this.enable = function(){
		getDOMObject(this.buttonId).className = this.getClass("normal");
//		getDOMObject(this.baseId + "Href").setAttribute("href", this.URL);
		this.disabled = false;
	}
	
	this.disable = function(){
		getDOMObject(this.buttonId).className = this.getClass("disabled");
//		getDOMObject(this.baseId + "Href").removeAttribute("href");
		this.disabled = true;
	}
	
	this.getText = function(){
		return(getDOMObject(this.baseId + "Text").innerHTML);
	}
	
	this.setText = function(text){
		getDOMObject(this.baseId + "Text").innerHTML = text;
	}
	
	this.showIcon = function(status){
		if(this.icon != null){
			if(this.iconElement == null){
				this.iconElement = document.createElement("img");
				this.iconElement.setAttribute("class", "menuIcon");
				this.iconElement.setAttribute("id", this.baseId + "IconImage");
				getDOMObject(this.baseId + "Icon").appendChild(this.iconElement);
			}
			this.iconElement.src = this.getIconImage(this.icon, status);
		}
	}
	
		
	this.setIcon = function(name){
		this.icon = name;
		this.showIcon("normal");
	}
	
	this.setUrl = function(URL){
		this.URL = URL;
//		getDOMObject(this.baseId + "Href").setAttribute("href", URL);
	}
	
	this.removeIcon = function(){
		this.icon = null;
		if(this.iconElement != null){
			getDOMObject(this.baseId + "Icon").removeChild(this.iconElement);
		}
	}
	
	this.getIconImage = function(name, status){
		return(this.parentMenu.getIconImage(name, status));
	}
	
	this.addEvents = function(x){
		eval("function " + this.buttonId + "OnHandler(){ x.mouseOver(); }");
		eval("getDOMObject(this.buttonId).onmouseover = function(){ " + this.buttonId + "OnHandler(); };");
		eval("function " + this.buttonId + "OffHandler(){ x.mouseOut(); }");
		eval("getDOMObject(this.buttonId).onmouseout = function(){ " + this.buttonId + "OffHandler(); };");
		eval("function " + this.buttonId + "ClickHandler(event){ x.click(event); }");
		eval("getDOMObject(this.buttonId).onclick = function(event){ " + this.buttonId + "ClickHandler(event); };");
	}
	
	if(this.disabled){
		getDOMObject(this.buttonId).className = this.getClass("disabled");
		getDOMObject(this.baseId + "Href").removeAttribute("href");
	}
	this.showIcon("normal");
	this.addEvents(this);
}


function addOnResizeHandler(handler){
	var oldHandler = window.onresize;
	eval("function newHandler(){ " + handler + " };");
	if(oldHandler){
		window.onresize = function(){ oldHandler(); newHandler(); };
	}else{
		window.onresize = function(){ newHandler(); };
	}
}

function addOnClickHandler(domId, handler){
	var oldHandler = getDOMObject(domId).onclick;
	eval("function newHandler(){ " + handler + " };");
	if(oldHandler){
		getDOMObject(domId).onclick = function(){ oldHandler(); newHandler(); };
	}else{
		getDOMObject(domId).onclick = function(){ newHandler(); };
	}
}  

function addOnFocusHandler(domId, handler){
	var oldHandler = getDOMObject(domId).onfocus;
	eval("function newHandler(){ " + handler + " };");
	if(oldHandler){
		getDOMObject(domId).onfocus = function(){ oldHandler(); newHandler(); };
	}else{
		getDOMObject(domId).onfocus = function(){ newHandler(); };
	}
}  

function setOnClickCursors(){
	for(var i=0; i<document.images.length; i++){
		var img = document.images[i];
		if(img.onclick){
			img.style.cursor = "pointer";
		}
	}
}

function selectMultipleMove(name){
	var sourceChildren, i;
	sourceChildren = getDOMObject(name + "Pool").childNodes;
	for(i=0; i < sourceChildren.length; i++){
		option = sourceChildren[i];
		if(option.nodeType == Node.ELEMENT_NODE && option.selected){
			getDOMObject(name + "Selection").appendChild(option);
			option.selected = false;
		}
		
	}
}

function MultipleSelector(id){
	this.id = id;
	this.poolId = id + "Pool";
	this.pool = getDOMObject(this.poolId);
	this.selectionId = id + "Selection";
	this.selection = getDOMObject(this.selectionId);
	this.buttonId = id + "MoveButton";
	this.button = getDOMObject(this.buttonId);
	this.direction = "right";

	
	this.click = function(e){
		var sourceChildren, i, option;
		if(this.direction == "right"){
			sourceChildren = this.pool.childNodes;
			destination = this.selection;
		}else{
			sourceChildren = this.selection.childNodes;
			destination = this.pool;
		}
		for(i=0; i < sourceChildren.length; i++){
			option = sourceChildren[i];
			if(option.nodeType == Node.ELEMENT_NODE && option.selected){
				destination.appendChild(option);
				option.selected = false;
			}
		
		}
	}
	
	this.leftFocus = function(e){
		this.direction = "right";
		this.button.value = "->";
	}
	
	this.rightFocus = function(e){
		this.direction = "left";
		this.button.value = "<-"
	}
	
	this.addEvents = function(x){
		eval("function " + this.id + "ClickHandler(){ x.click(); }");
		eval("this.button.onclick = function(event){ " + this.id + "ClickHandler(event); };");
		eval("function " + this.id + "LeftFocus(){ x.leftFocus(); }");
		eval("this.pool.onfocus = function(event){ " + this.id + "LeftFocus(event); };");
		eval("function " + this.id + "RightFocus(event){ x.rightFocus(); }");
		eval("this.selection.onfocus = function(event){ " + this.id + "RightFocus(event); };");
	}
  
	this.addEvents(this);  

}

function alertItems(){
	var parentDE, children, i, child, cc;
	parentDE = getDOMObject("multiSelect");
	children = parentDE.childNodes;
	for(i=0; i < children.length; i++){
		child = children[i];
		if(child.nodeType == Node.ELEMENT_NODE){
			if(child.selected){
				getDOMObject("yoyo").appendChild(child);
				child.selected = false;
			}
		}
	}
}

function init(){
	if(!inited){
		inited = true;
		setOnClickCursors();
		docInit();
		
		
		if(document.getElementById("googleMap") && mozileInterface == null){
			if (GBrowserIsCompatible()) {
				var map = new GMap2(document.getElementById("googleMap"));
				var geocoder = new GClientGeocoder();
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				var point = new GLatLng(52.942468, 5.923260);
				var center = new GLatLng(52.956859, 5.925137);
				map.setCenter(center, 13);
				map.addOverlay(new GMarker(point));
			}	
		}
		
		if (mozileInterface != null) {

			mozile.setSaveOption("custom", "url", document.location.href);
			mozile.setSaveOption("custom", "content", "editor");
		}
	}
}

window.setTimeout("init();", 2000); // Voor als Mozile roet in het eten gooit