// Daco de la Bretoniere @ lazzo.nl
// solution for jumpy viewport

var contentWidth = 1015;
var backgroundImgWidth = 4800;

// Webkit weird rendering when using viewport.getWidth!
if (Prototype.Browser.WebKit){
	var viewportWidth = window.innerWidth;	
} else {
	var viewportWidth = document.viewport.getWidth();
}
var mainLeftValue = Math.round((viewportWidth - contentWidth) / 2);
var bgLeftValue = Math.round((viewportWidth - backgroundImgWidth) / 2);

// Insert a rule into a stylesheet the W3C way
if (typeof document.styleSheets[0].insertRule != 'undefined') {
	document.styleSheets[0].insertRule('#wrapper {left:' + mainLeftValue + 'px}', 1);
	document.styleSheets[0].insertRule('body {background-position:'+ bgLeftValue +'px 0}', 1);
}
// Add a rule into a stylesheet the Microsoft way 
else {
	setTimeout(function(){
		
		document.styleSheets[0].addRule('#wrapper', 'left:' + mainLeftValue + 'px', 1);
		document.styleSheets[0].addRule('body', 'background-position:' + bgLeftValue + 'px 0', 1);		
		
	}, 0)

}

// Object for positioning the main content on 'resize'
var tekstpierement = {};
tekstpierement.scrollbarMainAdjust = function(){
	var viewportWidth = document.viewport.getWidth();
	var mainLeftValue = Math.round((viewportWidth - contentWidth) / 2);
	var bgLeftValue = Math.round((viewportWidth - backgroundImgWidth) / 2);
	$('wrapper').setStyle({left:mainLeftValue+'px'});
	$(document.body).setStyle({backgroundPosition:bgLeftValue +'px 0'});
}

Event.observe(document.onresize ? document : window, "resize", tekstpierement.scrollbarMainAdjust);
// / solution for jumpy viewport
