/* 
================================================================================================================================ CREDITS
Copyright 	: Copyright (c) 2009 JPL & The Hershey Company. All Rights Reserved.
Author(s) 	: Larry Daughenbaugh - ldaugh@jplcreative.com
Date      	: 11/4/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;

// ---------------------------------------------------------- WINDOW LOCATION
var url = window.location.toString();


/* ============================================================================================================================= CALL FUNCTIONS TO BE LOADED */
addOnLoad("load_flash");
addOnLoad("home_page_slides");
if(url.indexOf("promotion.aspx") != -1) {
	enable_modal_stylesheet();
}
/* ====================================================================================================== LOAD MODALS */

function load_flash() {
	if (document.getElementById('flash-content') != null) {
	    var flashvars = {};
        var params = { allowScriptAccess : "always", base : ".", scale : "exactfit" };
        var attributes = {};

		swfobject.embedSWF("start.swf", "flash-content", "960", "582", "9.0.0", "lib/swf/expressInstall.swf", flashvars, params, attributes);
		if (document.getElementById('flash-content-alert') != null) {
			document.getElementById('flash-content-alert').style.visibility = "visible";
		}
	}
}

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);
	}
}

var myTimer = null;
var defaultSection = 'slide0-pane';
var slideshowScroller = 'slideshow-scroller';

// USED TO AUTO SCROLL THE HOME PAGE SLIDE AREA UNTIL A TAB IS CLICKED
function autoScroll() {
	ScrollArrow('right','slidebuttons',slideshowScroller,defaultSection);
}

function home_page_slides() {
	if (document.getElementById(slideshowScroller) != null) {
		var tab0 = 'slide0-tab';
		var tab1 = 'slide1-tab';
		var tab2 = 'slide2-tab';
		var slideshow_previous = "slideshow_previous";
		var slideshow_next = "slideshow_next";

		document.getElementById(tab0).onclick = function() {
			ScrollSection('slide0-pane', slideshowScroller, defaultSection);
			return false;
		}
		document.getElementById(tab1).onclick = function() {
			ScrollSection('slide1-pane', slideshowScroller, defaultSection);
			return false;
		}
		document.getElementById(tab2).onclick = function() {
			ScrollSection('slide2-pane', slideshowScroller, defaultSection);
			return false;
		}
		
		if (url.indexOf('slide=') > -1) {
			var slide = url.split('slide=')[1];
			ScrollSection(slide, slideshowScroller, defaultSection);
		} else {
			myTimer = setTimeout(autoScroll,7000);
		}
	}
}


