/* 
========================================================================================================= CREDITS
Copyright 	: Copyright (c) 2008 JPL & Air-X-Changers HARSCO. All Rights Reserved.
Author(s) 	: Larry Daughenbaugh - ldaugh@jplcreative.com 
Date    	: 10/13/2008 
Notes     	: JavaScript file for handling various events ... onLoad, onClick, etc
========================================================================================================= CHANGE LOG
Date		Name			Desc
---			---				---
========================================================================================================= BEGIN JAVASCRIPT
*/
/* ====================================================================================================== SWAP/RESTORE IMAGE */
function restoreImg() {
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) {
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function swapImg() {
	var i,j=0,x,a=swapImg.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* ====================================================================================================== DROPDOWN JUMP MENU */
function jumpMenu(targ,selObj,restore){
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}

/* ====================================================================================================== 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;

/* ====================================================================================================== FUNCTIONS TO BE LOADED ON PAGE LOAD */
/* =========================================================== IMAGE PRELOADER */
/* NOT USED
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];
    }
}
*/

/* ====================================================================================================== LOAD FLASH FILES */
function loadFlash() {
	if (document.getElementById('slideshow') != null) {
		var flashvars = { };
        var params = {
            wmode: "transparent"
        };
        var attributes = {};

		swfobject.embedSWF("/lib/swf/home.swf", "slideshow", "561", "191", "9.0.0", "/lib/swf/expressInstall.swf", flashvars, params, attributes);
		if (document.getElementById('slideshow-alt') != null) {
		    document.getElementById('slideshow-alt').style.visibility = "visible";
		}

		// LOAD FAN ANIMATION IN LOGO AREA ON HOME PAGE ONLY
		if (document.getElementById('logo-home') != null) {
		    var flashvars = { };
            var params = {
                wmode: "opaque"
            };
            var attributes = {};

		    swfobject.embedSWF("/lib/swf/preloadFan.swf", "logo-home", "196", "191", "9.0.0", "/lib/swf/expressInstall.swf", flashvars, params, attributes);
		    if (document.getElementById('logo-alt') != null) {
		        document.getElementById('logo-alt').style.visibility = "visible";
		    }
		}
    }
    // LOAD REQUEST A QUOTE
	if (document.getElementById('request-quote') != null) {
		var flashvars = { };
        var params = {
            wmode: "transparent"
        };
        var attributes = {};

		swfobject.embedSWF("/lib/swf/preloader.swf", "request-quote", "549", "440", "9.0.0", "/lib/swf/expressInstall.swf", flashvars, params, attributes);
		if (document.getElementById('request-quote-alt') != null) {
		    document.getElementById('request-quote-alt').style.visibility = "visible";
		}
    }
	// LOAD TICKER
	if (document.getElementById('ticker') != null) {
		var flashvars = { };
        var params = {
            wmode: "transparent"
        };
        var attributes = {};

        document.getElementById("ticker-class").className = "callout-ticker-flash";
		swfobject.embedSWF("/lib/swf/ticker.swf", "ticker", "171", "140", "9.0.0", "/lib/swf/expressInstall.swf", flashvars, params, attributes);
		if (document.getElementById('ticker-alt') != null) {
            document.getElementById("ticker-class").className = "callout-ticker";
		    document.getElementById('ticker-alt').style.visibility = "visible";
		}
    }
	// LOAD FROM THE BEGINNING TIMELINE
	if (document.getElementById('timeline') != null) {
		var flashvars = { };
        var params = {
            wmode: "transparent"
        };
        var attributes = {};

		swfobject.embedSWF("/lib/swf/timeline.swf", "timeline", "550", "550", "9.0.0", "/lib/swf/expressInstall.swf", flashvars, params, attributes);
		if (document.getElementById('timeline-alt') != null) {
		    document.getElementById('timeline-alt').style.visibility = "visible";
		}
    }
}

/* =========================================================== DROPDOWN MENUS */
function loadDropDownMenus() {
	var lnkContactUs = document.getElementById('lnkContactUs');
	var lnkAboutUs = document.getElementById('lnkAboutUs');

	if (lnkAboutUs != null) {
        if (window.event) {
			lnkAboutUs.onmouseover = function(e) { dropdownmenu(this, window.event, menu_about, '120px'); };
			lnkAboutUs.onmouseout = function() { delayhidemenu(); };
		} else {
			lnkAboutUs.onmouseover = function(e) { dropdownmenu(this, e, menu_about, '100px'); };
			lnkAboutUs.onmouseout = function() { delayhidemenu(); };
		}
    }
	if (lnkContactUs != null) {
        if (window.event) {
			lnkContactUs.onmouseover = function(e) { dropdownmenu(this, window.event, menu_contact, '150px'); };
			lnkContactUs.onmouseout = function() { delayhidemenu(); };
		} else {
			lnkContactUs.onmouseover = function(e) { dropdownmenu(this, e, menu_contact, '150px'); };
			lnkContactUs.onmouseout = function() { delayhidemenu(); };
		}
    }
}

/* ====================================================================================================== SHOW/HIDE ITEMS */
function showHide() {
	var currentURL = window.location.search;
	var queryQuality = currentURL.indexOf("?tab=quality");
	var queryGreenStart = currentURL.indexOf("?tab=green");
	var queryHarsco = currentURL.indexOf("?tab=harsco");

	if (queryQuality >= 0) { showHide("header0"); }
	if (queryGreenStart >= 0) { showHide("header5"); }
	if (queryHarsco >= 0) { showHide("header6"); }
	
    function showHideAll(content, header, status) {			
        var i = 0;
		
		if (status == "show") {
            while(document.getElementById(content + i)) {
                document.getElementById(content + i).style.display = "block";
				document.getElementById(header + i).src = "/lib/img/tabs/tab-open.gif";
                i++;
            }
        } else {
            while(document.getElementById(content + i)) {
                document.getElementById(content + i).style.display = "none";
				document.getElementById(header + i).src = "/lib/img/tabs/tab-closed.gif";
                i++;
            }
        }
    }
	var btnShowAll = document.getElementById('btnShowAll');
	if (btnShowAll != null) {
        btnShowAll.onclick = function() {
            showHideAll("content", "header", "show")
		};
    }
	var btnHideAll = document.getElementById('btnHideAll');
	if (btnHideAll != null) {
        btnHideAll.onclick = function() {
            showHideAll("content", "header", "hide")
		};
    }

    function showHide(cid) {
		var ContentID = cid.replace("header","content");

		if (document.getElementById(ContentID).style.display == "none" || document.getElementById(ContentID).style.display == "") {
			document.getElementById(ContentID).style.display = "block";			
            document.getElementById(cid).src = "/lib/img/tabs/tab-open.gif";
        } else {
            document.getElementById(ContentID).style.display = "none";
            document.getElementById(cid).src = "/lib/img/tabs/tab-closed.gif";
	    }
    }

    function countContainers(header) {			
        i = 0;
        while(document.getElementById(header + i)) { i++; }
        return i;
    }

	var ContainerListeners = countContainers("header");
    if (ContainerListeners > 0) {
        var i = 0;
		var arrContainerListners = new Array();
        while(i < ContainerListeners) {
	        var temp = document.getElementById('header'+i);

			temp.onclick = function() {
				showHide(this.id);
			}
	        i++;
        }
	}
}

function divDimensions() {
    var lightbox = document.getElementById("lightbox");
	if (lightbox != null) {
	    lightbox.style.visibility = "hidden";
	    lightbox.style.display = "block";

        //alert(lightbox.offsetWidth);
        //alert(lightbox.offsetHeight);

	    //lightbox.style.width = lightbox.offsetWidth;
	    lightbox.style.height = lightbox.offsetHeight;

        //var marLeft = "-" + Math.ceil(lightbox.offsetWidth / 2) + "px";
        var marTop = "-" + Math.ceil(lightbox.offsetHeight / 2) + "px";
        //alert(marLeft);
        //alert(marTop);

	    lightbox.style.marginTop = marTop;
	    //lightbox.style.marginLeft = marLeft;

	    lightbox.style.visibility = "";
	    lightbox.style.display = "none";
    }
}

/* ====================================================================================================== CALL FUNCTIONS TO BE LOADED */
addOnLoad("loadFlash");
addOnLoad("loadDropDownMenus");
addOnLoad("showHide");
//addOnLoad("divDimensions");

