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 mozile, mozileInterface;

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){
		try{
			zoomWindow.close();
		}catch(e){}
	}
	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.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 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 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 && 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 setOnClickCursors(){
	for(var i=0; i<document.images.length; i++){
		var img = document.images[i];
		if(img.onclick){
			img.style.cursor = "pointer";
		}
	}
}

function embedMediaPlayer(id, width, height, autoPlay, splashImageFile){
	var placeHolder = "mediaPlaceHolder" + id;
	getDOMObject(placeHolder).innerHTML = "Loading media player";
	var fo = new SWFObject("/flash/FlowPlayerDark.swf", "flowPlayer", width, height, "7", "#ffffff", true);
	fo.addParam("allowScriptAccess", "always");
	fo.addParam("allowFullScreen", "true");
	autoPlay = autoPlay ? "true" : "false";
	splashImageFile = splashImageFile != null ? ", splashImageFile: '" + splashImageFile + "'" : "";
	fo.addVariable("config", "{ autoPlay: " + autoPlay + ", autoBuffering: " + autoPlay + ", loop: false, autoRewind: true, countryCode: 'en', playList: [ {overlayId: 'play' }, { url: '/streammedia.php?id=" + id + "' } ], initialScale: 'fit',  fullScreenScriptURL: '/js/fullscreen.js'" + splashImageFile + " }");

	fo.write(placeHolder);
}

function init(ba, ab){
	docInit();
	setOnClickCursors();
}

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

