/*
 * flash.js
 * Macromedia Flash plugin detection and replacement
 *
 * By Andy Smith, Preview Graphics
 * www.preview.co.uk
 *
 * Based on techniques from Peter-Paul Koch's Flash detection scripts
 * [1] and Shaun Inman's Flash replacement scripts [2]
 *
 *   [1] http://www.quirksmode.org/js/flash.html
 *   [2] http://www.shauninman.com/mentary/past/ifr_revisited_and_revised.php
 *
 * After this script is run two variables will be available:
 *  - flash_available will be set to true if Flash is known to be
 *    installed, false if Flash is known not to be installed, or null
 *    if the browser makes it impossible to tell.
 *  - flash_version will be set to the major version of the Flash
 *    plugin if this is known, or null if the version is unknown or
 *    Flash is not installed.
 *
 * In addition, if Flash is available a class will be applied to the HTML
 * element. This class is defined in the 'flash_class' variable below.
 */

var flash_available = null;
var flash_version = null;
var flash_class = "has-flash";

if (navigator && navigator.plugins && navigator.plugins.length)
  {
    // Best way to get info - supported by Netscape/Mozilla and some
    // others
    var plugin = navigator.plugins["Shockwave Flash"];
    if (plugin)
      {
        flash_available = true;
        if (plugin.description)
          {
            var desc = plugin.description;
            flash_version = desc.charAt(desc.indexOf('.') - 1);
          }
      }
    else if (navigator.plugins["Shockwave Flash 2.0"])
      {
        flash_available = true;
        flash_version = 2;
      }
    else
      {
        flash_available = false;
      }
  }
else if (navigator && navigator.mimeTypes && navigator.mimeTypes.length)
  {
    // Supported by Opera on Mac and Linux and some others. Also
    // supported by Netscape but not as useful as navigator.plugins -
    // can't get version.
    var mime = navigator.mimeTypes["application/x-shockwave-flash"];
    flash_available = (mime && mime.enabledPlugin ? true : false);
  }
else if (navigator && navigator.appVersion
         && navigator.appVersion.indexOf("MSIE") != -1
         && navigator.appVersion.indexOf("Windows") != -1)
  {
    // Internet Explorer for Windows - can only get information with
    // VBScript. And document.write. Nasty.
    document.write('<scr' + 'ipt language="VBScript">\n');
    document.write('on error resume next\n');
    document.write('flash_available = false\n');
    document.write('For v = 2 to 6\n');
    document.write('    If Not(IsObject(CreateObject("ShockwaveFlash.'
                   + 'ShockwaveFlash." & v))) Then\n');
    document.write('    \n');
    document.write('    Else\n');
    document.write('        flash_available = true\n');
    document.write('        flash_version = v\n');
    document.write('    End If\n');
    document.write('Next\n');
    document.write('</scr' + 'ipt>\n');
  }

if (flash_available && document.getElementsByTagName)
  {
    var html = document.getElementsByTagName('html')[0];
    if (html && (html.className.indexOf(flash_class) == -1))
      {
        html.className += ' ' + flash_class;
      }
  }


// Replace the content of element with a Flash movie. Params is currently
// ignored - intended to be developed as a dictionary to hold additional
// parameters like wmode (for transparency) and flashvars.
function flashReplace(element, movie, width, height, params)
{
  if (flash_available && (typeof element.innerHTML != "undefined"))
    {
      var h = '';
      h += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
         + ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"'
         + ' width="'+width+'" height="'+height+'">';
      h += '<param name="movie" value="'+movie+'" />';
      h += '<param name="quality" value="high" />';
      h += '<param name="wmode" value="transparent" />';
      h += '<embed type="application/x-shockwave-flash"'
         + ' src="'+movie+'" width="'+width+'" height="'+height+'"'
         + ' pluginspage="http://www.macromedia.com/go/getflashplayer"'
         + ' wmode="transparent"'
         + ' quality="high"></embed>';
      h += '</object>';
      element.innerHTML = h;
    }
}

