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 logo1 = document.getElementById('logo1');
	var logo2 = document.getElementById('logo2');
	var title = document.getElementById('title');
	if (logo1 && logo2 && title) {
		logo1.style.left = ((screenWidth() - 950) / 2) + 'px';
		title.style.left = ((screenWidth() - 950) / 2 + 260) + 'px';
		logo2.style.left = ((screenWidth() - 950) / 2 + 680) + '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 loadList () {
	var button = document.getElementById('list_button');
	var iframe = document.getElementById('list');
	if (button && iframe) {
		iframe.src = "list.php";
		button.style.display = 'none';
		iframe.style.display = '';
	}
}

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;
