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 inited = false;
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 mozile;

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.opacity = x;
		return(true);
	}else if(getDOMObject(id).style.opacity != null){
		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 fadeIn(layer, x, step, fadeId){
	if(x == 0){
		setOpacity(layer, 0);
		getDOMObject(layer).style.visibility = "visible";
	}
	if(fades[fadeId]){
		if((!(x > 100)) && setOpacity(layer, x)){
			x += step;
			window.setTimeout("fadeIn(\"" + layer + "\", " + x + ", " + step + ", " + fadeId + ")", 40);
		}else{
			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 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];
		try{
			if(img.onclick){
				img.style.cursor = "pointer";
			}
		}catch(e){}
	}
}

function init(){
	if(!inited){
		inited = true;
		docInit();
		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(52.942468, 5.923260);
				var center = new GLatLng(52.956859, 5.925137);
				map.setCenter(center, 13);
				map.addOverlay(new GMarker(point));
			}	
		}
		
		try{
			if(mozile){
				mozile.setSaveOption("custom", "url", document.location.href);
				mozile.setSaveOption("custom", "content", "editor");
				window.setTimeout(window.stop, 4000);
			}
		}catch(e){}// MSIE zuigt!
	}
}

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


