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('red'); }
}

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);
addLoadEvent(addFlash);
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);
}

function addFlash() {
	var flashTag = new FlashTag();

	flashTag.version = 7;
	flashTag.src = 'flash/BridgemanFlash.swf';
	flashTag.id = 'main';
	flashTag.width = 845;	
	flashTag.height = 155;
	flashTag.bgcolor = '#000000';
	flashTag.wmode ='transparent'; // [transparent|opaque]

	flashTag.noPlayerHtml = flashTag.noPlayerVersionHtml = '<div id="flashNoPlayerDiv">You don\'t have the latest version of Adobe Flash Player. <br/> <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" onclick="window.open( this.href);return false;">Click to download</a> </div>';
	flashTag.writeToElement( 'bannerDiv' );
}
