addLoadEvent(init);
addLoadEvent(scaleIt);

function init()
{
	window.onresize = scaleIt;	
}

function scaleIt()
{
	var contentElem = getElm("main");
	contentElem.style.height = "auto";
	var contentHeight = meetHoogte(contentElem);
	var vpHeight = viewPortSize("height");
	var compensatieHeight = 40;	// De footer en header
	var contentYpos = findPos(contentElem)[1];
	var newContentHeight = vpHeight - contentYpos - compensatieHeight;
	if (newContentHeight > contentHeight)
	{
		contentElem.style.height = newContentHeight+"px";
	}
	else
	{
		return false;
	}
}

// Basic functions
function getElm(id)
{
	if (document.getElementById(id))
	{
		return document.getElementById(id);
	}
	else
	{
		return false;
	}
}

function findPos(obj,refObj)
{
	// Vind de absolute positie van een object.
	var curleft = curtop = 0;
	var startX;
	var startY;
	
	if (refObj)
	{
		startX = findPos(refObj)[0];
		startY = findPos(refObj)[1];
	}
	else
	{
		startX = 0;
		startY = 0;
	}
		
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft-startX,curtop-startY];
}

function meetHoogte(elm)
{
	return elm.offsetHeight;
}

function meetBreedte(elm)
{
	return elm.offsetWidth;
}

function setHoogte(elm,height)
{
	elm.style.height = height+"px";
}

function viewPortSize(dimension)
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	if (dimension == "width") return myWidth;
	if (dimension == "height") return myHeight;
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	} else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}
