/*
FontSizer v2.0
Javascript to dynamically change font sizes on a web page.
Coded by Phil Nash of www.unintentionallyblank.co.uk
Modified by Justin Chow of www.chakracentral.com
Cookies script courtesy of http://www.quirksmode.org/js/cookies.html
Measuring the current font size courtesy of http://www.alistapart.com/articles/fontresizing

** Please don't remove this notice **

See http://www.unintentionallyblank.co.uk/ for full details

To use the code, upload this file to your site's main directory and add the following lines to the <head> element of your site:

<script type="text/javascript" src="fontSizer.js"></script>
  
*/

// 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={
  iFS:null,
  cFS:null,
  // 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")) {
      var sizes = UBUtils.rCookie("fS").split(",");
      fS.iFS = sizes[0]*1; 
      fS.cFS = sizes[1]*1;
      fS.setBodySize();
    } else {
    // else create an element and measure it to see the current font size
      var el = document.createElement('span');
      el.innerHTML = "&nbsp;";
      el.style.position = "absolute";
      el.style.left = "-9999px";
      el.style.lineHeight = "1em";
      document.body.insertBefore(el,document.body.firstChild);
      fS.iFS = el.offsetHeight/16;
      fS.cFS = fS.iFS;
      UBUtils.cCookie("fS",fS.iFS+","+fS.cFS,30);
    }
    // add links and attach onclick events to fire the sizing functions
    UBUtils.addJSLink(fC,fS.incFS,"Text Size ");
/* 
    UBUtils.addJSLink(fC,fS.rFS," R ");
    UBUtils.addJSLink(fC,fS.decFS," A-");
*/	
  },
  // increase font size
  incFS: function () {
    fS.cFS = fS.cFS*1.2;
	if (fS.cFS > 1.3){	
		fS.cFS = fS.iFS;
	}
    fS.setBodySize();
    return false;
  },

/*
  // decrease font size
  decFS: function () {
    fS.cFS = fS.cFS*0.8333;
    fS.setBodySize();
    return false;
  },
  // reset to the original font size
  rFS: function () {
    fS.cFS = fS.iFS;
    fS.setBodySize();
    return false;
  },
*/
  
  // set the body size and set a cookie for persistance
  setBodySize: function() {
    document.body.style.fontSize = fS.cFS + 'em';
    UBUtils.cCookie("fS",fS.iFS+","+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("fontControls")});