// JavaScript Document
//if(window.addEventListener){
//	window.addEventListener('load', startSite);
//	window.addEventListener('resize', resizeSite);
//} else {
	window.onload = startSite;
	window.onresize = resizeSite;
//}
	
function startSite () {
		
	resizeSite();
//	resizeWindow();
	
}

function getWindowDimension (innerOuter) {
	
	if (window.innerWidth)
		return [window.innerWidth, window.innerHeight];

	if (document.body.clientWidth)
		return [document.body.clientWidth, document.body.clientHeight];
	
}

function getScrollHeight (element) {
	
	if (element.scrollHeight)
		return element.scrollHeight;

}

function getContentDimensions (element) {
	
	if (document.defaultView){
		var stringWidth = document.defaultView.getComputedStyle(element, "").getPropertyValue("width");
		var stringHeight = document.defaultView.getComputedStyle(element, "").getPropertyValue("height");
		var arrayWidth = stringWidth.split('px');
		var arrayHeight = stringHeight.split('px');
		return [arrayWidth[0], arrayHeight[0]];
	} else if (element.clientWidth)
		return [element.clientWidth, element.clientHeight];	
		
}

function setDivHeight (element, height) {
	element.style.height = height+'px';
}

function setDivPaddingRight (element, padding) {
	element.style.paddingRight = padding+'px';
}

function resizeSite () {

	var margin = 242;
	var marginNews = 272;
	var minContentHeigt = 420;
	var content = document.getElementById('contentBlock');
	var wrapper = document.getElementById('wrapper');
	var nieuws = document.getElementById('nieuws');
	var windowDimension = getWindowDimension();
	var scrollHeight = getScrollHeight(content);

	if (windowDimension[1] > (minContentHeigt+margin)) {
		if ((scrollHeight + margin) > windowDimension[1]) {
			setDivHeight(content, (windowDimension[1] - margin));
			setDivHeight(nieuws, windowDimension[1] - marginNews);
			setDivHeight(wrapper, windowDimension[1]);
			setDivPaddingRight(content, 5);
		} else if ((scrollHeight + margin) <= windowDimension[1]) {
			setDivHeight(content, scrollHeight);
			setDivHeight(wrapper, (scrollHeight + margin));
			setDivPaddingRight(content, 21);
		}
	}
	else {
		setDivHeight(content, minContentHeigt);
		setDivHeight(wrapper, (minContentHeigt + margin));
		setDivPaddingRight(content, 5);
	}

}

function resizeWindow () {
	
	var minWidth = 1024;
	var newWidth;
	var windowDimensions = getWindowDimension();
	
	if (windowDimensions[0] >= minWidth)
		newWidth = windowDimensions[0];
	else
		newWidth = minWidth;
		
	var newOffsetWidth = Math.abs(newWidth - document.body.clientWidth);
	var newOffsetHeight = Math.abs(getScrollHeight(document.body) - document.body.clientHeight)
	
	//this trick is for firefox only. When the window is maximized, changing the window dimensions provokes strange behaviour
	//when the property isnt recognized by a browser or the value is higher then zero when maximized, the window will be updated still, as long this doesn't
	//provike strange behaviour there is no problem
	if(window.screenY <= 0)
		return
	else
		window.resizeBy(newOffsetWidth, newOffsetHeight);
	
}