var pageWidth = pageHeight = backgroundOffsetX = backgroundOffsetY = 0;
var gecko = navigator.userAgent.indexOf('Gecko')>0;

window.onload = window.onresize = function() {
    setPageSize();
    positionBackground();
}

function positionBackground() {
//	document.body.style.width  = pageWidth;
//	document.body.style.height = pageHeight;
	var pos = findPos(document.getElementById('mainContent'));

	if(gecko && (backgroundOffsetX == 'center') && (pos[0]>3)){ return; }

	backgroundOffsetX = (pos[0] - 114) + 'px';
	backgroundOffsetY = (pos[1] - 62 ) + 'px';
	if(gecko && (pos[0]>3)){ backgroundOffsetX = 'center'; }
	document.body.style.backgroundPosition = backgroundOffsetX + ' ' + backgroundOffsetY;
//	document.body.style.backgroundPositionY = backgroundOffsetY;
//	alert("1:" + pageWidth + "...2:" + pageHeight);
}

function setPageSize(){
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		setPageSize = function(){
			pageWidth  = window.innerWidth;
			pageHeight = window.innerHeight;
		}
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		setPageSize = function(){
			pageWidth  = document.documentElement.clientWidth;
			pageHeight = document.documentElement.clientHeight;
		}
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		setPageSize = function(){
			pageWidth  = document.body.clientWidth;
			pageHeight = document.body.clientHeight
		}
	}

	setPageSize();
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop  = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop  += obj.offsetTop
		}
	}
	return [curleft,curtop];
}