// JavaScript Document

stylesheetTitles = new Array("small","medium","large"); //stores all the stylesheet "titles" in ascending order
siteID = "gosh"

<!---------------------------------------------------------------------->
<!--- CHANGING STYLESHEETS                                           --->
<!---------------------------------------------------------------------->

function increase(path)
	{
	if (textsize < stylesheetTitles.length-1)
		{	
		textsize++; //increases counter
		var title = stylesheetTitles[textsize]; //gets the correct "title" of the stylesheet
		setActiveStyleSheet(title); //changes the stylesheet
		document.getElementById("minus").src="lib/templates/shared/minus_red.gif"; //make sure minus is not grayed out
		if (textsize == stylesheetTitles.length-1)
			{
			document.getElementById("plus").src="lib/templates/shared/plus_grey.gif"; //gray out plus
			}			
		}
	}

function decrease(path)
	{
	if (textsize > 0)
		{
		textsize--; //decreases counter
		var title = stylesheetTitles[textsize]; //gets the correct "title" of the stylesheet
		setActiveStyleSheet(title); //changes the stylesheet
		document.getElementById("plus").src="lib/templates/shared/plus_red.gif"; //make sure plus is not grayed out
		if (textsize == 0)
			{
			document.getElementById("minus").src="lib/templates/shared/minus_grey.gif"; //gray out minus
			}
		}
	}
	
function setActiveStyleSheet(title)
	{
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) //cycles through all "link" elements
  		{
    	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) //checks to make sure you are looking at a stylesheet
			{
      		a.disabled = true; //disables all stylesheets
     		if(a.getAttribute("title") == title) a.disabled = false; //enables correct stylesheet by evaluating the "title"
			createCookie(siteID+"_style", textsize, 365);
    		}
  		}
	}
	
<!---------------------------------------------------------------------->
<!--- SETTING COOKIES                                                --->
<!---------------------------------------------------------------------->
//window.onunload = function(e) {
	//createCookie(siteID+"_style", textsize, 365);
//}

function createCookie(name,value,days)
	{
		if (days)
			{
    			var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
		else expires = "";
		var textsizeString = String(value); //converts "textsize" to a string
		document.cookie = name+"="+textsizeString+expires+"; path=/"; //writes the cookie
	}

function readCookie(name)
	{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
		{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
	return null;
	}

var cookie = parseInt(readCookie(siteID+"_style")); //reads the cookie and extracts the preferred stylesheet's number
textsize = (cookie ? cookie : 0); //checks to see if a cookie exists and gives "textsize" the correct value
setActiveStyleSheet(stylesheetTitles[textsize]); //sets the preferred stylesheet