function init () {
	setPosition();
}

function setPosition () {
	var container = document.getElementById('container');
	if (container) {
		// Strip white spaces from container
		stripWhiteSpaces(container);

		var screenshot = 340;
		var count = container.childNodes.length;

		if (screenWidth() < count * screenshot) {
			container.style.paddingLeft = (screenWidth() % screenshot) / 2;
		}
		else {
			container.style.paddingLeft = (screenWidth() - count * screenshot) / 2;
		}
	}

	var steak = document.getElementById('steak');
	var title = document.getElementById('title');
	if (steak && title) {
		steak.style.left = ((screenWidth() - 900) / 2) + 'px';
		title.style.left = ((screenWidth() - 900) / 2 + 220) + 'px';
	}
}

function screenWidth () {
	return parseInt(document.all ? document.body.clientWidth : window.innerWidth) - scrollBarWidth();
}

function scrollBarWidth() {
	var width = 0;

	// Hide scrollbar
	document.body.style.overflow = 'hidden';
	width = document.body.clientWidth;

	// Enable scrollbar
	document.body.style.overflow = 'scroll';
	width -= document.body.clientWidth;
	
	// Fix for IE
	if (!width) width = document.body.offsetWidth - document.body.clientWidth;

	document.body.style.overflow = '';

	return width;
}

function stripWhiteSpaces (node) {
	if (!node) { return; }
	for (var i=0; i<node.childNodes.length; i++) {
		// Stripping the white spaces and repeat for each sub node (unless it's a leaf node)
		if (node.childNodes[i].nodeName == '#text' && node.childNodes[i].nodeValue.match(/^\s*$/) &&
				node.childNodes.length > 1) {
			node.removeChild(node.childNodes[i]);
		}
		stripWhiteSpaces(node.childNodes[i]);
	}
}

window.onload = init;
window.onresize = setPosition;
