	/**
	 * Dynamic Text Resizing
	 * @author Craig McIntosh
	 * Free to use, modify, and distribute with attribution.
	 * 
	 * This operates by setting the font-size attribute on the document body,
	 * increasing/decreasing it by a given amount per application
	 * and saving the number of steps taken in the "fontSize" cookie.
	 *
	 * All text sizes below body on the page should be defined in relative units,
	 * or they will be immune to these changes!
	 * 
	 * @param base The default "zeroed-out" font-size. This will be applied upon
	 * page load for a firt-time visitor. This should match the CSS-defined 
	 * font-size on the body element.
	 * @param units "em", "px", "%", ect, modifies base.
	 * @param stepSize The amount to increase/decrease the base by each
	 * time a size change is requested.
	 * @param minSteps Optional the maximum net amount of times fontSize can be decrimented.
	 * @param maxSteps Optional the maximum net amount of times fontSize can be incrimented.
	 */
	function TextSizer(base, units, stepSize, minSteps, maxSteps) {
		
		this.base = base;
		this.units = units;
		this.stepSize = stepSize;
		this.minSteps = minSteps * -1;
		this.maxSteps = maxSteps;
		this.cookie = new CookieHandler('fontSize', 30);
				
		this.apply = function(steps) {
			document.body.style.fontSize = (base + (steps * this.stepSize)) + units;
		};
				
		this.getPreset = function() {
			var steps = parseInt(this.cookie.getCookie());
			if(isNaN(steps)) steps = 0;
			return steps;
		};
		
		this.increase = function() {
			steps = this.getPreset();
			if(steps != this.maxSteps) {
				steps++;
				this.apply(steps);
				this.cookie.setCookie(steps);
			}
		};
		
		this.decrease = function() {
			steps = this.getPreset();
			if(steps != this.minSteps) {
				steps--;
				this.apply(steps);
				this.cookie.setCookie(steps);
			} 
		};
				
		// When initialized, apply from cookie or set to base
		var preset = this.getPreset();
		this.apply(preset);
	}
	
	
	// Cookie handler class	based on http://www.quirksmode.org/js/cookies.html
	
	function CookieHandler(name, days) {
	
		this.name = name;
		this.days = days;
	
		this.setCookie = function(value, name, days) {
			if(!days) days = this.days;
			if(!name) name = this.name;
			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=/";
		}
		
		this.getCookie = function(name) {
			if(!name) name = this.name;
			var name_eq = 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(name_eq) == 0) return c.substring(name_eq.length,c.length);
			}
			return null;
		}
		
	}
	
	// End CookieHandler
		
		
	// Set-Up
	// If not using your preferred cross-browser listener when needed, use window.onload.
	// If not using window.onload, at least ensure script is included well after #increase and #decrease.

	//window.onload = function() { 
		var textSizer = new TextSizer(100, '%', 50, 0, 3);
		document.getElementById('decrease').onclick =
			function(){textSizer.decrease(); return false;};
		document.getElementById('increase').onclick =
			function(){textSizer.increase(); return false;};
	//};


