/* 
========================================================================================================= CREDITS
Copyright 	: Copyright (c) 2009 JPL & Pinnacle Health. All Rights Reserved.
Author(s) 	: Larry Daughenbaugh - ldaugh@jplcreative.com
Date      	: 3/16/2009
Notes     	: JavaScript file for handling various events ... onLoad, onClick, etc
========================================================================================================= CHANGE LOG
Date		Name			Desc
---			---				---
========================================================================================================= BEGIN JAVASCRIPT
*/
/* ====================================================================================================== MULTIPLE ONLOAD HANDLER */
var onLoadFunctions = new Array();
var iloadFunction = 0;

// Pass each function that needs to load
function addOnLoad(func) {
    onLoadFunctions[iloadFunction] = func;
    iloadFunction++;
}
// Loops through all of the functions that were added
function loadAllFunctions() {
    for(i=0; i < onLoadFunctions.length; i++) {
        eval(onLoadFunctions[i]+"()");
    }
}
// Load all of the functions that you've set
window.onload = loadAllFunctions;



/* ====================================================================================================== CALL FUNCTIONS TO BE LOADED */
addOnLoad("styleSheetSwitcher");


/* ====================================================================================================== IMAGE PRELOADER */
function preloadImages() {
    // Array of any images you want to preload 
    var ImagesToPreload = new Array();
        ImagesToPreload[0] = "";

	var graphics = new Array();
    for (iLoad=0; iLoad < ImagesToPreload.length; iLoad++) {
        graphics[iLoad] = new Image();
        graphics[iLoad].src = ImagesToPreload[iLoad];
    }
}

/* ====================================================================================================== SWTICH ACTIVE STYLESHEETS */
function styleSheetSwitcher() {
	var textSmall = document.getElementById('small')
	var textMedium = document.getElementById('medium')
	var textLarge = document.getElementById('large')
	var tipObj = document.getElementById("tooltip");

	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);

	/* UPDATE STYLE SWITCHER */
	function updateStyleSwitcher(switcherId,resetSwitcher1,resetSwitcher2) {
		if (switcherId == "" || switcherId == null) {
			textSmall.style.backgroundPosition = "0px -33px";
			textMedium.style.backgroundPosition = "0px -3px";
			textLarge.style.backgroundPosition = "0px -3px";
		} else {
			document.getElementById(switcherId).style.backgroundPosition = "0px -33px";
			if (resetSwitcher1 != "") document.getElementById(resetSwitcher1).style.backgroundPosition = "0px -3px";
			if (resetSwitcher2 != "") document.getElementById(resetSwitcher2).style.backgroundPosition = "0px -3px";
		}
	}
	updateStyleSwitcher(title,"","");

	if (textSmall != null) {
		textSmall.onmouseover = function() {
			enabletip = true;
			showTip(tipObj, "Toggle the font size of select content.");
		}
		textSmall.onmouseout = function() {
			enabletip = false;
			tipObj.style.visibility = "hidden";
			tipObj.style.left = "-9999px";
		}
		textSmall.onclick = function() {
			setActiveStyleSheet('small');
			createCookie("style","small",365);
			updateStyleSwitcher("small","medium","large");
			return false;
		}
	}
	if (textMedium != null) {
		textMedium.onmouseover = function() {
			enabletip = true;
			showTip(tipObj, "Toggle the font size of select content.");
		}
		textMedium.onmouseout = function() {
			enabletip = false;
			tipObj.style.visibility = "hidden";
			tipObj.style.left = "-9999px";
		}
		textMedium.onclick = function() {
			setActiveStyleSheet('medium');
			createCookie("style","medium",365);
			updateStyleSwitcher("medium","small","large");
			return false;
		}
	}
	if (textLarge != null) {
		textLarge.onmouseover = function() {
			enabletip = true;
			showTip(tipObj, "Toggle the font size of select content.");
		}
		textLarge.onmouseout = function() {
			enabletip = false;
			tipObj.style.visibility = "hidden";
			tipObj.style.left = "-9999px";
		}
		textLarge.onclick = function() {
			setActiveStyleSheet('large');
			createCookie("style","large",365);
			updateStyleSwitcher("large","small","medium");
			return false;
		}
	}
}

