// JavaScript Document

	<!-- Begin
	<!-- Original:  Mattias Sjoberg. Edited By Ashley Bennett -->
	
	var expDays = 30;
	var exp = new Date(); 
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	
	//to run when opening the page to see if there is a cookie, returns the value. edited by Ash
	function bg(){
		var favBG = GetCookie('bg');
		if (favBG == null) {
			favBG = 0;
			SetCookie('bg', favBG, exp);
		}
		return favBG;
	}
	
	//sets a cookie to the value of the dropdown. edited by Ash
	function set(bgNum){
		favBG = bgNum;
		SetCookie ('bg', favBG, exp);
	}
	
	//for dealing with cookies. not Ash's code
	function getCookieVal (offset) {  
		var endstr = document.cookie.indexOf (";", offset);  
		if (endstr == -1)    
			endstr = document.cookie.length;  
		return unescape(document.cookie.substring(offset, endstr));
	}
	function GetCookie (name) {  
		var arg = name + "=";  
		var alen = arg.length;  
		var clen = document.cookie.length;  
		var i = 0;  
		while (i < clen) {    
			var j = i + alen;    
			if (document.cookie.substring(i, j) == arg)      
				return getCookieVal (j);    
			i = document.cookie.indexOf(" ", i) + 1;    
			if (i == 0) break;   
		}  
		return null;
	}
	function SetCookie (name, value) {  
		var argv = SetCookie.arguments;  
		var argc = SetCookie.arguments.length;  
		var expires = (argc > 2) ? argv[2] : null;  
		var path = (argc > 3) ? argv[3] : null;  
		var domain = (argc > 4) ? argv[4] : null;  
		var secure = (argc > 5) ? argv[5] : false;  
		document.cookie = name + "=" + escape (value) + 
			((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
			((path == null) ? "" : ("; path=" + path)) +  
			((domain == null) ? "" : ("; domain=" + domain)) +    
			((secure == true) ? "; secure" : "");
	}
	function DeleteCookie (name) {  
		var exp = new Date();  
		exp.setTime (exp.getTime() - 1);  
		var cval = GetCookie (name);  
		document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	}


	<!-- Ash's Code -->

	//maxnum is the max number of bg's available (e.g. 2 = bg0.jpg and bg1.jpg) when choosing a random bg
	var maxnum = 7;

	//if the dropdown is 0, choose a random style, otherwise choose the right one
	//(which is listbox.selectedIndex - 1 since listbox and bg's both start at 0, but 'random style' is in the 0 position in listbox)
	function ChangeSkin(styleNum) {
		if (styleNum == 0) {
			var bgnumber = Math.floor(Math.random() * maxnum);
		} else {
			var bgnumber = styleNum - 1;
		}
		document.getElementById("wrapper").style.backgroundImage = "url(../images/bg" + bgnumber + ".jpg)";
		document.body.style.backgroundImage = "url(../images/gradient" + bgnumber + ".jpg)";
	}
	
	//on page load
	function start(){
		var bgNum = bg();
		ChangeSkin(bgNum);
		document.getElementById("styleSelect").selectedIndex = bgNum;
		//document.styleForm.styleSelect.selectedIndex = bgNum;
	}
	
	//on changing dropdown
	function change(bgNum){
		set(bgNum);
		ChangeSkin(bgNum);
	}

	// End -->
