var prefsLoaded = false;
var currentStyle = 'blue';
var defaultStyle = 'blue'

function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  { window.onload = func; }
  else
  { window.onload = function() { oldonload(); func(); } }
}

function showContainer()
{
	document.getElementById('container').style.display = 'block';
}

function swapColour()
{
	if (currentStyle == 'blue')
	{ setColour('red'); }
	else
	{ setColour('yellow'); }
}

function setColour(colour)
{
	switch (colour)
	{
		case 'yellow':
			currentStyle = 'yellow';
			document.body.className = 'yellowstyle';
			break;
		case 'red':
			currentStyle = 'red';
			document.body.className = 'redstyle';
			break;
		case 'blue':
			currentStyle = 'blue';
			document.body.className = 'bluestyle';
			break;
		case 'green':
			currentStyle = 'green';
			document.body.className = 'greenstyle';
			break;
		default:
			// default style if none specified
			currentStyle = defaultStyle;
			document.body.className = defaultStyle + 'style';
	}
}


// Thieved from artechnica.com ui code
addLoadEvent(setUserOptions);
window.onunload = saveSettings;

function setUserOptions(){
	if(!prefsLoaded){
		cookie = getCookie('pageColor');
		// default style if no cookie
		currentStyle = cookie ? cookie : defaultStyle;
		setColour(currentStyle);

		prefsLoaded = true;
	}
	showContainer();
}

function saveSettings()
{
  setCookie('pageColor', currentStyle);
}