// Initial settings
var defaultScheme = 'blue';
var prefsLoaded = false;
var currentStyle = 'orange';
var currentFontSize = 0.9;

// Attach a function to the onLoad event
function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  { window.onload = func; }
  else
  { window.onload = function() { oldonload(); func(); } }
}

/*
Avoid style-change flicker (every visible element must be contained within
a div with id "container"
*/
function showContainer()
{ document.getElementById('container').style.display = 'block';
	if(document.getElementById('registration')){
		document.getElementById('registration').style.display = 'block';	
	}
}

// Set the body class to swap colours
function setColour(colour)
{
	switch (colour)
	{
		case 'orange':
			currentStyle = 'orange';
			document.body.className = 'orangestyle';
			break;
		case 'yellow':
			currentStyle = 'yellow';
			document.body.className = 'yellowstyle';
			break;
		case 'green':
			currentStyle = 'green';
			document.body.className = 'greenstyle';
			break;
		case 'blue':
			currentStyle = 'blue';
			document.body.className = 'bluestyle';
			break;
		case 'magenta':
			currentStyle = 'magenta';
			document.body.className = 'magentastyle';
			break;
		case 'red':
			currentStyle = 'red';
			document.body.className = 'redstyle';
			break;
		case 'brown':
			currentStyle = 'brown';
			document.body.className = 'brownstyle';
			break;
		case 'grey':
			currentStyle = 'grey';
			document.body.className = 'greystyle';
			break;
		case 'black':
			currentStyle = 'black';
			document.body.className = 'blackstyle';
			break;
		default:
			// default style if none specified
			currentStyle = 'orange';
			document.body.className = 'orangestyle';
	}
}

function changeFontSize(sizeDifference){
	currentFontSize = currentFontSize + sizeDifference;
	setFontSize(currentFontSize);
};

function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('container') : document.all('container');
	stObj.style.fontSize = fontSize + 'em';
};


// Thieved from artechnica.com ui code
addLoadEvent(setUserOptions);
window.onunload = saveSettings;

function setUserOptions(){
	if(!prefsLoaded){
		
		// color
		cookie = readCookie('pageColour');
		currentStyle = cookie ? cookie : defaultScheme;
		setColour(currentStyle);
		
		// font size
		cookie = readCookie('fontSize');
		currentFontSize = cookie ? cookie : 0.9;
		setFontSize(currentFontSize);

		prefsLoaded = true;
	}
	showContainer();
}

function saveSettings()
{
  createCookie('pageColour', currentStyle, 30);
  createCookie('fontSize', currentFontSize, 30);
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
};

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
};

loadOfficeFlash = function() {
	

	var flashTag = new FlashTag();
	
	flashTag.version = 7;
	flashTag.src = 'flash/OFFICE-09-02-2007.swf';
	flashTag.id = 'officeFlashAnimation';
	flashTag.width = 163;	
	flashTag.height = 210;
	flashTag.scale = 100;
	flashTag.bgcolor = '#ffffff';
	flashTag.wmode ='opaque'; // [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( 'officeFlash' );

}
addLoadEvent(loadOfficeFlash);