function initPage()
{
	fixLayout();
	var cSwitcher = document.getElementById("color-switcher");
	var links = cSwitcher.getElementsByTagName("a");
	
	
	var _defColor = getCookie();
	if (_defColor)
	{
		document.body.className = _defColor;
	}
	for (i = 0; i< links.length; i++)
	{
	
		links[i].onclick = function()
		{
			var _color = this.href.substr(this.href.indexOf("#") + 1);
			if (_color)
			{
				document.body.className = this.href.substr(this.href.indexOf("#") + 1);
				updateCookie(_color);
			}
			return false;
		}
	}

}

function updateCookie(vl) {
		var today = new Date();
		var exp = new Date(today.getTime() + (365*24*60*60*1000));
		document.cookie = 'cSwitcher=color=' + vl + ';' +'expires=' + exp.toGMTString() + ';' +'path=/';
	}

function getCookie() { 
		var cname = 'cSwitcher=color=';	
		var start = document.cookie.indexOf(cname);
		var len = start + cname.length;
		if ((!start) && (cname != document.cookie.substring(0,cname.length))) {return null;}
		if (start == -1) return null;
		var end = document.cookie.indexOf(";",len);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
	}

function fixLayout() 
{

	var cont = document.getElementById("container");
	var contHeight = cont.offsetHeight;
	
	//var wHeight = document.documentElement.clientHeight;
	wHeight = window.innerHeight;	

	if (document.all && !window.opera) {
		wHeight = document.documentElement.clientHeight;
	}

	if (contHeight < wHeight)
	{
		cont.style.marginTop = (wHeight - contHeight) / 2 + "px";
	}
	else
	{
		cont.style.marginTop = "0px";
	}


	
}

if (window.addEventListener)
{
	window.addEventListener("load", initPage, false);
	window.addEventListener("resize", fixLayout, false);
}
else if (window.attachEvent)
{
	window.attachEvent("onload", initPage);
	window.attachEvent("onresize", fixLayout);
}
