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;

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.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 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, btnDOMId, layerDOMId, posId, acol, ncol){
	this.btnId = btnDOMId;
	this.layerId = layerDOMId;
	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 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/FlowPlayerLP.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();
}

