function valign()
{
	var divId = 'maincontainer';

	var IE = window.attachEvent && !window.opera ? true : false;

	var IE7 = window.XMLHttpRequest && window.attachEvent && !window.opera ? true : false;

	if(IE && document.body.style.position != 'absolute')
	{
		document.body.style.position = 'absolute';
		document.body.style.height = '100%';
	}

	var windowSize = new Object();
	windowSize.height = !IE ? window.innerHeight : document.body.clientHeight;
	windowSize.width = !IE ? window.innerWidth : document.body.clientWidth;

	var div = document.getElementById(divId);

	var divSize = new Object();
	divSize.height = div.offsetHeight;
	divSize.width = div.offsetWidth;

	var marginTop = windowSize.height >= divSize.height ? Math.abs((windowSize.height/2)-(divSize.height/2)) : 0;
	var marginLeft = windowSize.width >= divSize.width ? Math.abs((windowSize.width/2)-(divSize.width/2)) : 0;

	div.style.marginTop = marginTop+'px';
	if(IE)
	{
		div.style.marginLeft = marginLeft+'px';
	}
}

// check useragent
function checkBrowserName(name){
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf(name.toLowerCase())>-1) {
		return true;
	}
	return false;
}

// only if useragent is not an MSIE then center the container
if(checkBrowserName('MSIE') == false){
	if (window.addEventListener){
		window.addEventListener("load", valign, false);
		window.addEventListener("resize", valign, false);
	}else if (window.attachEvent){
		window.attachEvent("onload", valign);
		window.attachEvent("onresize", valign);
	}
}