
/* ====================================================================================================== MULTIPLE ONLOAD HANDLER */
var onLoadFunctions = new Array();
var iloadFunction = 0;
var memoStatus = true;

// Build page name for Omniture reporting.
// Page name built by buildPgName() function.
var curr_pgName = null; 

function buildPgName() {
	var curr_url = window.location.href.split("//");
	var path_array = curr_url[1].split("/");
	// create page name object
	build_pgName = new Object;
	build_pgName.domain = path_array[0];
	build_pgName.dir = '';
	// assign domain
	if ( build_pgName.domain.match(/hersheys/) ) { build_pgName.domain = "Hersheys"; }
	// build directory structure, append file name
	for ( i = 1; i <= path_array.length-1; i++ ) {
		if( path_array[i].indexOf("?") == -1) {
			build_pgName.dir = build_pgName.dir + ":" + path_array[i];
		}
		else {
			var tempSplit = path_array[i].split("?");
			build_pgName.dir = build_pgName.dir + ":" + tempSplit[0];
		}
	}
	// cut file extensions
	build_pgName.dir = build_pgName.dir.split(".");
	build_pgName.dir = build_pgName.dir[0]
	// if there is reference to "index" or "default", replace with "home"
	if ( build_pgName.dir.match(/index/) ) { build_pgName.dir = build_pgName.dir.replace(/index/, "home") }
	if ( build_pgName.dir.match(/default/) ) { build_pgName.dir = build_pgName.dir.replace(/default/, "home") }
	// if the last character is ":", replace with "home"
	if ( build_pgName.dir.charAt(build_pgName.dir.length-1) == ":" ) { build_pgName.dir = build_pgName.dir + "home" }
	// build page name structure
	curr_pgName = build_pgName.domain + build_pgName.dir;
}

buildPgName();

// 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 EACH FUNCTION TO LOAD */
addOnLoad("loadFlash");

/* ====================================================================================================== LOAD FLASH FILES */
function loadFlash() {
	// HERSHEY HEROES HOME PAGE
	if (document.getElementById('home_flash_replace') != null) {

        var flashvars = { };
        var params = { wmode: "transparent", base: ".", allowFullScreen: "true", allowscriptaccess: "always" };
        var attributes = { id: "website" };
		
		swfobject.embedSWF("lib/swf/Preloader.swf", "home_flash_replace", "100%", "650", "9.0.0", "/fr/twizzlers/lib/swf/expressInstall.swf", flashvars, params, attributes);
		if (document.getElementById('home_flash_alt') != null) {
			document.getElementById('home_flash_alt').style.visibility = "visible";
		}
	}
	// HERSHEY BRAND FOOTER
	if (document.getElementById('hershey-canada-brandbar') != null) {
        var flashvars = { bgColor: "0xffffff", xmlPath: "/fr/general/xml/brandbar.xml", logoPath: "/fr/general/swf/logos/", curr_pgName: curr_pgName, inputDevAccount: "hersheyintcanadadev,hersheyglobaldev", inputLiveAccount: "hersheyintcanada,hersheyglobal" };
        var params = { wmode: "transparent" };
        var attributes = {};

		swfobject.embedSWF("/fr/general/brandbar_wide.swf", "hershey-canada-brandbar", "920", "75", "9.0.0", "/fr/twizzlers/lib/swf/expressInstall.swf", flashvars, params, attributes);
		if (document.getElementById('hershey-canada-brandbar-alt') != null) {
			document.getElementById('hershey-canada-brandbar-alt').style.visibility = "visible";
		}
	}
}
