/*
FontSizer v2.1mod
Javascript to dynamically change font sizes on a web page.
Coded by Phil Nash of www.unintentionallyblank.co.uk
Cookies script courtesy of http://www.quirksmode.org/js/cookies.html
Measuring the current font size courtesy of http://www.alistapart.com/articles/fontresizing

-- 20080206
* Removed JS link creation
* Replaced addDOMLoadEvent with jQuery call
* Call init with jQuery selector of parent to size
-- 20080207
* Fixed IE6 issue by appending, not prepending, size detection span to body
-- 20080220
* Fixed sizing by ignoring offset calculation and defaulting to 1
-- Marcus Campbell, Tugboat Media
*/

var fS = {
    ele:  null,
    iFS:  null,
    cFS:  null,
    init: function (ele) {
        fS.ele = ele;
        if (UBCookie.read("fS")) {
            var sizes = UBCookie.read("fS").split(",");
            fS.iFS = sizes[0] * 1;
            fS.cFS = sizes[1] * 1;
            fS.setBodySize();
        } else {
            fS.iFS = 1;
            fS.cFS = 1;
            UBCookie.create("fS", fS.iFS + "," + fS.cFS, 30);
        }
    },
    incFS: function () {
        fS.cFS = fS.cFS * 1.25;
        fS.setBodySize();
        return false;
    },
    decFS: function () {
        fS.cFS = fS.cFS * 0.8;
        fS.setBodySize();
        return false;
    },
    rFS: function () {
        fS.cFS = fS.iFS;
        fS.setBodySize();
        return false;
    },
    setBodySize: function() {
        $(fS.ele).css("font-size", fS.cFS + "em");
        UBCookie.create("fS", fS.iFS + "," + fS.cFS, 30);
    }
}

var UBCookie={
  create: 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=/";
  },
  read: 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;
  },
  erase: function(name) { createCookie(name,"",-1); }
}

$(function() { fS.init("#main"); });