/* 
========================================================================================================= CREDITS
Copyright 	: Copyright (c) 2008 JPL & HARSCO. All Rights Reserved.
Author(s) 	: Larry Daughenbaugh - ldaugh@jplcreative.com 
Date    	: 12/2/2008 
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;

/* ====================================================================================================== LOAD MODALS */
function loadModals() {
	/* 
	* AUTOMATED
	* init_modal() SEARCHES FOR ALL MODALS AND ATTACHES EVENT LISTENERS 
	*/
	init_modal();

	/* 
	* MANUAL
	* USE THE EXAMPLE BELOW TO ATTACH EVENT LISTENERS MANUALLY, INCREMENT THE COUNTER FOR EACH ADDITION
	* THE SECOND PARAMETER SHOULD BE SET TO TRUE ONLY IF YOU NEED TO DYNAMICALLY DETERMINE THE HEIGHT/WIDTH
	*/
	modal_manual0 = document.getElementById('modal0_manual_open');
	if (modal_manual0 != null) {
		modal_manual0.onclick = function() {
			new_modal_manual0 = new modal('modal0_manual',true);
			new_modal_manual0.activate();
			return false;
		}
	}
}

/* ====================================================================================================== LOAD FLASH FILES */
function loadFlash() {
	// GLOBAL PROFILE
	if (document.getElementById('flash0') != null) {
        var flashvars = {};
        var params = { wmode: "opaque" };
        var attributes = {};

		swfobject.embedSWF("lib/swf/flash0.swf", "flash0", "800", "200", "9.0.0", "lib/swf/expressInstall.swf", flashvars, params, attributes);
		if (document.getElementById('flash0-alt') != null) {
			document.getElementById('flash0-alt').style.visibility = "visible";
		}
	}
	if (document.getElementById('flash1') != null) {
        var flashvars = {};
        var params = { wmode: "opaque" };
        var attributes = {};

		swfobject.embedSWF("lib/swf/flash1.swf", "flash1", "500", "500", "9.0.0", "lib/swf/expressInstall.swf", flashvars, params, attributes);
	}
}

function enable_modal_stylesheet() {
	var ss;
	var ss_exists = false;
	var i = 0;
	while (i < document.styleSheets.length) {
		ss = document.styleSheets[i];
		if (ss.href.indexOf("/cstore/lib/css/modalsprint.css") > -1) ss_exists = true;
		i++;
	}
	
	if (ss_exists) {
		i = 0;
		while (i < document.styleSheets.length) {
			ss = document.styleSheets[i];
			if (ss.href.indexOf("/cstore/lib/css/modalsprint.css") > -1) ss.disabled = false;
			i++;
		}
	} else {
		// ADD PRINT STYLESHEET (FOR MODAL)
		var new_print_ss = document.createElement('link');
		new_print_ss.rel = 'stylesheet';
		new_print_ss.type = 'text/css';
		new_print_ss.media = 'print';
		new_print_ss.href = '/cstore/lib/css/modalsprint.css';
		document.getElementsByTagName("head")[0].appendChild(new_print_ss);
	}
}

/* ====================================================================================================== CALL FUNCTIONS TO BE LOADED */
addOnLoad("loadModals");
addOnLoad("loadFlash");
if(window.location.href.indexOf("promotion.aspx") != -1) {
	enable_modal_stylesheet();
}


