// System globals
var _isIE = (navigator.appName == "Microsoft Internet Explorer");
var _isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1);
var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var flash8Installed = false;
var flash9Installed = false;
var maxFlashVersion = 9;             // highest version we can actually detect
var actualFlashVersion = 0;          // version the user really has


function detectFlash() {
  if(_isIE && _isWin){
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
    document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
    document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
    document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
    document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
    document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
    document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
    document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
    document.write('<\/SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
  } else if (navigator.plugins) {
    // standard javascript detection that uses the navigator.plugins array.
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {

      // Some version of Flash was found. Time to figure out which.

      // Set convenient references to flash 2 and the plugin description.
      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      // DEBUGGING: uncomment next line to see the actual description.
      // alert("Flash plugin description: " + flashDescription);

      // A flash plugin-description looks like this: Shockwave Flash 4.0 r5
      // We can get the major version by grabbing the character before the period
      // note that we don't bother with minor version detection.
      // Do that in your movie with $version or getVersion().
      var flashVersion = parseInt(flashDescription.substring(16));

      // We found the version, now set appropriate version flags. Make sure
      // to use >= on the highest version so we don't prevent future version
      // users from entering the site.
      flash2Installed = flashVersion == 2;
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion == 6;
      flash7Installed = flashVersion == 7;
      flash8Installed = flashVersion == 8;
      flash9Installed = flashVersion >= 9;
    }
  }

  // Loop through all versions we're checking, and
  // set actualFlashVersion to highest detected version.
  for (var i = 2; i <= maxFlashVersion; i++) {
    if (eval("flash" + i + "Installed") == true) actualFlashVersion = i;
  }

  // If we're on msntv (formerly webtv), the version supported is 4 (as of
  // January 1, 2004).
  if(navigator.userAgent.indexOf("WebTV") != -1) actualFlashVersion = 4;

  // DEBUGGING: uncomment next line to display flash version
  // alert("version detected: " + actualFlashVersion);
}

function populateInnerHtmlFlash(divObject,swfUrl,width,height,flashVars)
  {
    if(divObject == undefined)
      return;
    var objectEmbedSrc  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
      + 'width="'+width+'" height="'+height+'"'
      + 'codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
      + '<param name="movie" value="'+swfUrl+'" />'
      + '<param name="quality" value="high" />'
      + '<param name="bgcolor" value="#ffffff" />'
      + '<param name="wmode" value="transparent"/>';
    if(flashVars == undefined) {    
      objectEmbedSrc = objectEmbedSrc + '<embed src="'+swfUrl+'" quality="high" bgcolor="#ffffff" '
      + 'width="'+width+'" height="'+height+'" name="testCheck" align="middle"'
      + 'play="true"'
      + 'wmode="transparent"'
      + 'quality="high"'
      + 'allowScriptAccess="sameDomain"'
      + 'type="application/x-shockwave-flash"'
      + 'pluginspage="https://www.macromedia.com/go/getflashplayer">'
      + '<\/embed>'
	  + '<\/object>';
    } else {
      objectEmbedSrc = objectEmbedSrc + '<param name=FlashVars value="' + flashVars + '">'
	  + '<embed src="'+swfUrl+'" quality="high" bgcolor="#ffffff" devicefont="true"'
      + 'width="'+width+'" height="'+height+'" name="flvplayer" align="middle"'
      + 'play="true"'
      + 'wmode="transparent"'
      + 'quality="high"'
      + 'allowScriptAccess="sameDomain"'
	  + 'FlashVars="' + flashVars + '"'
      + 'type="application/x-shockwave-flash"'
      + 'pluginspage="https://www.macromedia.com/go/getflashplayer">'
      + '<\/embed>'
	  + '<\/object>';
	}
    divObject.innerHTML = objectEmbedSrc;
  }
      
      
detectFlash();  // call our detector now that it's safely loaded.
