//
// dsp_flash_homepage.js
// Display flash file **filename** if client's browser supports it.
//
// Note: create seperate instances of this file for different flash files.
//
// $Log $
// 04/17/09 - D. Butler: changed this completely, now uses PINT.util.flash!
// 03/27/03 - C. Ducker: added image map parameter to display image function
// 02/25/03 - C. Ducker: added class name and alt text parameter to image display.
//                       updated dependency list.
// 09/10/02 - C. Ducker: initial version.
//
var PINT = { util: {}};
PINT.util.flash = function() {
    this.aParams = arguments[0] || [];
    this.sId = this.aParams.id || "";
    this.sSwf = this.aParams.swf || "";
    this.iWidth = this.aParams.width || 0;
    this.iHeight = this.aParams.height || 0;
	this.sAlign = this.aParams.align || "middle";
    this.iVersion = this.aParams.version || 6;
    this.sImageMap = this.aParams.imagemap || "";
    this.sCodeBase = this.iVersion + ",0,0,0";
    this.sDefaultImage = this.aParams.defaultimage || "";
	this.sNoScriptId = this.aParams.noscriptId || "";
	this.sAltText = this.aParams.alttext || "Please <a href='http://www.macromedia.com/go/getflashplayer'>upgrade your Flash Player</a>.";
	this.sBypassText = this.aParams.bypasstext || "";
    this.sRedirectUrl = this.aParams.redirecturl || "";
    this.sBgColor = this.aParams.bgcolor || "";
    this.aParams = {};
    this.aVars = {};

    /**
    @item {Method} addParam
    @parent PINT.util.flash
    @info Adds a name/value parameter to the resulting object and embed tag
    @param {String} sName The parameter name to add
    @param {String} sValue The value to add
    @sample
    oSwf.addParam('wmode', 'transparent');
    */
    this.addParam = function(sName, sValue) {
        this.aParams[sName] = sValue;
    };

    /**
    @item {Method} getParams
    @parent PINT.util.flash
    @info Returns an array of all parameters
    @param  {String} sName The name of the variable to get
    @return {Array} Parameters
    */
    this.getParams = function(sName) {
        if (sName) {
            return this.aParams[sName];
        } else {
            return this.aParams;
        }
    };

    /**
    @item {Method} addVariable
    @parent PINT.util.flash
    @info Adds a name/value pair to the flash vars
    @param {String} sName The variable name to add
    @param {String} sValue The value to add
    @sample
    oSwf.addVariable('selectedColor', 'blue');
    */
    this.addVariable = function(sName, sValue) {
        this.aVars[sName] = sValue;
    };

    /**
    @item {Method} getVars
    @parent PINT.util.flash
    @info Gets all of the flashvars as an array
    @param {String} sName Optional The variable name to get. If null it will return all vars.
    @return {Array} Flash vars
    @sample
    alert(oSwf.getVars());
    */
    this.getVars = function(sName) {
        if (sName) {
            return this.aVars[sName];
        } else {
            return this.aVars;
        }
    };

/**
    @item {Method} getParamTags
    @parent PINT.util.flash
*/
    this.getParamTags = function() {
        var sParamTags = "";
        for (var sParam in this.getParams()) {
            if (typeof sParam == "string"){
                sParamTags += '<param name="' + sParam + '" value="' + this.getParams(sParam) + '" />';
            }
        }
        if (sParamTags === "") {
            sParamTags = null;
        }
        return sParamTags;
    };
/**
    @item {Method} getHTML
    @parent PINT.util.flash
*/
    this.getHTML = function() {
        var sFlashHTML = "";
        if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) {
			var protocol = (("https:" == document.location.protocol) ? "https://" : "http://");
            sFlashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+protocol+'fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.sCodeBase + '" width="' + this.iWidth + '" height="' + this.iHeight + '" id="' + this.sId + '" name="' + this.sId + '" align="' + this.sAlign + '">';
            sFlashHTML += '<param name="movie" value="' + this.sSwf + '" />';
            if (this.getParamTags() !== null) {
                sFlashHTML += this.getParamTags();
            }
            if (this.getVariablePairs() !== null) {
                sFlashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
            }
            sFlashHTML += '</object>';
        } else {
            sFlashHTML += '<embed type="application/x-shockwave-flash" src="' + this.sSwf + '" width="' + this.iWidth + '" height="' + this.iHeight + '" id="' + this.sId + '" name="' + this.sId + '" align="' + this.sAlign + '"';
            for (var sParam in this.getParams()) {
                if (typeof sParam == "string"){
                    sFlashHTML += ' ' + sParam + '="' + this.getParams(sParam) + '"';
                }
            }
            if (this.getVariablePairs() !== null) {
                sFlashHTML += ' flashVars="' + this.getVariablePairs() + '"';
            }
            sFlashHTML += '></embed>';
        }
        return sFlashHTML;
    };

