//Style Sheet Switcher version 1.1 Oct 10th, 2006
//Author: Dynamic Drive: http://www.dynamicdrive.com
//Usage terms: http://www.dynamicdrive.com/notice.htm

//Unofficial Update to fix Safari 5.1 glitch re: alternate stylesheets or the disabled property in regards to them
// See: http://www.dynamicdrive.com/forums/showthread.php?p=259199 for more info

function indicateSelected(a){if(selectedtitle!=null&&(a.type==undefined||a.type=="select-one")){var a=a.type=="select-one"?a.options:a;for(var b=0;b<a.length;b++){if(a[b].value==selectedtitle){if(a[b].tagName=="OPTION")a[b].selected=true;else{a[b].checked=true}break}}}}function chooseStyle(a,b){if(document.getElementById){setStylesheet(a);setCookie("mysheet",a,b);title=a}}function setStylesheet(a,b){var c,d,e=[""];if(setStylesheet.chosen)try{document.getElementsByTagName("head")[0].removeChild(setStylesheet.chosen)}catch(f){}for(c=0;d=document.getElementsByTagName("link")[c];c++){if(d.getAttribute("rel").toLowerCase()=="alternate stylesheet"&&d.getAttribute("title")){d.disabled=true;e.push(d);if(d.getAttribute("title")==a){d.disabled=false;setStylesheet.chosen=document.createElement("link");setStylesheet.chosen.rel="stylesheet";setStylesheet.chosen.type="text/css";if(d.media)setStylesheet.chosen.media=d.media;setStylesheet.chosen.href=d.href;document.getElementsByTagName("head")[0].appendChild(setStylesheet.chosen)}}}if(typeof b!="undefined"){var g=Math.floor(Math.random()*e.length);e[g].disabled=false}return typeof b!="undefined"&&e[g]!=""?e[g].getAttribute("title"):""}function deleteCookie(a){setCookie(a,"moot")}function setCookie(a,b,c){var d=new Date;var e=typeof c!="undefined"?d.setDate(d.getDate()+parseInt(c)):d.setDate(d.getDate()-5);document.cookie=a+"="+b+"; expires="+d.toGMTString()+"; path=/"}function getCookie(a){var b=new RegExp(a+"=[^;]+","i");if(document.cookie.match(b))return document.cookie.match(b)[0].split("=")[1];return null}var manual_or_random="manual";var randomsetting="3 days";var title="";if(manual_or_random=="manual"){var selectedtitle=getCookie("mysheet");if(document.getElementById&&selectedtitle!=null){setStylesheet(selectedtitle);title=selectedtitle}else{chooseStyle("Light_ON",1)}}else if(manual_or_random=="random"){if(randomsetting=="eachtime")setStylesheet("","random");else if(randomsetting=="sessiononly"){if(getCookie("mysheet_s")==null)document.cookie="mysheet_s="+setStylesheet("","random")+"; path=/";else setStylesheet(getCookie("mysheet_s"))}else if(randomsetting.search(/^[1-9]+ days/i)!=-1){if(getCookie("mysheet_r")==null||parseInt(getCookie("mysheet_r_days"))!=parseInt(randomsetting)){setCookie("mysheet_r",setStylesheet("","random"),parseInt(randomsetting));setCookie("mysheet_r_days",randomsetting,parseInt(randomsetting))}else setStylesheet(getCookie("mysheet_r"))}}
