// IOTBS1.2[DC] :: Attack of the Body Switchers: "The Director's Cut"// ***********************************************// 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*****************************************************************************/var screenSwitcher = new stylePrefs('text-switcher', 'Text Style Preference', ' | SELECTED' );screenSwitcher.defineClass('default', 'Default');screenSwitcher.defineClass('high', 'Higher contrast');var screenSwitcher = new stylePrefs('textsize-switcher', 'Text Size Preference', ' | SELECTED');screenSwitcher.defineClass('default', 'Default');screenSwitcher.defineClass('font-large', 'Large');screenSwitcher.defineClass('font-xlarge', 'X-Large');var screenSwitcher = new stylePrefs('color-switcher', 'Color Scheme Preference', ' | SELECTED');screenSwitcher.defineClass('default', 'Default');screenSwitcher.defineClass('red', 'Red');screenSwitcher.defineClass('green', 'Green');/**********************************************************************************************************************************************************/};var switcher;if(typeof window.addEventListener != 'undefined'){window.addEventListener('load', iotbs, false);}else if(typeof document.addEventListener != 'undefined'){document.addEventListener('load', iotbs, false);}else if(typeof window.attachEvent != 'undefined'){window.attachEvent('onload', iotbs);window.attachEvent('onunload', function(){this.daLen = document.all.length;for(var i=0; i<this.daLen; i++){document.all[i]['onchange'] = null;}});}function switchManager(canvas){this.string  = '';this.canvas = 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;}};switchManager.prototype.set = function(days){this.date = new Date();this.date.setTime(this.date.getTime() + ( days *24*60*60*1000));this.info = this.string.replace(/ /g,'#');if(this.info == '') { this.date.setTime(0); }document.cookie = 'stylePrefs=' + this.info+ '; expires=' + this.date.toGMTString() + '; path=/';};switchManager.prototype.read = function(){this.cookie = null;if(document.cookie){if(document.cookie.indexOf('stylePrefs')!=-1){this.cookie = document.cookie.split('stylePrefs=');this.cookie = this.cookie[1].split(';');this.cookie = this.cookie[0].replace(/#/g,' ');}}return this.cookie;};function stylePrefs(divid, label, selected){if(document.getElementById(divid) == null) { return false; }this.classes = [], this.labels = [];this.div = document.getElementById(divid);this.dl = this.div.appendChild(this.createElement('dl'));this.attrs = { 'text' : label };this.dt = this.dl.appendChild(this.createElement('dt', this.attrs));this.selected = selected;return true;};stylePrefs.prototype.defineClass = function(key, val){if(typeof this.dl == 'undefined') { return false; }this.item = this.dl.appendChild(this.createElement('dd'));if(key == 'default'){this.link = this.item.appendChild(document.createTextNode(val + this.selected));}else if(switcher.cookie != null && switcher.cookie.indexOf(' ' + key + ' ')!=-1) {this.link = this.item.appendChild(document.createTextNode(val + this.selected));if(key != 'default'){this.text = this.dl.childNodes[1].firstChild.nodeValue;this.dl.childNodes[1].removeChild(this.dl.childNodes[1].firstChild);this.attrs = { 'href' : 'javascript:void("' + this.classes[0] + '", "' + this.labels[0] + '")', 'text' : this.labels[0] };this.link = this.dl.childNodes[1].appendChild(this.createElement('a', this.attrs));}}else{this.attrs = { 'href' : 'javascript:void("' + key + '", "' + val + '")', 'text' : val };this.link = this.item.appendChild(this.createElement('a', this.attrs));}var self = this;this.item.onclick = function(){if(this.getElementsByTagName('a').length == 0) { return false; }this.classLen = self.classes.length;for(var i=0; i < this.classLen; i++){switcher.string = switcher.string.replace(' ' + self.classes[i] + ' ','');}this.key = unescape(this.firstChild.href).split('"')[1];this.val = unescape(this.firstChild.href).split('"')[3];if(this.key != 'default'){switcher.string += ' ' + this.key + ' ';}this.items = self.dl.getElementsByTagName('dd');this.itemsLen = this.items.length;for(i=0; i < this.itemsLen; i++){if(this.items[i].firstChild.nodeName == '#text'){this.items[i].removeChild(this.items[i].firstChild);this.attrs = { 'href' : 'javascript:void("' + self.classes[i] + '", "' + self.labels[i] + '")', 'text' : self.labels[i] };this.link = this.items[i].appendChild(self.createElement('a', this.attrs));}}for(i=0; i < this.itemsLen; i++){if(this.items[i] == this){this.items[ (i == this.itemsLen - 1 ? 0 : i + 1) ].firstChild.focus();this.removeChild(this.firstChild);this.appendChild(document.createTextNode(self.labels[i] + self.selected));}}switcher.canvas.className = switcher.initial + switcher.string;switcher.set(365);return true;};this.classes[this.classes.length] = key;this.labels[this.labels.length] = val;return true;};stylePrefs.prototype.createElement = function(tag, attrs){this.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' :this.ele.appendChild(document.createTextNode(attrs[i]));break;case 'class' : this.ele.className = attrs[i];break;case 'for' : this.ele.setAttribute('htmlFor',attrs[i]);break;default : this.ele.setAttribute(i,'');this.ele[i] = attrs[i];break;}}}return this.ele;};