/*
 * A 'class' to resize fonts on a website.
 * tijdsbesteding: 
 * 20/11: 2,5 uur
 */

// some default values for the instance variables
// This array will hold all the tags that we want to affect with a text size change
var tags = new Array('div','td','tr','p','b','span','table','strong','emphasis','a','h1','h2','h3','pre','sub','sup','i','th','cp','ul','ol','li','dt','dd');
// font size values in pixels
var pixelArray =  new Array('10','12','16','20','24','30','40');
// font size values in em
var emArray =  new Array('0.7','0.9','1.0','1.5','2.0','2.5','3');
// the initial font-size
var initSize = 0;
// exclude these classes from resizing
var excludes =  new Array('exclude');

/*
 * function to set all the instance vars at once.
 */
function fontConstruct(t, p, e, i, x) {
	this.tags = t;
	this.pixelArray = p;
	this.emArray = e;
	this.initSize = i;
	this.excludes = x;
}
	
/*
 * function to change the font-size
 */
function fontSetSize(size, unit) {
	if (!document.getElementById) {
		return;
	}

	if (size < 0 ) {
		size = 0;
	}
	
	// assumes that pixelArray and emArray have the same length
	if (size > pixelArray.length ) {
		size = pixelArray.length - 1;
	}
	docBody = document.getElementsByTagName('body')[0];
	
	for (i = 0 ; i < tags.length ; i++ ) {
		// get all elements with by tag name tags[i]
		getAllTags = docBody.getElementsByTagName(tags[i]);
		// set the size for all found elements
		for (k = 0 ; k < getAllTags.length ; k++) {
			var exclude = false;
			for(m = 0; m < this.excludes.length; m++){
				var re = new RegExp("\\b" + excludes[m] + "+\\b", "i");
				if(getAllTags[k].className.match(re)){
					exclude = true;
					break;
				}
			}
			if (!exclude){
				getAllTags[k].style.fontSize = (unit=='px') ? pixelArray[size]+unit: emArray[size]+unit;
			}
		}
	}
}

/*
 * resizes the font to the original size.
 */
function fontResetSize() {
	fontSetSize(initSize, 'px')
}