var hidePanels;
var debugPanel;
		
function updateDebugInfo(){
	var mainContentContainer = document.getElementById("mainContentContainer");
	debugPanel.innerHTML = 'Window w: ' + document.body.clientWidth + '<br />'
						 + 'Window h: ' + document.body.clientHeight + '<br />'
						 + 'Content h: ' + mainContentContainer.style.height + '<br />'
						 + 'Content scroll h: ' + mainContentContainer.scrollHeight;
					 		;
}

function pageLoad() {
	debugPanel = document.getElementById('debugPanel');
	placeMap();			
	buildPage();
	photoOnLoad();
	nieuwsOnLoad();
	linksOnLoad();
}
		
function buildPage(){
	var mainContentContainer = document.getElementById("mainContentContainer");
	mainContentContainer.style.width = document.body.clientWidth - 440 + 'px';
	mainContentContainer.style.height = document.body.clientHeight - 20 + 'px';
	mainContentContainer.style.overflow = 'hidden';
	
	try{		
		mainContentContainer.childNodes[0].style.position = 'relative';
		mainContentContainer.childNodes[0].style.zIndex = 2;
		mainContentContainer.childNodes[0].style.position = 'relative';
		mainContentContainer.childNodes[1].style.zIndex = 1;
	}catch(err){
	}	
	updateDebugInfo();
}

function windowHeight(){
	var alto= 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		alto= window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		alto= document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		alto= document.body.clientHeight;
	}

	return alto;
}

function create_random(){
	var random_number = Math.floor(Math.random() * 999999) + 1;
	return random_number;
}

function handle_overlay(state){
	
	/* Verwijder eerst de eventueel aanwezige overlay */
	var overlay_container = document.getElementById('overlay_container');
	if(overlay_container != null){
		document.body.removeChild(overlay_container);
	}

	if(state){
		/* Plaatse overlay */
		var overlay_container = document.createElement('div');
		overlay_container.setAttribute('id','overlay_container');
		overlay_container.style.position = 'absolute';
		overlay_container.style.top = '0px';
		overlay_container.style.left = '0px';
		overlay_container.style.width = '100%';
		overlay_container.style.height = windowHeight() + 'px';
		overlay_container.style.zIndex = 1000;
		document.body.appendChild(overlay_container);
		
		overlay_container.innerHTML = '<div id="overlay_shade" style="Filter:Alpha(opacity=75); -moz-opacity:0.7;"></div>';
		var overlay_shade = document.getElementById('overlay_shade');
		overlay_shade.setAttribute('onclick','handle_overlay(false);');
		overlay_shade.style.backgroundColor = '#006699';
		overlay_shade.style.top = '0px';
		overlay_shade.style.left = '0px';
		overlay_shade.style.width = '100%';
		overlay_shade.style.height = windowHeight() + 'px';
		overlay_shade.style.zIndex = 1000;
		
		var overlay_content = document.createElement('div');
		overlay_content.setAttribute('id', 'overlay_content');
		overlay_content.style.position = 'absolute';
		overlay_content.style.top = '0px';
		overlay_content.style.left = '0px';
		overlay_content.zIndex = 1002;
		
		overlay_container.appendChild(overlay_content);
		
		return overlay_content;
	}else{
		return true;
	}
}

function centerContent(content){
	var leftMargin = content.offsetWidth / 2 - content.offsetWidth + 'px';
	var topMargin = content.offsetHeight / 2 - content.offsetHeight + 'px';

	content.style.marginLeft = leftMargin;
	content.style.marginTop = topMargin; 
	
	content.style.left = '50%';
	content.style.top = '50%';
 	
 	return true;
}

function prepareArticle(articleID){
	if(document.getElementById(articleID)) return false;
	
	var articleParent		= document.getElementById('main_scroll');
	var article				= document.createElement('div');
	var articleTools		= document.createElement('div');
	var articleTitle		= document.createElement('div');
	var articleBody			= document.createElement('div');
	
	articleTools.className = 'articleTools';
	articleTools.id = articleID + '_tools';
	articleTools.innerHTML = 'Sluiten';
	if(articleTools.addEventListener){
		articleTools.addEventListener('click', function(){closeArticle(this)}, true);
	}else{
		articleTools.attachEvent('onclick', function(){closeNamedArticle(articleID)});
	}
	article.appendChild(articleTools);
	
	articleTitle.className = 'articleTitle';
	articleTitle.id = articleID + '_title';
	articleTitle.innerHTML = 'Title';
	if(articleTitle.addEventListener){
		articleTitle.addEventListener('click', function(){toggleRollUp(this);}, true);
	}else{
		articleTitle.attachEvent('onclick', function(){toggleNamedRollUp(articleTitle.id)});
	}
	article.appendChild(articleTitle);
	
	articleBody.className = 'articleBody';
	articleBody.id = articleID + '_body';
	articleBody.innerHTML = 'Content';
	article.appendChild(articleBody);
	
	article.id = articleID;
	article.className = 'article';
	articleParent.appendChild(article);

}

/* XML Tools =====================*/

function getNextSibling(startBrother){
	var endBrother = startBrother.nextSibling;
	while(endBrother.nodeType!=1){
		endBrother = endBrother.nextSibling;
	}
	return endBrother;
}

function getInnerText (node) {
	if (typeof node.textContent != 'undefined') {
		return node.textContent;
	}else if (typeof node.innerText != 'undefined') {
		return node.innerText;
	}else if (typeof node.text != 'undefined') {
		return node.text;
	}else {
		switch (node.nodeType) {
		case 3:
		case 4:
			return node.nodeValue;
		break;
		case 1:
		case 11:
			var innerText = '';
			for (var i = 0; i < node.childNodes.length; i++) {
				innerText += getInnerText(node.childNodes[i]);
			}
			return innerText;
		break;
		default:
		return '';
		}
	}
}
/* Einde XML Tools ===============*/

/* Content Loader ================*/
var net = new Object();
net.READY_STATE_UNINITIALIZED = 0;
net.READY_STATE_LOADING = 1;
net.READY_STATE_LOADED = 2;
net.READY_STATE_INTERACTIVE = 3;
net.READY_STATE_COMPLETE = 4;

net.ContentLoader = function(url, onload, onerror){
	this.url = url;
	this.req = null;
	this.onload = onload;
	this.onerror = (onerror) ? onerror : this.defaultError;
	this.loadXMLDoc(url);
}

net.ContentLoader.prototype = {
	loadXMLDoc:function(url){
		if(window.XMLHttpRequest){
			this.req = new XMLHttpRequest();
		}else if(window.ActiveXObject){
			this.req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		if(this.req){
			try{
				var loader = this;
				this.req.onreadystatechange = function(){
					loader.onReadyState.call(loader);
				}
				this.req.open('GET', url, true);
				this.req.send(null);
			}catch(err){
				this.onerror.call(this);
			}
		}
	},
	
	onReadyState:function(){
		var req = this.req;
		var ready = req.readyState;
		if(ready == net.READY_STATE_COMPLETE){
			var httpStatus = req.status;
			if(httpStatus == 200 || httpStatus == 0){
				this.onload.call(this);
			}else{
				this.onerror.call(this);
			}
		}
	},
	
	defaultError:function(){
		alert("error fetching data!"
			+ "\n\nreadyState: " + this.req.readyState
			+ "\nstatus: " + this.req.status
			+  "\nheader: " + this.req.getAllResponseHeaders()
			);
	}
}
/* ===============================*/
