
/*FontSizer v2.0 - See http://www.unintentionallyblank.co.uk/ for full details*/
// addDOMLoadEvent provides an event that fires when the DOM is ready, rather than when all the content has loaded.
addDOMLoadEvent=(function(){var e=[],t,s,n,i,o,d=document,w=window,r='readyState',c='onreadystatechange',x=function(){n=1;clearInterval(t);while(i=e.shift())i();if(s)s[c]=''};return function(f){if(n)return f();if(!e[0]){d.addEventListener&&d.addEventListener("DOMContentLoaded",x,false);/*@cc_on@*//*@if(@_win32)d.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");s=d.getElementById("__ie_onload");s[c]=function(){s[r]=="complete"&&x()};/*@end@*/if(/WebKit/i.test(navigator.userAgent))t=setInterval(function(){/loaded|complete/.test(d[r])&&x()},10);o=w.onload;w.onload=function(){x();o&&o()}}e.push(f)}})();

// fS is the object that will include all the fontSizing code
var fS={
  cFS:12,
  // init is run when the DOM is loaded. It takes one argument, the id of an element that the fontSizing links are attached to.
  init: function (fC) {
    if (!document.getElementById(fC) || !document.createTextNode) { return; }
    // Read a cookie if it has already been set and set the font size accordingly
    if (UBUtils.rCookie("fS")) {
      fS.cFS = parseInt(UBUtils.rCookie("fS"));
      fS.setBodySize();
    }
    // add links and attach onclick events to fire the sizing functions
    UBUtils.addJSLink(fC,fS.incFS,"A+");
    document.getElementById(fC).appendChild(document.createTextNode('   '));
    UBUtils.addJSLink(fC,fS.decFS,"A-");
  },
  // increase font size
  incFS: function () {
    fS.cFS = fS.cFS + 1;
    fS.setBodySize();
    return false;
  },
  // decrease font size
  decFS: function () {
    fS.cFS = fS.cFS - 1;
    fS.setBodySize();
    return false;
  },
  // set the body size and set a cookie for persistance
  setBodySize: function() {
    var p = document.getElementById('storyContent');
    p.style.fontSize =  fS.cFS + 'px';
    UBUtils.cCookie("fS",fS.cFS,30);
  }
}


// Utility functions, including cookies and adding a link to the document with an onclick event
var UBUtils={
  cCookie: function (name,value,days) {
	if (days) {
	  var date = new Date();
	  date.setTime(date.getTime()+(days*24*60*60*1000));
	  var expires = "; expires="+date.toGMTString();
	} else { var expires = ""; }
	document.cookie = name+"="+value+expires+"; path=/";
  },
  rCookie: function (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;
  },
  eCookie: function(name) { UBUtilscCookie(name,"",-1); },
  
  addJSLink: function (elementId, onClickFunction, linkText) {
	var element = document.getElementById(elementId);
	var link = document.createElement("a");
	var linkText = document.createTextNode(linkText);
	link.appendChild(linkText);
	link.onclick = onClickFunction;
	link.href="#"+elementId;
	element.appendChild(link);
  }
}

// add the onload event, change "fontControls" to the id of the element you want the resizing links to appear in.
addDOMLoadEvent(function() {fS.init("jsFontResize")});
