$(document).ready(function() {
	/**
	 * Change the font-size of the page in three steps.
	 *
	 */
	var textChanger = {
		defaultFS: '1.2em',
		increasedFS: '1.6em',
		decreasedFS: '.8em',
		increase: function() {
			$('body').css('font-size', this.increasedFS);
			this.box('increase');
		},
		decrease: function() {
			$('body').css('font-size', this.decreasedFS);
			this.box('decrease');
		},
		reset: function() {
			$('body').css('font-size', this.defaultFS);
			this.box('reset');
		},
		box: function(elId) {
			$('body').find('ul.resizer li').each(function() {
				$(this).removeClass('active');
			});
			$('#'+elId).parent().addClass('active');
		},
		init: function() {
			cookieFontSize = this.getCookie();
			if(cookieFontSize == 'decreased') this.decrease();
			if(cookieFontSize == 'increased') this.increase();

			$('body').delegate('#decrease', 'click', function(e) {
				textChanger.decrease();
				textChanger.updateCookie('decreased');
			});
			$('body').delegate('#increase', 'click', function(e) {
				textChanger.increase();
				textChanger.updateCookie('increased');
			});
			$('body').delegate('#reset', 'click', function(e) {
				textChanger.reset();
				textChanger.updateCookie('normal');
			});
		},
		updateCookie: function(vl)	{
			var today = new Date();
			var exp = new Date(today.getTime() + (365*24*60*60*1000));
			document.cookie = 'textChangerL=size=' + vl + ';' +'expires=' + exp.toGMTString() + ';' +'path=/';
		},
		getCookie: function()	{
			var cname = 'textChangerL=size=';
			var start = document.cookie.indexOf(cname);
			var len = start + cname.length;
			if ((!start) && (cname != document.cookie.substring(0,cname.length))) {return null;}
			if (start == -1) return null;
			var end = document.cookie.indexOf(";",len);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(len, end));
		}
	};

	textChanger.init();
});

