runOnLoad.functionsQueue = new Array();
runOnLoad.isLoaded = false;

function runOnLoad(functionCall) {
	if (runOnLoad.isLoaded) functionCall();
	else runOnLoad.functionsQueue.push(functionCall);
}

runOnLoad.run = function() {
	if (runOnLoad.isLoaded) return;
	for (var i = 0; i < runOnLoad.functionsQueue.length; i++) {	
		//
		// runOnLoad.functionsQueue[i]();
		//
		try { runOnLoad.functionsQueue[i](); }		
		catch(functionError) { 
			if (functionError instanceof Error) {
				alert(functionError.name + ": " + functionError.message);
			}
		}
	}
	runOnLoad.isLoaded = true;
	delete runOnLoad.functionsQueue;
	delete runOnLoad.run;
};

if (window.addEventListener) {
	window.addEventListener("load", runOnLoad.run, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", runOnLoad.run)
} else {
	window.onload = runOnLoad.run;
}

runOnLoad(addTextSizer);

/*- Stylesheet Switcher ------------------------------------------------------*/

function addTextSizer() {
	if (!document.getElementById) return false;
	if (!document.createElement) return false;
	if (!document.createTextNode) return false;
	//
	var strapBox = document.getElementById("strapBox");
	if (!strapBox) return false;
	//
	var textSizer = document.createElement("span");
	textSizer.setAttribute("id", "textSizer");
	//
	var title = document.createTextNode("Adjust Text Size: ");
	//
	var link1 = document.createElement("a");
	link1.className = "normal current"
	link1.setAttribute("href", "#");
	var link1Text = document.createTextNode("A");
	link1.appendChild(link1Text);
	link1.onclick = function() {
		setActiveStyleSheet("default");
		link1.className = "normal current";
		link2.className = "large";
		return false;
	};
	//
	var link2 = document.createElement("a");
	link2.className = "large";
	link2.setAttribute("href", "#");
	var link2Text = document.createTextNode("A");
	link2.appendChild(link2Text);
	link2.onclick = function() {
		setActiveStyleSheet("large text");
		link1.className = "normal";
		link2.className = "large current";
		return false;
	};
	//
	textSizer.appendChild(title);
	textSizer.appendChild(link1);
	textSizer.appendChild(link2);
	//
	strapBox.appendChild(textSizer);
}

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		  a.disabled = true;
		  if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}
