/*This script changes the masthead image when a user selects one, and stores that image name in a cookie so it persists through browsing. This script is open source.  Feel free to use it in your projects. I only ask that you let me know via the contact form on www.miterboxdesigns.com.  Thanks!*/
function mastheadImageSwap (value) {
var name = new Array ('glass','leaves','fuzzy','wetdog');
var images = new Array ('url(../images/masthead/trial4.jpg)','url(../images/masthead/trial11.jpg)','url(../images/masthead/trial1.jpg)','url(../images/masthead/trial2.jpg)');
for (i=0; i<name.length; i++) {
if(value == name[i]) {
	if (document.styleSheets[0].rules) {
	document.styleSheets[0].rules[4].style.backgroundImage=images[i];
	document.styleSheets[0].rules[5].style.backgroundImage=images[i];
	}
	else if(document.styleSheets[0].cssRules) {
	document.styleSheets[0].cssRules[3].style.backgroundImage=images[i];
} else {
alert('This script does not work in your browser');
return;
}
}
}
}


function getCurrentImage() {
var nowimage = '';
	if (document.styleSheets[0].rules) {
	return nowimage = document.styleSheets[0].rules[4].style.backgroundImage;
	}
	else if (document.styleSheets[0].cssRules) {
	return nowimage = document.styleSheets[0].cssRules[3].style.backgroundImage;
	} 
}

function setCurrentImage(newimage) {
if (document.styleSheets[0].rules) {
	document.styleSheets[0].rules[4].style.backgroundImage = newimage;
	document.styleSheets[0].rules[5].style.backgroundImage = newimage;
} else if (document.styleSheets[0].cssRules) {
	document.styleSheets[0].cssRules[3].style.backgroundImage = newimage;
}
}

/*This font-size switcher receives a string parameter from the onClick event equal to the desired font-size (10px, 12px, 14px), then applies that value directly to the body tag through the style object.  Last, it stores this value in a cookie so the change is persistent across pages.  This script is open source.  Feel free to use it in your projects. I only ask that you (a) let me know via the contact form on www.miterboxwebdesigns.com and (b) include a commented reference to the source (my URL would be great) in your code.  Thanks!*/
function changeFont(value) {
var size = new Array('s','m','l');
var font = new Array('62.8\%','72.8\%','82.8\%');
for (i=0; i<size.length; i++) {
if(value == size[i]) {
	if (document.styleSheets[0].rules) {
	document.styleSheets[0].rules[3].style.fontSize=font[i];
	}
	else if(document.styleSheets[0].cssRules) {
	document.styleSheets[0].cssRules[2].style.fontSize=font[i];
} else {
alert('This script does not work in your browser');
return;
}
}
}
} 

function getCurrentFont() {
var nowfont = '';
	if (document.styleSheets[0].rules) {
	return nowfont = document.styleSheets[0].rules[3].style.fontSize;
	}
	else if (document.styleSheets[0].cssRules) {
	return nowfont = document.styleSheets[0].cssRules[2].style.fontSize;
	} 
}

function setCurrentFont(newfont) {
if (document.styleSheets[0].rules) {
	document.styleSheets[0].rules[3].style.fontSize = newfont;
} else if (document.styleSheets[0].cssRules) {
	document.styleSheets[0].cssRules[2].style.fontSize = newfont;
}
}


/*Cookie functions*/

function writeCookie(name,value) {
	var expire = new Date();
	var oneYear = expire.getTime() + (365 * 24 * 60 * 60 * 1000);
	expire.setTime(oneYear);
	document.cookie = name + "=" + escape(value) + "; expires=" + expire.toGMTString() + "; path=/";
}
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 unescape(c.substring(nameEQ.length,c.length));
  }
  return null;
}


window.onunload = function(b) {
	var title = getCurrentImage();
	writeCookie("image",title);
	var title = getCurrentFont();
	writeCookie("font", title); 
	}

function loadImage() {
  var cookie = readCookie("image");
  var title = cookie ? cookie : getCurrentImage();
setCurrentImage(title);
  var cookie = readCookie("font");
  var title = cookie ? cookie : getCurrentFont();
setCurrentFont(title);
}
	
  /* var cookie = readCookie("image");
  var title = cookie ? cookie : getCurrentImage();
  setCurrentImage(title);
  var cookie = readCookie("font");
  var title = cookie ? cookie : getCurrentFont();
  setCurrentFont(title); */