// Flash Version Detector  v1.1.5
// http://www.dithered.com/javascript/flash_detect/index.html
// code by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
// with VBScript code from Alastair Hamilton

var flashVersion = 0;

var flashVersion2 = false;
var flashVersion3 = false;
var flashVersion4 = false;
var flashVersion5 = false;
var flashVersion6 = false;


// Function getFlashCookie(NameOfCookie)
// Returns: Flash version if found in cookie and -1 if no match is found
// Author: Austin Kottke (austin@bridgepub.com)

function getFlashCookie(cookieName) 
{
// Get flash cookie and if it exists;
var c = document.cookie.indexOf(cookieName, 0); 
// The cookie is found, now retrieve the data.

// Check if the cookie contains an index or -1 if nothing was found;
if (c != -1) 
	{
		// cookieData = the index into the document.cookie string 
		// then we add the length of whatever the cookie name is +1 because 
		// we want the actual data after the "=".
		var cookieData = c + cookieName.length + 1;
		
		// Now we have the index, now get the 1 character string past the = sign.
		// substring returns however many characters you specify into the index.
		 
		return (document.cookie.substring(cookieData, cookieData + 1)); 	
	} else {
		// No match in cookie so this exits;
		return -1 ; 
	
	}
}

function getFlashVersion() {


	// Check if the cookie is set, so we don't need to do this.
	
	var c = (getFlashCookie("flash"));
	
	// If c contains something greater than 0, than we got some flash! So 
	// don't run this routine; 
	if(c >= 1) {
		return Number(c);
		}  

	var agent = navigator.userAgent.toLowerCase();
	
   // NS3 needs flashVersion to be a local variable
   
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}
		//alert(flashPlugin.description);
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	   document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('flashVersion2 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  		document.write('flashVersion3 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  		document.write('flashVersion4 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  		document.write('flashVersion5 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  		document.write('flashVersion6 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n'); 
		document.write('</scr' + 'ipt\> \n');
		
		
		for (var i = 2; i <= 6; i++) 
		{  
			if (eval("flashVersion" + i) == true) 
			   	{
	  			flashVersion = i; 
				//alert("flash: " + flashVersion);
				}
  		}
  }
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}
	document.cookie = 'flash=' + flashVersion;
	//alert(flashVersion);
	return flashVersion;
	
}

flashVersion_DONTKNOW = -1;





/* ------------------------- Conditional Flash Inclusion Code -------------------------- */


function outputFlashMovie(path, width, height, params) {
/*
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="547" height="195">
<param name=movie value="<cms:link>/pics/cos/bpi/en_US/trade/home/bpianim.swf</cms:link>">
<param name=quality value=high>
<param name=wmode value=transparent>
<embed src="<cms:link>/pics/cos/bpi/en_US/trade/home/bpianim.swf</cms:link>" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="547" height="195">
</embed> 
</object>
*/

var paramsText = '';

for (var k in params) {
  paramsText += '<param name="' + k + '" value="' + params[k] + '">';
}

// Output the flash movie
document.writeln(

'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" ' +
'width="' + width + '" height="' + height + '">' +
'<param name=movie value="' + path + '">' +
'<param name=quality value=high>' +
paramsText + 
'<embed src="' + path + '" quality=high ' + 
'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ' +
'width="' + width + '" height="' + height + '"></embed></object>'

);

}

function doFlashWithAlt(path, width, height, params, reqVersion, altid) {
  if (getFlashVersion() >= reqVersion) {
    outputFlashMovie(path, width, height, params);
    var e = document.getElementById(altid);
    if (e) {
      e.style.display = "none";
    }
  }
}
