//<![CDATA[
//open initialisation function
function iotbs() {
	switcher = new switchManager();
	//create a screenSwitcherButton ('classname', 'butonId')
	var screenSwitcherButton1 = buttonDefineAction('normal', 'decreaseType');
	var screenSwitcherButton2 = buttonDefineAction('moyen', 'increaseType');
};


//global preferences manager reference
var switcher;

//setup initialisation function
//.. gecko, safari, konqueror and generic
if(typeof window.addEventListener != 'undefined')
{
	window.addEventListener('load', iotbs, false);
}
//.. opera 7
else if(typeof document.addEventListener != 'undefined')
{
	document.addEventListener('load', iotbs, false);
}
//.. win/ie
else if(typeof window.attachEvent != 'undefined')
{
	window.attachEvent('onload', iotbs);
}
	
	
//preferences manager 
function switchManager()
{
	//string for storing the overall custom classname
	//I was originally storing it in the body class name directly
	//but 1.7+ mozilla builds were not honouring the trailing whitespace we need
	this.string  = '';
	
	//store reference to body element
	this.body = document.getElementsByTagName('body')[0];
	//store the initial classname
	this.initial = this.body.className;
	
	//if the default classname is empty, add "iotbs"
	if(this.initial == '')
	{
		this.initial = 'normal';
	}
	
	//look for a stored cookie
	this.cookie = this.read();

	//if it exists
	if(this.cookie != null)
	{
		//store cookie value to string
		this.string = this.cookie;
		
		//set new body class name
		this.body.className = this.string;
	}
	
	//*** dev
	//document.title = '<' + this.body.className.replace(/ /g,'+') + '>   [' + this.string.replace(/ /g,'+') + ']';
	
};
	
//set a cookie method
switchManager.prototype.set = function(days, variable)
{
	//format expiry date
	this.date = new Date();
	this.date.setTime(this.date.getTime() + ( days *24*60*60*1000));
	//create the cookie
	document.cookie = 'bodySwitcher=' + variable
		+ '; expires=' + this.date.toGMTString() 
		+ '; path=/';
		
};
	
	
//read a cookie method
switchManager.prototype.read = function()
{
	//set null reference so we always have something to return
	this.cookie = null;
	
	//if a cookie exists
	if(document.cookie)
	{
		//if it's our cookie
		if(document.cookie.indexOf('bodySwitcher')!=-1)
		{
			//extract and store relevant information (turning '#' back into spaces)
			this.cookie = document.cookie.split('bodySwitcher=');
			this.cookie = this.cookie[1].split(';');
			this.cookie = this.cookie[0].replace(/#/g,' ');
		}
	}
	return this.cookie;
};

/* Adding buttonSwitcher action definition - isw */
function bodySwitcherButton(classSwitcher)
{
	//set new body class name
	//alert(classSwitcher);
	switcher.body.className = classSwitcher;
	
	//store changes to a cookie which expires a year from now
	switcher.set(365, classSwitcher);
	
	//*** dev
	//document.title = '<' + switcher.body.className.replace(/ /g,'+') + '>   [' + switcher.string.replace(/ /g,'+') + ']';
};

function buttonDefineAction(classSwitcher, buttonId)
{
	document.getElementById(buttonId).style.cursor = 'pointer';
	document.getElementById(buttonId).onclick = function () {bodySwitcherButton(classSwitcher)};
}
	
//]]>