// functions lifted from http://www.heartsofoakfoundation.org/

// RESIZING TEXT -------------------------------------------------------

// Set Body text size
function setSize(iSize) {
	if (!document.getElementsByTagName) return false;
	var bodyTag = document.getElementsByTagName ("body");
	for (var i=0; i < bodyTag.length; i++) {
		if (!bodyTag[i].style.fontSize) {
		if (!readCookie("resize")) {
		bodyTag[i].style.fontSize = "100%";
		}
		else {
		bodyTag[i].style.fontSize = ((parseFloat(readCookie("resize"))) + "%");
		}
		}
		else {
		if (!readCookie("resize")) {
		bodyTag[i].style.fontSize = "100%";
		}
		else {
		bodyTag[i].style.fontSize = (((parseFloat(iSize)) + (parseFloat(readCookie("resize")))) + "%");
		}
		}
		cookieValue = bodyTag[i].style.fontSize;
		writeCookie("resize", cookieValue, 0);
	}
}


// Attaches the onclick event to the correct ids to allow resizing
function resizeT(iID, iDir) {
	if (!document.getElementById) return false;
	var incLink = document.getElementById (iID);
	if (iDir == "decrease") {
	incLink.onclick = function() {
		setSize("-5%");
		return false;
	}
	}
	if (iDir == "increase") {
	incLink.onclick = function() {
		setSize("5%");
		return false;
	}
	}
}

// Writes cookie
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.

function writeCookie(name,value,hours) {
  if (hours) {
    var date = new Date();
    date.setTime(date.getTime()+(hours*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}


// Read Cookie

function readCookie(name) {
  var cookieValue = 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(cookieValue) == 0) return c.substring(cookieValue.length,c.length);
  }
  return null;
}

window.onload=function(){
resizeT("stIncrease", "increase");
resizeT("stDecrease", "decrease");
setSize("100%");
}