/**
    @item {Method} getVariablePairs
    @parent PINT.util.flash
*/
    this.getVariablePairs = function() {
        var aVariablePairs = [];
        for (var sName in this.getVars()) {
            if (typeof sName == "string"){
                aVariablePairs.push(sName + "=" + encodeURIComponent(this.getVars(sName)));
            }
        }
        if (aVariablePairs.length > 0) {
            return aVariablePairs.join("&");
        } else {
            return null;
        }
    };

        /**
    @item {Method} render
    @parent PINT.util.flash
    @info Renders the flash into the page
    @param {String} sIdContainer The div to display the flash in.
    @sample
    oSwf.render();
    */
    this.render = function(sIdContainer) {

    	this.addParam("quality", "high");
    	if (this.sBgColor) {
    	    this.addParam("bgcolor", this.sBgColor);
    	}

    	this.sDetect = PINT.util.getQueryParamValue("detectflash");

        if (this.detectFlash(this.iVersion) || this.sDetect == "false") {
            if (sIdContainer) {
                document.getElementById(sIdContainer).innerHTML = this.getHTML();
            } else {
                document.write(this.getHTML());
			}
		} else {
            if (this.sRedirectUrl !== "") {
                document.location.replace(this.sRedirectUrl);
		    }
			else if (this.sNoScriptId !== "") {
                var oElement = document.getElementById(this.sNoScriptId);
				if (oElement) {
                    oElement.style.display = oElement.parentNode.style.display;
                }
			}
			else if (this.sDefaultImage !== "") {
    			var sImageString = "<img src=\"" + this.sDefaultImage + "\" width=\"" + this.iWidth + "\" height=\"" + this.iHeight + "\" border=\"0\" alt=\"\"";
    			if (typeof this.sImageMap != "undefined" && this.sImageMap !== "") {
                    sImageString += " usemap=\"#" + this.sImageMap + "\" ";
    			}
    			sImageString += " class=\"inlineimage\" />";
				if (sIdContainer) {
					document.getElementById(sIdContainer).innerHTML = sImageString;
				} else {
					document.write(sImageString);
				}
			} else {
				if (sIdContainer) {
					document.getElementById(sIdContainer).innerHTML = this.sAltText + "" + this.sBypassText;
				} else {
					document.write(this.sAltText + "" + this.sBypassText);
				}
			}
    	}
    };

/**
    @item {Method} getFlashVersion
    @parent PINT.util.flash
    @info Gets a users flash version
    @return {Integer} User's Flash Version
    @sample
    alert(oSwf.getFlashVersion());
    */
    this.getFlashVersion = function() {
    	var iFlashVersion = 0;
    	if (navigator.plugins && navigator.plugins.length) {
    		var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
            var oPlugin = navigator.plugins["Shockwave Flash" + swVer2];
    		if (oPlugin) {
    			if (oPlugin.description) {
                    var sDescription = oPlugin.description;
    	   			var aDescription = oPlugin.description.split(" ");
                    var aMajorVersion = aDescription[2].split(".");
                    iFlashVersion = aMajorVersion[0];
    			}
    		}
    	} else {
            var axo;
            try {
        		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
        		iFlashVersion = 7;
        	} catch (e) {}

        	if (!iFlashVersion)
        	{
        		try {
        			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
        			iFlashVersion = 6;
        		} catch (e1) {}
        	}

        	if (!iFlashVersion)
        	{
        		try {
        			/* version will be set for 4.X or 5.X player */
        			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
        			iFlashVersion = 4;
        		} catch (e2) {}
        	}

        	if (!iFlashVersion)
        	{
        		try {
        			/* version will be set for 3.X player */
        			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
        			iFlashVersion = 3;
        		} catch (e3) {}
        	}
            
            if (!iFlashVersion)
        	{
        		try {
        			/* version will be set for 2.X player */
        			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
        			iFlashVersion = 2;
        		} catch (e4) {}
        	}
    	}
    	return iFlashVersion;
    };

    /**
    @item {Method} detectFlash
    @parent PINT.util.flash
    @info Compares the user's flash version to one passed in
    @param {Integer} iVersion Flash version to compare to the latest version
    @return {Boolean} True if the user's flash version is >= iVersion
    @sample
    if (oSwf.detectFlash(9)) alert('do something');
    */
    this.detectFlash = function(iVersion) {
    	return (this.getFlashVersion() >= iVersion);
    };
};

PINT.util.getQueryParamValue = function(sParam) {
	var aTemp = document.location.search.split('&');
	for (var i=0;i<aTemp.length;i++) {
		var aTemp2 = aTemp[i].split('=');
		if (aTemp2[0] == sParam) {
			return aTemp2[1];
		}
	}
	return "";
};

// Set flash files into an array
var flashFileNameArray = new Array();
flashFileNameArray[flashFileNameArray.length] = rootDirectory + "/flash/random1.swf";
flashFileNameArray[flashFileNameArray.length] = rootDirectory + "/flash/random2.swf";
flashFileNameArray[flashFileNameArray.length] = rootDirectory + "/flash/random3.swf";

var maxNumber       = flashFileNameArray.length - 1;
var generatorNumber = Math.random();
var randomNumber    = Math.round(generatorNumber*maxNumber);

// flash file set up
var flash_file_width  = 760;
var flash_file_height = 222;

var h_flash = new PINT.util.flash({  
	 "swf" : flashFileNameArray[randomNumber],  
	 "noscriptId" : "flash1",  
	 "width" : flash_file_width,  
	 "height" : flash_file_height  
 });  
h_flash.addParam('wmode', 'transparent');  
h_flash.render('h_flash');
