var FLASH_MAX = 20; // the latest Flash plug-in version or higher
var FLASH_VERSION = 0;

var agent = navigator.userAgent.toLowerCase();
if (navigator.plugins != null && navigator.plugins.length > 0) {
  var plugin = navigator.plugins['Shockwave Flash'];
  if (typeof plugin == 'object') {
    for (i = 3; i<= FLASH_MAX; i++) {
      if (plugin.description.indexOf(i+'.') != -1) {
        FLASH_VERSION = i;
      }
    }
  }
} else if (document.all && agent.indexOf('win') != -1 && agent.indexOf('16bit') == -1) {
  document.write('<'+'script language="VBScript"'+'> \n');
  document.write('set FlashObj = Nothing \n');
  document.write('on error resume next \n');
  document.write('For i = '+FLASH_MAX+' to 3 step -1 \n');
  document.write('set FlashObj = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n');
  document.write('If (Not(FlashObj is Nothing)) Then \n');
  document.write('FLASH_VERSION = i \n');
  document.write('Exit For \n');
  document.write('End If \n');
  document.write('Next \n');
  document.write('<'+'\/script'+'> \n');
} else if (agent.indexOf('webtv/2.5') != -1) {
  FLASH_VERSION = 3;
} else if (agent.indexOf('webtv') != -1) {
  FLASH_VERSION = 2;
} else {
  FLASH_VERSION = -1;
}

function hasFlash(version) { return (FLASH_VERSION >= version); }

function createFlash(version, name, width, height, bgcolor, quality, menu, flashvars, flashclass) {
  flashvars = flashvars != null ? flashvars : '';
  var swf = '';
  swf += '<object';
  if (flashclass != null && flashclass.length > 0) { swf += ' class="'+flashclass+'"'; }
  swf += ' width="'+width+'"';
  swf += ' height="'+height+'"';
  // Removed: MacIE doesn't show anything if a type is included here.
  // swf += ' type="application/x-shockwave-flash"';
  swf += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
  swf += ' codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+',0,0,0">';
  swf += '<param name="movie" value="'+name;
  if (flashvars != null && flashvars.length > 0) { swf += '?'+flashvars; }
  swf += '">';
  swf += '<param name="FlashVars" value="'+flashvars+'">'
  swf += '<param name="bgcolor" value="'+bgcolor+'">';
  swf += '<param name="quality" value="'+quality+'">';
  swf += '<param name="wmode" value="opaque">';
  swf += '<param name="menu" value="'+menu+'">';
  swf += '<embed src="'+name;
  if (flashvars != null && flashvars.length > 0) { swf += '?'+flashvars; }
  swf += '"';
  if (flashclass != null && flashclass.length > 0) { swf += ' class="'+flashclass+'"'; }
  swf += ' Flashvars="'+flashvars+'"';
  swf += ' width="'+width+'"';
  swf += ' height="'+height+'"';
  swf += ' bgcolor="'+bgcolor+'"';
  swf += ' quality="'+quality+'"';
  swf += ' wmode="opaque"';
  swf += ' menu="'+menu+'"';
  swf += ' type="application/x-shockwave-flash"';
  swf += ' pluginspage="https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
  swf += '<\/embed>';
  swf += '<\/object>';
  return (swf);
}

function writeFlash(v,n,w,h,bg,q,m,nf,fv) {
  if (hasFlash(v)) {
    document.write(createFlash(v,n,w,h,bg,q,m,fv));
  } else {
    document.write('<img src=' + nf + ' />');
  }
}