var flashVersionOK = false;
var flashVersion   = -1;


// NOTES:
// To embed a Flash movie (SWF) into a HTML page, call embedFlash with all the parameters.
// Once this function is called, no other attempts will be made to determine the installed
// Flash player's version.
// That is, if the first time a movie is embedded, the minimumVersion is specified to be 8,
// then if the installed player is 8 or later, then version will not be checked again. It
// is assumed that all other movies required by the page have the same minimum requirement.
// However, if the desire is to have this check done the next time embedFlash is called,
// then call resetFlashOK first.

// function: embedFlash
//   Parameters:
//     width          = string or number - width of SWF
//     height         = string or number - height of SWF
//     minimumVersion = number not a string
//     moviePath      = path and name of SWF file
//     vmode          = string - opague or transparent
//     bgcolor        = string - something like "#ffffff", or "" if vmode is transparent
//   Example:
//     embedFlash ("780", "125", 8, "/flash/myMovie.swf?option=abc");

function embedFlash (width, height, minimumVersion, moviePath)
{
  if (isFlashOK (minimumVersion))
  {
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+minimumVersion+',0,0,0" width="'+width+'" height="'+height+'">');
    document.write('<param name="allowScriptAccess" value="always" />');
    document.write('<param name="movie"   value="'+moviePath+'" />');
    document.write('<param name="wmode"   value="transparent" />');
    document.write('<param name="quality" value="high" />');
    document.write('<embed src="'+moviePath+'" quality="high" width="'+width+'" height="'+height+'" wmode="transparent" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
  }

  return (flashVersionOK);
}


// function: embedFlashFull
//   Parameters:
//     width          = string or number - width of SWF
//     height         = string or number - height of SWF
//     minimumVersion = number not a string
//     moviePath      = path and name of SWF file
//     bgcolor        = string - something like "#ffffff", or "" if vmode is transparent
//     vmode          = string - opague or transparent
//     id             = string - id used to access movie via script
//     flashVars      = optional parameters
//   Example:
//     embedFlash ("780", "125", 8, "/flash/myMovie.swf?option=abc", "transparent", "", "myId", "path=myPath");

function embedFlashFull (width, height, minimumVersion, moviePath, vmode, bgcolor, id, flashVars)
{
  if (isFlashOK (minimumVersion))
  {
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+minimumVersion+',0,0,0" id="'+id+'" width="'+width+'" height="'+height+'">');
    document.write('<param name="allowScriptAccess" value="always" />');
    document.write('<param name="movie"             value="'+moviePath+'" />');
    document.write('<param name="wmode"             value="'+vmode+'" />');
    document.write('<param name="bgcolor"           value="'+bgcolor+'" />');
    document.write('<param name="FlashVars"         value="'+flashVars+'" />');
    document.write('<param name="quality"           value="high" />');
    document.write('<embed src="'+moviePath+'" quality="high" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" wmode="'+vmode+'" allowScriptAccess="always" FlashVars="'+flashVars+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
  }

  return (flashVersionOK);
}


// function: resetFlashOK
// Allows the version check the next time embedFlash is called.
function resetFlashOK ()
{
  flashVersionOK = false;
}


// private function
function isFlashOK (minimumFlashVersion)
{
  flashVersion   = -1;
  if (flashVersionOK == false)
  {
    getFlashVersion ();
    if (flashVersion != -1)
    {
      if (minimumFlashVersion <= flashVersion)
        flashVersionOK = true;
      else
        flashVersionOK = false;
    }
  }

  return (flashVersionOK);
}

// private function
function getFlashVersion ()
{
  var latestFlashVersion = 25;
  var agent              = navigator.userAgent.toLowerCase(); 

  // 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')
    { 
      for (var i = latestFlashVersion; i >= 3; i--)
      {
        if (flashPlugin.description.indexOf(i + '.') != -1)
        {
          flashVersion = i;
          break;
        }
      }
    }
  }

  // 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)
  {
    var doc = '<scr' + 'ipt language="VBScript"\> \n';
    doc += 'On Error Resume Next \n';
    doc += 'Dim obFlash \n';
    doc += 'For i = ' + latestFlashVersion + ' To 3 Step -1 \n';
    doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
    doc += '   If IsObject(obFlash) Then \n';
    doc += '      flashVersion = i \n';
    doc += '      Exit For \n';
    doc += '   End If \n';
    doc += 'Next \n';
    doc += '</scr' + 'ipt\> \n';
    document.write(doc);
  }
}

