/*
This script creates two buttons to increase or descrease the font sizes on the page, and a
to return the text to its original size.

To enable:
	-give an id="fontSizeUp" to the enlarge text button
	-give an id="fontSizeDown" to the shrink text button
	-give an id="fontSizeZero" to the original size button
	-apply onload="initResizeButtons()" to the body tag
	-in the below variable, write (in quotes) the id of the div whose content you would like resized
*/
	var resizeId = "maincontent"; //enter the  id of the element whose text you wish to resize
/*
Future improvements (coming soon!):
	-adjust line-height as well as text size
	-create size information if the font size is undeclared
	
	***For this script to work, all text must have a font size declared somewhere within the stylesheet
	   or style attribute!***
	
	textResizeButton_v3_divs.js is copyright (c) James C. Childress and Jonathan S. Childress, 2008
*/
	var emIncrement = .1;
	var pxIncrement = 2;
	var ptIncrement = 1;
/*
	The three above variables are used to determine the rate of resize per button click.
	There is a different variable for sizes defined through multiples, pixels, or points. 
	Adjust the increments to increase or decrease the resize rate.
*/

	getStyle = function (el,stylePropMoz,stylePropIE) {;
		if (el.currentStyle)
			var y = el.currentStyle[stylePropIE];
		else if (window.getComputedStyle)
			var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(stylePropMoz);
		return y;
	}

	fsize = function(resize) {
	
	var classArray = document.getElementById(resizeId).getElementsByTagName('*');
	
		for (i=0; i<classArray.length; i++) {
			var vsize = getStyle(classArray[i],"font-size","fontSize");
			var numsize = parseInt(vsize);
			var funit = "px";
			var increment = 1;
			
			if (vsize.indexOf("em") != -1) {
				funit = "em";
				increment = emIncrement;
			}
			else if (vsize.indexOf("pt") != -1) {
				funit = "pt";
				increment = ptIncrement;
			}
			else {
				funit = "px"
				increment = pxIncrement;
			}
			
			if (resize == "up") 
				vsize = (numsize+increment) + funit;
			else
				vsize = (numsize-increment) + funit;
			
			classArray[i].style.fontSize = vsize;	
		}
	}

	initResizeButtons = function() {
		
	var classArray = document.getElementById(resizeId).getElementsByTagName('*');
		var vsize = new Array();
		
		for (i=classArray.length-1; i>=0; i--) {
			vsize[i] = getStyle(classArray[i],"font-size","fontSize");			
		}
	
		u = document.getElementById("fontSizeUp");
		u.onclick = function () {fsize('up');}	
		if (u.captureEvents) u.captureEvents(Event.CLICK);
			
		d = document.getElementById("fontSizeDown");
		d.onclick = function() {fsize('down');}
		if (d.captureEvents) d.captureEvents(Event.CLICK);
		
		z = document.getElementById("fontSizeZero");
		z.onclick = function() {
			for (i=classArray.length-1; i>=0; i--) {
				classArray[i].style.fontSize = vsize[i];
			}
		}
		if (z.captureEvents) z.captureEvents(Event.CLICK);
	}
