// JavaScript Document

// goal is to have the following
// call the function by textSizer(), looking like this:
// textSizer('add', '12', 'px') 
// first string can be add, subtract, multiply or divide
// second string is the incremental value
// third string is the affected incremental, be it pixels, points, percentage, etc.


// extra code snippets
// var classname = myTags[i].getAttribute("class");
	// document.getElementById("status").innerHTML = myTags.length;
	//myTags = myTags + document.getElementsByTagName("li");
	/*
	for (i = 0; i < myTags.length; i++) {
		currSize = parseInt(myTags[i].style.fontSize);
		newSize = parseInt(currSize) + parseInt(myIncr);
		myTags[i].style.fontSize = newSize + "px";
		// myTags[i].style.fontSize = 22 + "px";
	}
	*/
	
	/*
	if(x != 0) {
		document.getElementById('statusArea').innerHTML = document.getElementById('statusArea').innerHTML + " :: " + newSize; 
	} else {
		document.getElementById('statusArea').innerHTML = newSize;
	}
	*/
	
if(!(currBounding)) {
	var currBounding = 0;		
}


function textSizer(myOper, myIncr, myIncrType, myLineIncr) {
	// Init variables
	if(!highBound) {
		var highBound = 2;
	} if(!lowBound) {
		var lowBound = 0;
	} if(!myIncr) {
		var myIncr = 2;	
	} if(!myIncrType) {
		var myIncrType = "px";	
	}

	
	
	var myTags = new Array(0);

	// All the tags within which text will be affected
	var workingTags = new Array("li", "p", "a", "ul", "ol", "td", "div", "span", "h1", "h2", "h3", "h4", "h5", "h6", "font", "b", "i", "u", "strong");
	
	// Load all tags into a large array using the list in workingTags
	for(var i = 0; i < workingTags.length; i++) {
		thisarr = document.getElementsByTagName(workingTags[i]);
		switch(myOper) {
			case "add":
				if(currBounding < highBound) {
					for(x = 0; x < thisarr.length; x++) {
						if(thisarr[x].currentStyle) {
							// We are using Internet Explorer
							newSize = parseInt(thisarr[x].currentStyle.fontSize) + parseInt(myIncr);
							if(myLineIncr) {
								newLineSize = parseInt(thisarr[x].currentStyle.lineHeight) + parseInt(myLineIncr);	
							}
						} else if(window.getComputedStyle) {
							// We are using a Netscape compatible browser
							newSize = parseInt(window.getComputedStyle(thisarr[x], "").getPropertyValue("font-size")) + parseInt(myIncr);
							if(myLineIncr) {
								newLineSize = parseInt(window.getComputedStyle(thisarr[x], "").getPropertyValue("line-height")) + parseInt(myLineIncr);	
							}
						} else if(document.defaultView && document.defaultView.getComputedStyle) {
							// this seems to hit safari when nothing else does...
							if(parseInt(document.defaultView.getComputedStyle(thisarr[x], null).getPropertyValue('font-size')) != null) {
								var newSize = parseInt(document.defaultView.getComputedStyle(thisarr[x], null).getPropertyValue('font-size')) + parseInt(myIncr) + myIncrType;
							}
							if(myLineIncr) {
								newLineSize = parseInt(document.defaultView.getComputedStyle(thisarr[x], null).getPropertyValue('line-height')) + parseInt(myLineIncr);
							}
						} else if(thisarr[x].style.fontSize != "" && thisarr[x].style.fontSize != null) { 
							// Style is embedded into the tag
							newSize = parseInt(thisarr[x].style.fontSize) + parseInt(myIncr);
							if(myLineIncr) {
								newLineSize = parseInt(thisarr[x].style.lineHeight) + parseInt(myLineIncr);	
							}
						}
						// alert("old size: " + thisarr[x].style.fontSize + " and new size: " + newSize);
						// alert("x: " + x + "i: " + i);
						if(newSize) {
							thisarr[x].style.fontSize = parseInt(newSize) + "px";
						}
						if(myLineIncr) {
							thisarr[x].style.lineHeight = parseInt(newLineSize) + "px";
						}
					}
				}
				break;
			case "subtract":
				if(currBounding > lowBound) {
					for(x = 0; x < thisarr.length; x++) {
						if(thisarr[x].currentStyle) {
							// We are using Internet Explorer
							newSize = parseInt(thisarr[x].currentStyle.fontSize) - parseInt(myIncr);
							if(myLineIncr) {
								newLineSize = parseInt(thisarr[x].currentStyle.lineHeight) - parseInt(myLineIncr);	
							}
						} else if(window.getComputedStyle) {
							// We are using a Netscape compatible browser
							newSize = parseInt(window.getComputedStyle(thisarr[x], "").getPropertyValue("font-size")) - parseInt(myIncr);
							if(myLineIncr) {
								newLineSize = parseInt(window.getComputedStyle(thisarr[x], "").getPropertyValue("line-height")) - parseInt(myLineIncr);	
							}
						} else if(document.defaultView && document.defaultView.getComputedStyle) {
							// this seems to hit safari when nothing else does...
							if(parseInt(document.defaultView.getComputedStyle(thisarr[x], null).getPropertyValue('font-size')) != null) {
								var newSize = parseInt(document.defaultView.getComputedStyle(thisarr[x], null).getPropertyValue('font-size')) - parseInt(myIncr) + myIncrType;
							}
							if(myLineIncr) {
								newLineSize = parseInt(document.defaultView.getComputedStyle(thisarr[x], null).getPropertyValue('line-height')) - parseInt(myLineIncr);
							}
						} else if(thisarr[x].style.fontSize != "" && thisarr[x].style.fontSize != null) { 
							// Style is embedded into the tag
							newSize = parseInt(thisarr[x].style.fontSize) - parseInt(myIncr);
							if(myLineIncr) {
								newLineSize = parseInt(thisarr[x].style.lineHeight) - parseInt(myLineIncr);	
							}
						}
						// alert("old size: " + thisarr[x].style.fontSize + " and new size: " + newSize);
						// alert("x: " + x + "i: " + i);
						if(newSize) {
							thisarr[x].style.fontSize = parseInt(newSize) + "px";
						}
						if(myLineIncr) {
							thisarr[x].style.lineHeight = parseInt(newLineSize) + "px";
						}
					}
				}
				break;	
		}	
		// myTags.concat(thisarr);		
	}
	
	if(myOper == "add" && currBounding < highBound) {
		currBounding++;
	} 
	if(myOper == "subtract" && currBounding > lowBound) {
		currBounding--;	
	}
}