// **********************************************************
// Flash Detect Script
// moock fpi [f.lash p.layer i.nspector]
// version: 1.3.5
// ----------------------------------------------------------

var fds_requiredVersion = 6;   // Version the user needs to view site (max 9, min 2)

// ----------------------------------------------------------
// System globals
var fds_minVersion = 2;             // lowest version we can actually detect
var fds_maxVersion = 9;             // highest version we can actually detect
var fds_actualVersion = 0;          // version the user really has
var fds_hasRightVersion = false;    // boolean. true if it's safe to embed the flash movie in the page

var fds_flashesInstalled = {};      // array of boolean flags indicating which version was detected

fds_flashesInstalled.set_value = function(index, value) { this[index] = value; }

// Write vbscript detection on ie win. IE on Windows doesn't support regular JavaScript plugins array detection.
if( (navigator.appVersion.indexOf("MSIE") != -1) && (navigator.appVersion.indexOf("Windows")) ) {
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  for (var i=fds_maxVersion; i > fds_minVersion; i--) {
    document.write('call fds_flashesInstalled.set_value('+ i +', IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+ i +'"))) \n');
  }
  document.write('</SCR' + 'IPT\>'); // break up end tag so it doesn't end our script
}


// Standard javascript detection using navigator.plugins array
function fds_detectFlash() {
  if (navigator.plugins) {
    // check for flash 2 or flash 3+.
    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
      var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

      // We found the version, now set appropriate version flags
      if (flashVersion >= fds_maxVersion) fds_flashesInstalled[fds_maxVersion] = true;
      else if (flashVersion >= fds_minVersion) fds_flashesInstalled[flashVersion] = true;
    }
  }

  for (var i=fds_maxVersion; i > fds_minVersion; i--) if (fds_flashesInstalled[i]) {
    fds_actualVersion = i; break;
  }

  // If we're on webtv, the version supported is 2 (pre-summer2000 or 3, post-summer2000)
  if(navigator.userAgent.indexOf("WebTV") != -1) fds_actualVersion = 3;

  // DEBUGGING: uncomment next line to display flash version
  //alert("version detected: " + fds_actualVersion);

  fds_hasRightVersion = (fds_actualVersion >= fds_requiredVersion);
}

fds_detectFlash();

function fds_displayFlash(flashArgs)
{
  if (fds_actualVersion >= flashArgs.minVersion) {
  //if (fds_hasRightVersion) { // if we've detected an acceptable version
    var oeTags = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
    + 'CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" '
    + 'WIDTH="'+ flashArgs.width +'" HEIGHT="'+ flashArgs.height +'">'
    + '<PARAM NAME="MOVIE" VALUE="'+ flashArgs.flashUrl +'">'
    + '<PARAM NAME="PLAY" VALUE="true">'
    + '<PARAM NAME="LOOP" VALUE="false">'
    + '<PARAM NAME="QUALITY" VALUE="high">'
    + '<PARAM NAME="MENU" VALUE="'+ flashArgs.menu +'">'
    + ((typeof(flashArgs.flashVars)!='undefined')? '<PARAM NAME="FLASHVARS" VALUE="'+ flashArgs.flashVars.replace('"','&quot;').replace('\\','\\\\') +'">': '')
    + (flashArgs.transparent? '<PARAM NAME="WMODE" VALUE="transparent">': '')
    + '<EMBED SRC="'+ flashArgs.flashUrl +'"'
    + ' WIDTH="'+ flashArgs.width +'" HEIGHT="'+ flashArgs.height +'"'
    + ' PLAY="true"'
    + ' LOOP="false"'
    + ' QUALITY="high"'
    + ' MENU="'+ flashArgs.menu +'"'
    + ((typeof(flashArgs.flashVars)!='undefined')? ' FLASHVARS="'+ flashArgs.flashVars.replace('"','&quot;').replace('\\','\\\\')+'"': '')
    + ' TYPE="application/x-shockwave-flash"'
    + (flashArgs.transparent? ' WMODE="transparent"': '')
    + ' PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
    + '</EMBED>'
    + '</OBJECT>';
    document.write(oeTags); // embed the flash movie
  }

  else { // flash is too old or we can't detect the plugin, show alternate content from the noscript tags
    var altContentElmt = document.getElementById(flashArgs.clientId +'_altcontent');
    document.write((altContentElmt.firstChild!=null)? altContentElmt.firstChild.nodeValue: altContentElmt.innerHTML);
  }
}
