/* Script for Flash Player detection and dynamic writes of swf movies vs. alt images */

// global constants - changing these will change the parameters of all swf instances, except when forced by an individual function call.
var FLASH_CONTENT_VERSION = 7;
var FLASH_CLASS_ID = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
var FLASH_CODEBASE = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0';
var FLASH_PLUGINTYPE = 'application/x-shockwave-flash';
var FLASH_PLUGINSPAGE = 'http://www.macromedia.com/go/getflashplayer';
var FLASH_ALLOWSCRIPTACCESS = 'sameDomain';
var FLASH_AUTOPLAY = 'true';
var FLASH_LOOP = 'false';
var FLASH_MENU = 'false';
var FLASH_LIVECONNECT = 'false';
var FLASH_QUALITY = 'high';
var FLASH_DEFAULT_BGCOLOR = '#ffffff';
var FLASH_DEFAULT_ALIGN = 'middle';
var FLASH_DEFAULT_ID = 'styleFlash';

// local variables
var blnFlashCanPlay = false;

/* FUNCTION PARAMETERS GUIDE:
	strMovie - path to the Flash movie [required]
	divName - path to alternate div content [required]
	divLayer - for backward compatibility [if no value, '' is required]
	intWidth - pixel width of the movie/image content
	intHeight - pixel height of the movie/image content
	hexBgcolor - background color for the flash movie [optional - defaults to FLASH_DEFAULT_BGCOLOR]
	strId - id of the Flash object, on pages with more than 1 flash instance these should be unique [optional - defaults to FLASH_DEFAULT_ID]
	strAlign - html alignment of the content [optional - defaults to FLASH_DEFAULT_ALIGN]
	intFlashVersion - version of the Flash Player required to play the content [optional - defaults to FLASH_CONTENT_VERSION]
	strPlay - Flash play parameter - true or false [optional - defaults to FLASH_AUTOPLAY]
	strLoop - Flash loop parameter - true or false [optional - defaults to FLASH_LOOP]
	strMenu - Flash menu parameter - true or false [optional - defaults to FLASH_MENU]
*/	
function flashWrite(strMovie, divName, divLayer, intWidth, intHeight, hexBgcolor, strId, strAlign, intFlashVersion, strPlay, strLoop, strMenu, auxVars) {
   
    intFlashVersion = (intFlashVersion) ? intFlashVersion : FLASH_CONTENT_VERSION;

	var blnPluginPresent = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

    if ( blnPluginPresent != 0 ) 
    { 
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
		    for (var i = 0; i < words.length; ++i)
		    {
			if (isNaN(parseInt(words[i])))
			continue;
			var intPluginVersion = words[i]; 
		    }
             
        intPluginVersion = parseInt(intPluginVersion);  

	}
    
    // Internet Explorer does not properly support navigator object
	if  ( blnPluginPresent == 0 && document.all ) 
    {

        intPluginVersion = ControlVersion();            
        if ( intPluginVersion != -1 ) {      
            // Given "WIN 2,0,0,11"
    	    tempArray         = intPluginVersion.split(" "); 	// ["WIN", "2,0,0,11"]
    		tempString        = tempArray[1];			// "2,0,0,11"
    		versionArray      = tempString.split(",");	// ['2', '0', '0', '11']      
            intPluginVersion = versionArray[0];    
        }
    }
    

    if (intPluginVersion >= intFlashVersion)
            blnFlashCanPlay = true;


            
	if ( blnFlashCanPlay ) {
		
		hexBgcolor = (hexBgcolor) ? hexBgcolor : FLASH_DEFAULT_BGCOLOR;
		strId = (strId) ? strId : FLASH_DEFAULT_ID;
		strAlign = (strAlign) ? strAlign : FLASH_DEFAULT_ALIGN;
		strPlay = (strPlay) ? strPlay : FLASH_AUTOPLAY;
		strLoop = (strLoop) ? strLoop : FLASH_LOOP;
		strMenu = (strMenu) ? strMenu : FLASH_MENU;
		divLayer = (divLayer) ? divLayer : divLayer;
								
		document.write('<OBJECT classid="' + FLASH_CLASS_ID + '"');
		document.write(' codebase="' + FLASH_CODEBASE + '" ');
		document.write(' ID="' + strId + '" WIDTH="' + intWidth + '" HEIGHT="' + intHeight + '" ALIGN="' + strAlign + '">');
		document.write(' <PARAM NAME="movie" VALUE="' + strMovie + '"?dartSZ=' + dart["sz"] + '&dart_site=' + dart["site"] + '&dart_zone=' + dart["zone"] + '&dart_target=' + dart["target"] + '&dart_dcopt=' + dart["dcopt"] + '&dart_url=' + escape(dart["url"]) + '"> ');
		document.write(' <PARAM NAME="quality" VALUE="' + FLASH_QUALITY + '"><PARAM NAME="wmode" VALUE="transparent"><PARAM NAME="MENU" VALUE="' + strMenu + '"><PARAM NAME="LOOP" VALUE="' + strLoop + '"><PARAM NAME="PLAY" VALUE="' + strPlay + '"><PARAM NAME="bgcolor" VALUE="' + hexBgcolor + '"> '); 
		document.write(' <PARAM NAME="FlashVars" VALUE="'+auxVars+'&trend_id='+getQueryParam("t_id")+'&dartSZ=' + dart["sz"] + '&dart_site=' + dart["site"] + '&dart_zone=' + dart["zone"] + '&dart_target=' + dart["target"] + '&dart_dcopt=' + dart["dcopt"] + '&dart_url=' + escape(dart["url"]) + '"> ');
		document.write(' <EMBED src= "' + strMovie + '?dartSZ=' + dart["sz"] + '&dart_site=' + dart["site"] + '&dart_zone=' + dart["zone"] + '&dart_target=' + dart["target"] + '&dart_dcopt=' + dart["dcopt"] + '&dart_url=' + escape(dart["url"]) + '" ');
		document.write(' flashvars="'+auxVars+'&trend_id='+getQueryParam("t_id")+'" quality="' + FLASH_QUALITY + '" play="' + strPlay + '" loop="' + strLoop + '" menu="' + strMenu + '" bgcolor="' + hexBgcolor + '"  wmode="transparent" ');
		document.write(' swLiveConnect="' + FLASH_LIVECONNECT + '" WIDTH="' + intWidth + '" HEIGHT="' + intHeight + '" NAME="' + strId + '" ALIGN="' + strAlign + '"');
		document.write(' TYPE="' + FLASH_PLUGINTYPE + '" PLUGINSPAGE="' + FLASH_PLUGINSPAGE + '">');
		document.write(' </EMBED>');
		document.write(' </OBJECT>');
	} else {
    
		document.getElementById(divName).style.display="block";
	}
}

function getQueryParam(param){
	var q = document.location.search || document.location.hash;
	if(q) {
		var pairs = q.substring(1).split("&");
		for (var i=0; i < pairs.length; i++) {
			if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
				return pairs[i].substring((pairs[i].indexOf("=")+1));
			}
		}
	}
}

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
/* obaptist - 2007-05-15 - test to see /scripts has been removed from bulk deploys */