//////////////////////////////////////////////////
//
//  haveFlashVersion()
//
//  Detects if a specified version of Flash is installed
//
//  Modularised from embedFlash() by Andy Hames 21/09/2007
//
//  Parameters:
//    version         the version of Flash that is required
//
//  For MSIE clients this function requires that the accompanying VBScript function MSIEWinDetectFlash has also been included on the calling page
//
//////////////////////////////////////////////////
function haveFlashVersion(version) {
  var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
  if (plugin) {
    var words = navigator.plugins["Shockwave Flash"].description.split(" ");
    for (var i = 0; i < words.length; ++i) {
      if (isNaN(parseInt(words[i]))) continue;
      var MM_PluginVersion = words[i];
    }
    var haveVersion = MM_PluginVersion >= version;
  }
  else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
    // MSIE doesn't support navigator.mimeTypes - call to external VBScript function instead
    var haveVersion = MSIEWinDetectFlash(version); 
  }
  
  return haveVersion;
}


//////////////////////////////////////////////////
//
//  embedFlash()
//
//  Calls haveFlashVersion() to detect if Flash is installed and embeds the specified movie into the calling web page.
//  If Flash is not available, inserts an alternative image where specified or a standard 'Install Flash...' message.
//
//  Author:       Andy Hames 21/09/2007
//  Change History:
//    20/03/2008  Andy Hames - Add optional parameter alt_image_id
//    09/09/2008  Andy Hames - Display upgrade message if no alternative images specified. Split out Flash detection to haveFlashVersion().
//
//  Parameters:
//    version         the version of Flash that is required
//    filename        location of the .swf file to play
//    movie_w         the movie's width
//    movie_h         the movie's height
//    movie_id        the movie's id attribute
//    alt_image       [optional] an alternate image to show if Flash is not available
//    alt_image_text  [optional] the alt text value for the alt_image
//    alt_image_link  [optional] a hyperlink to apply to the alt_image
//    alt_image_id    [optional] an id attribute to apply to the alt_image
//
//////////////////////////////////////////////////
function embedFlash(version, filename, movie_w, movie_h, movie_id, alt_image, alt_image_text, alt_image_link, alt_image_id) {
  if (haveFlashVersion(version)) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="'+movie_id+'" width="'+movie_w+'" height="'+movie_h+'" align="">');
    document.write('  <param name="movie" value="' + filename + '"><param name="wmode" value="opaque"><param name="menu" value="false"><param name="quality" value="high"><param name="bgcolor" value="">');
    document.write('  <embed src="' + filename + '" quality="high" wmode="opaque" menu="false" swLiveConnect="false" width="' + movie_w + '" height="' + movie_h + '" name="' + movie_id + '" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
    document.write('</object>');
  } 
  else {
    if (alt_image != undefined) {
      // Alternative static image defined - use this
      var hyperlink = (alt_image_link != undefined);
      if (hyperlink) {document.write('<a href="' + alt_image_link + '">');}
      document.write('<img src="' + alt_image + '" width="' + movie_w + '" height="' + movie_h + '" border="0"');
      if (alt_image_text != undefined) {document.write(' alt="' + alt_image_text + '"');}
      if (alt_image_id != undefined) {document.write(' id="' + alt_image_id + '"');}
      document.write(' />');
      if (hyperlink) {document.write('</a>');}
    }
    else {
      // No alternative - display upgrade message instead
      document.write('<p id="' + movie_id + '_noflash" class="no_flash_msg">');
      document.write('  <a href="http://www.adobe.com/products/flashplayer/" title="Opens in a new window" target="_blank"><strong>Install Adobe Flash player to view our enhanced content</strong></a>');
      document.write('</p>');
    }
  }
}