function addEvent(elm, evType, fn,useCapture) {
		if(elm.addEventListener)
		{
			elm.addEventListener(evType, fn, useCapture);
			return true;
		}
		else if (elm.attachEvent)
		{
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		}
		else
		{
			elm['on' + evType] = fn;
		}
}

/*
This style switcher enhancement was written by Ian Lloyd (http://lloydi.com/). 
The basis for this addition comes from Ethan Marcotte's style switcher as 
documented in the Wrox book professional CSS.

Feel free to use on your site but please leave comment as-is (adding your  
own comments regarding further modifications that you may choose to make.
*/

// VARIABLES - uncomment and customise to suit needs
var ContainerID = "content"; //Add the name of the container that you want the switcher tool to be written into here
var Position = "first"; // If you enable this, the switcher will be inserted as either the first item in the parent container, otherwise it'll add as last item
var PromptMessage = "Did you notice that you can hide and show references using the link above? [This note will not be displayed after you hit refresh or visit another page]";
var promptTrigger = 200; //how many page views until the prompt to check out the other styles appears;
// End variables

function findCSS() {
//check for previous visits to site/page
var visitCount = readCookie("visitCount");
if ((typeof visitCount=="undefined")||(visitCount=="NaN")){
	visitCount=0;
	}
else{
	visitCount = parseInt(visitCount);
	visitCount+=1;
	}
//log another visit to the page, store in cookie - to be used for prompt mechanism
setCookie("visitCount", visitCount, 365);

var altCSS = false;//no alternative style sheets found
var CSSlinks = document.getElementsByTagName("link");
if (CSSlinks.length>0)
	{
	var switcherDiv = document.createElement("div");
	switcherDiv.setAttribute("id","switcher");
	var ul = document.createElement("ul");

	//write in link to default style
	var defaultLI = document.createElement("li");
	defaultLI.setAttribute("class","first");
	defaultLI.setAttribute("className","first");
	var defaultLItext = document.createTextNode("Show footnotes");
	var defA = document.createElement("a");
	defA.setAttribute("href","#");
	defA.setAttribute("title","Show footnotes");
	defA.onclick = doSwitch;
	defA.appendChild(defaultLItext);
	defaultLI.appendChild(defA);
	ul.appendChild(defaultLI);

	//loop through all CSS links - look for alternate styles
	for (i=0;i<CSSlinks.length;i++) {
		if (CSSlinks[i].rel=="alternate stylesheet") {
			altCSS = true;//there are alternative style sheets here
			var newLI 		= document.createElement("li");
			var newA		= document.createElement("a");
			newA.setAttribute("href","#");
			newA.setAttribute("title",CSSlinks[i].title);
			newA.onclick = doSwitch;
			var newLItext 	= document.createTextNode(CSSlinks[i].title);
			newA.appendChild(newLItext);
			newLI.appendChild(newA);
			ul.appendChild(newLI);
			}
		}
	if (altCSS) { //alternate stylesheets were found - add to document
		//add navigation list to switcher container
		switcherDiv.appendChild(ul);
		//add prompt text for *this visit only*
		if (typeof promptTrigger!='undefined') {
			if (visitCount==promptTrigger) {
				var promptP = document.createElement("p");
				var promptPtext = document.createTextNode(PromptMessage);
				promptP.setAttribute("class","style-switch-prompt");
				promptP.setAttribute("className","style-switch-prompt");
				promptP.appendChild(promptPtext);
				switcherDiv.appendChild(promptP);
				}
			}
		//what parent container is switcher to go into?
		if (typeof ContainerID!='undefined') {//place in container set in variables
			var container = document.getElementById(ContainerID);
			}
		else {//drop into body of document
			var container = document.getElementsByTagName("body");
			container = container[0];
			}
		//where in parent container should it go?
		if (typeof Position!='undefined') {
			container.insertBefore(switcherDiv, container.firstChild );
			}
		else {
			container.appendChild(switcherDiv);
			}
		}
	}
}
function doSwitch(e) {
activeCSS(this.title);
return false;
}
addEvent(window,'load',findCSS, false);
