// IOTBS1.3 :: Invasion of the Body Switchers
// ***********************************************
// This copyright statement must remain in place for both personal and commercial use
// GNU General Public License -- http://www.gnu.org/copyleft/gpl.html
// ***********************************************
// Original concept by Andy Clarke -- http://www.stuffandnonsense.co.uk/
// DOM scripting by brothercake -- http://www.brothercake.com/
// Create element and attributes based on a method by beetle -- http://www.peterbailey.net/
//************************************************
function iotbs() { //open initialisation function 
//************************************************

//initialise the preferences manager ('canvas-element')
switcher = new switchManager('body');

/*****************************************************************************
 Define switching controls
*****************************************************************************/


//create a new switcher control ('container-id', 'label')
var screenSwitcher = new bodySwitcher('screen-switcher', 'Customize:');

//add a new class option ('classname', 'label')
screenSwitcher.defineClass('default', 'Normal');
screenSwitcher.defineClass('font', 'Larger Font Size');
screenSwitcher.defineClass('highvisibility', 'High Contrast');

/*****************************************************************************
*****************************************************************************/



//close initialisation function
};var switcher;function domReady(){this.n = typeof this.n == 'undefined' ? 0 : this.n + 1;if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)){if(!(typeof document.all != 'undefined' && typeof window.opera == 'undefined' && typeof document.mimeType == 'undefined')){iotbs();}}else if(this.n < 60){setTimeout('domReady()', 250);}};domReady();function switchManager(canvas){this.string  = '';this.canvas = canvas == 'body' && typeof document.body != 'undefined' ? document.body : document.getElementsByTagName(canvas)[0];this.initial = this.canvas.className;if(this.initial == ''){this.initial = 'itobs';}this.cookie = this.read();if(this.cookie != null){this.string = this.cookie;this.canvas.className = this.initial + this.string;}if(typeof window.attachEvent != 'undefined'){window.attachEvent('onunload', function(){for(var i=0; i<document.all.length; i++){document.all[i]['onchange'] = null;}});}};switchManager.prototype.set = function(days){var thedate = new Date();thedate.setTime(thedate.getTime() + ( days *24*60*60*1000));var info = this.string.replace(/ /g,'#');if(info == '') { thedate.setTime(0); }document.cookie = 'bodySwitcher=' + info+ '; expires=' + thedate.toGMTString() + '; path=/';};switchManager.prototype.read = function(){this.cookie = null;if(document.cookie && document.cookie.indexOf('bodySwitcher=')!=-1){this.cookie = document.cookie.split('bodySwitcher=')[1].split(';')[0].replace(/#/g,' ');}return this.cookie;};function bodySwitcher(divid, label){if(document.getElementById(divid) == null) { return false; }this.classes = [];this.options = 0;var attrs = { 'action' : '' };var frm = document.getElementById(divid).appendChild(this.create('form', attrs));var fieldset = frm.appendChild(this.create('fieldset'));attrs = { 'for' : 'select-' + divid };var labele = fieldset.appendChild(this.create('label', attrs));attrs = { 'text' : label };labele.appendChild(this.create('span', attrs));attrs = { 'id' : 'select-' + divid };this.select = labele.appendChild(this.create('select', attrs));var self = this;this.select.onchange = function(){var len = self.classes.length;for(var i=0; i<len; i++){switcher.string = switcher.string.replace(' ' + self.classes[i] + ' ','');}var chosen = this.options[this.options.selectedIndex].value;if(chosen != 'default'){switcher.string += ' ' + chosen + ' ';}switcher.canvas.className = switcher.initial + switcher.string;switcher.set(365);};return true;};bodySwitcher.prototype.defineClass = function(key, val){if(typeof this.select == 'undefined') { return false; }var attrs = { 'value' : key, 'text' : val }; this.select.appendChild(this.create('option', attrs));if(switcher.cookie != null && switcher.cookie.indexOf(' ' + key + ' ')!=-1){this.select.selectedIndex = this.options;}this.classes[this.options] = key;this.options ++;return true;};bodySwitcher.prototype.create = function(tag, attrs){var ele = (typeof document.createElementNS != 'undefined') ? document.createElementNS('http://www.w3.org/1999/xhtml',tag) : document.createElement(tag);if(typeof attrs != 'undefined'){for(var i in attrs){switch(i){case 'text' :ele.appendChild(document.createTextNode(attrs[i]));break;case 'class' : ele.className = attrs[i];break;case 'for' : ele.setAttribute('htmlFor',attrs[i]);break;default : ele.setAttribute(i,'');ele[i] = attrs[i];break;}}}return ele;};