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();

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.opacity = x;
		return(true);
	}
	if(getDOMObject(id).style.MozOpacity != null){
		getDOMObject(id).style.MozOpacity = 0.01 * x;
		return(true);
    }
	if(getDOMObject(id).style.opacity){
		getDOMObject(id).style.opacity = 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 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 currentWidth, currentHeight, width, height, additional;
		if(window.innerWidth){
			var currentWidth = window.innerWidth;
			var currentHeight = window.innerHeight;
		}else{
			var currentWidth = document.body.offsetWidth;
			var currentHeight = document.body.offsetHeight;
		}
		if(document.getElementById('IE7SizingLayer')){
			currentHeight = document.getElementById('IE7SizingLayer').offsetHeight;
		}
		additional = 0;
		additional += ((navigator.appName.indexOf("Internet Explorer") != -1) && (navigator.userAgent.indexOf("Opera") == -1)) ? -4 : 0;
		if(this.stretchX){
			width = currentWidth - (this.l + this.r) + additional;
			getDOMObject(this.id).style.width = width.toString() + "px";
		}
		if(this.stretchY){
			height = currentHeight - (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 menuLink(parentObject, btnDOMId, acol, ncol){
	this.btnId = btnDOMId;
	this.parentMenu = parentObject;
	this.activeButtonColor = (acol != "") ? acol : this.parentMenu.activeButtonColor;
	this.normalButtonColor = (ncol != "") ? ncol : this.parentMenu.normalButtonColor;

	getDOMObject(this.btnId).style.color = this.normalButtonColor;
  
	this.mouseOver = function(){
		try{
			getDOMObject(this.btnId).style.color = this.activeButtonColor;
			this.parentMenu.collapseChildren();
		}catch(e){}
	}
  
	this.mouseOut = function(){
		try{
			getDOMObject(this.btnId).style.color = this.normalButtonColor;
		}catch(e){}
	}
	
	this.click = function(){
		try{
			pageExit();
		}catch(e){}
	}
  
	this.addEvents = function(x){
		eval("function " + this.btnId + "OnHandler(){ x.mouseOver(); }");
		eval("getDOMObject(this.btnId).onmouseover = function(){ " + this.btnId + "OnHandler(); };");
		eval("function " + this.btnId + "OffHandler(){ x.mouseOut(); }");
		eval("getDOMObject(this.btnId).onmouseout = function(){ " + this.btnId + "OffHandler(); };");
		eval("function " + this.btnId + "ClickHandler(){ x.click(); }");
		eval("getDOMObject(this.btnId).onclick = function(){ " + this.btnId + "ClickHandler(); };");
	}

	this.addEvents(this);
}
  
  
function menuItem(parentObject, baseId, posId, acol, ncol){
	this.btnId = baseId + "Btn";
	this.layerId = baseId + "Layer";
	this.tableId = baseId + "Table";
	this.positionerId = posId;
	this.parentMenu = parentObject;
	this.subMenuArray = new Array();
	this.subMenuCounter = 0;
//  this.menuLinkArray = new Array();
//  this.menuLinkCounter = 0;
	this.isExpanded = false;
	this.activeButtonColor = (acol != "") ? acol : this.parentMenu.activeButtonColor;
	this.normalButtonColor = (ncol != "") ? ncol : this.parentMenu.normalButtonColor;
	this.expandedZ = this.parentMenu.expandedZ;
	this.collapsedZ = this.parentMenu.collapsedZ;
	this.fadeId = 0;
	this.isTopLevel = false;
  
	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)) ? -2 : 0;
	totalLeft = getDOMX(this.layerId) + getDOMX(this.positionerId) + this.addLeft;
	getDOMObject(this.layerId).style.left = totalLeft + "px";
	totalTop = getDOMY(this.layerId) + getDOMY(this.positionerId)+ this.addTop;
	getDOMObject(this.layerId).style.top = totalTop + "px"; 
  
	getDOMObject(this.btnId).style.color = this.normalButtonColor;
	if(!this.parentMenu.isTopLevel){
		getDOMObject(this.btnId).style.cursor = "default";
	}
	this.click = function(e){
		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.addMenu = function(menuObject){
		this.subMenuArray[this.subMenuCounter] = menuObject;
		this.subMenuCounter += 1;
	}
  
	this.expand = function(){
		cancelFade(this.fadeId);
		this.parentMenu.collapseChildren();
		getDOMObject(this.layerId).style.zIndex = this.expandedZ;
		setOpacity(this.layerId, 100);
		getDOMObject(this.layerId).style.visibility = "visible";
//   volgende regels bugfix voor Mozilla 1.6  
//    getDOMObject("superLayer").style.visibility = "visible";
//    getDOMObject("superLayer").style.visibility = "hidden";

//		getDOMObject(this.layerId).style.left = getDOMX(this.layerId) + getDOMX(this.positionerId) + this.addLeft;
//		getDOMObject(this.layerId).style.top = getDOMY(this.layerId) + getDOMY(this.positionerId)+ this.addTop; 


		this.isExpanded = true;
		this.setMenusExpanded();
	}
  
	this.collapseChildren = function(){
		if(this.subMenuCounter > 0){
			for(var i=0; i<this.subMenuCounter; i++){
				this.subMenuArray[i].collapse();
			}
		}
	}
  
	this.collapse = function(){
		if(this.isExpanded){
			this.collapseChildren();
			getDOMObject(this.layerId).style.zIndex = this.collapsedZ;
			this.cancelFade = false;
			this.isExpanded = false;
			getDOMObject(this.btnId).style.color = this.normalButtonColor;
			this.fadeId = getNewFadeId();
			fadeOut(this.layerId, 100, 10, this.fadeId);
		}
	}
  
	this.collapseAll = function(){
		this.parentMenu.collapseAll();
	}

	this.mouseOver = function(){
		try{
			getDOMObject(this.btnId).style.color = this.activeButtonColor;
			if(this.parentMenu.menusExpanded() && ! this.isExpanded){
				this.expand();
			}
		}catch(e){}
	}
  
	this.mouseOut = function(){
		if(!this.isExpanded){
			getDOMObject(this.btnId).style.color = this.normalButtonColor;
		}
	}
  
	this.setMenusExpanded = function(){
		this.parentMenu.setMenusExpanded();
	}
  
	this.menusExpanded = function(){
		return(this.parentMenu.menusExpanded());
	}
  
	this.addEvents = function(x){
		eval("function " + this.btnId + "OnHandler(){ x.mouseOver(); }");
		eval("getDOMObject(this.btnId).onmouseover = function(){ " + this.btnId + "OnHandler(); };");
		eval("function " + this.btnId + "OffHandler(){ x.mouseOut(); }");
		eval("getDOMObject(this.btnId).onmouseout = function(){ " + this.btnId + "OffHandler(); };");
		eval("function " + this.btnId + "ClickHandler(event){ x.click(event); }");
		eval("getDOMObject(this.btnId).onclick = function(event){ " + this.btnId + "ClickHandler(event); };");
	}
  
	this.addEvents(this);  
}

function globalMenuHandler(activeColor, normalColor, ez, cz){
	this.menuCounter = 0;
	this.menuArray = new Array();
	this.menusAreExpanded = false;
	this.activeButtonColor = (activeColor != "") ? activeColor : "#ff0000";
	this.normalButtonColor = (normalColor != "") ? normalColor : "#000000";
	this.expandedZ = ez;
	this.collapsedZ = cz;
	this.isTopLevel = true;

	this.addMenu = function(menu){
		this.menuArray[this.menuCounter] = menu;
		this.menuCounter += 1;
	}
  
	this.collapseChildren = function(){
		for(var i=0; i<this.menuCounter; i++){
			this.menuArray[i].collapse();
		}
		this.setMenusCollapsed();
	}
  
	this.collapseAll = function(){
		this.collapseChildren();
	}
	
	this.setMenusExpanded = function(){
		this.menusAreExpanded = true;
	}
  
	this.setMenusCollapsed = function(){
		this.menusAreExpanded = false;
	}
  
	this.menusExpanded = function(){
		return(this.menusAreExpanded);
	}
  
	this.addToEventList = function(x){
//		var oldHandler = window.onfocus;
		var oldHandler = document.onclick;
		function newHandler(){
			x.collapseAll();
		}
		if(oldHandler){
//			window.onfocus = function(){ oldHandler(); newHandler(); };
			document.onclick = function(){ oldHandler(); newHandler(); };
		}else{
//			window.onfocus = function(){ newHandler(); };
			document.onclick = function(){ newHandler(); };
		}
	}
	if(!debugMode){this.addToEventList(this);}
}

function blinkButton(DomId, cp, onUrl, offUrl){
	this.id = DomId;
	this.isCurrentPage = cp;
	this.actUrl = onUrl;
	this.norUrl = offUrl;
	this.width = getDOMObject(this.id).width;
	this.height = getDOMObject(this.id).height;
	this.blinkOn = new Image(this.width, this.height);
	this.blinkOn.src = this.actUrl;
	this.blinkOff = new Image(this.width, this.height);
	this.blinkOff.src = this.norUrl;

	this.activate = function(){
		if(!this.isCurrentPage){
			getDOMObject(this.id).src = this.blinkOn.src;
		}
	}

	this.deactivate = function(){
		if(!this.isCurrentPage){
			getDOMObject(this.id).src = this.blinkOff.src;
		}
	}

	this.setCurrent = function(){
		this.isCurrentPage = true;
	}

	this.addEvents = function(x){
		eval("function " + this.id + "OnHandler(){ x.activate(); }");
		eval("getDOMObject(this.id).onmouseover = function(){ " + this.id + "OnHandler(); };");
		eval("function " + this.id + "OffHandler(){ x.deactivate(); }");
		eval("getDOMObject(this.id).onmouseout = function(){ " + this.id + "OffHandler(); };");
		eval("function " + this.id + "ClickHandler(){ x.setCurrent(); }");
		eval("getDOMObject(this.id).onclick = function(){ " + this.id + "ClickHandler(); };");
	}

	this.addEvents(this);
		if(this.isCurrentPage){
		getDOMObject(this.id).src = this.blinkOn.src;
	}
}

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 pageExit(){
//	fadeOut("innerText", 100, 5, getNewFadeId());
}

function lead(i){
	if(i < 10){
		return(0 + i.toString());
	}
	return(i.toString());
}

function writeClock(){
	var d = new Date();
	var s = days[d.getDay()] + ", " + d.getDate() + " " + months[d.getMonth()] + " " + d.getFullYear();
	s += ", " + d.getHours() + ":" + lead(d.getMinutes()) + ":" + lead(d.getSeconds());
	cct = "clock" + clockTopLayer;
	clockTopLayer = clockTopLayer == 1 ? 2 : 1;
	oct = "clock" + clockTopLayer;
	getDOMObject(cct).innerHTML = s;
	getDOMObject(cct).style.zIndex = 20;
	getDOMObject(oct).style.zIndex = 21;
	getDOMObject(cct).style.visibility = "visible";
	fadeOut(oct, 100, 20, clockFadeId);
}

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

function init(ba, ab){
	var x = new stretchDiv("bgImg", 100, 0, 71, 0);
	var y = new stretchDiv("textLayer", 100, 0, 100, 0);
	var grey1 = new stretchDiv("botGreyBar", -1, 0, -1, 0);
	var grey2 = new stretchDiv("topGreyBar", -1, 0, -1, 0);
	var green = new stretchDiv("bottomGreenBar", -1, 0, -1, 0);
	window.setInterval("writeClock()", 1000);
	if(navigator.userAgent.indexOf("Gecko") != -1){
//		getDOMObject("menuTopLayer").style.top = "76px";
	}
	if((navigator.appName.indexOf("Internet Explorer") != -1) && (navigator.userAgent.indexOf("Opera") == -1) && (navigator.userAgent.indexOf("NT 5.1") != -1)){
//		getDOMObject("menuTopLayer").style.top = "79px";
	}
	var menuHandler = menuInit();
	setOnClickCursors();
	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(53.144675, 6.361264);
			var center = point; //new GLatLng(52.985300, 5.914300);
			map.setCenter(center, 13);
			map.addOverlay(new GMarker(point));
		}	
	}
}
