﻿function Flash(movie, id, width, height, ver, bg, fv)
{
  this.movie = movie;
  this.id = id;
  this.width = width;
  this.height = height;
  this.ver = ver ? ver : "8,0,0,0";

  this.align ="middle";

  this.attributes = new Array();
  this.params = new Object();

  if(bg)
    this.setParam("bgcolor", bg);
  if(fv)
    this.setParam("FlashVars", fv);

  this.setParam("allowScriptAccess", "sameDomain");
  this.setParam("quality", "high");
}


Flash.prototype.addAttribute = function(n, v)
{
  if(v)
    this.attributes[this.attributes.length] = n + '="' + v + '"';
  else
    this.attributes[this.attributes.length] = n;
}

Flash.prototype.setParam = function(n, v)
{
  this.params[n] = v;
}

Flash.prototype.toString = function()
{
  if(this.ver.length < 2)
    this.ver += ",0,0,0";

  var s = '<object id="' + this.id + '" width="' + this.width + '" height="' + this.height + '" align="' + this.align + '" ';
  s += 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.ver + '" ';
  for(var i=0; i<this.attributes.length; i++)
    s += this.attributes[i] + " ";
  s += '>';

  s += '<param name="movie" value="' + this.movie + '" />';
  for(var k in this.params)
    s += '<param name="' + k + '" value="' + this.params[k] + '" />';

  s += '<embed menu="false" src="' + this.movie + '" ';
  s += 'width="' + this.width + '" height="' + this.height + '" name="' + this.id + '" align="' + this.align + '" ';
  for(var k in this.params)
    s += k + '="' + this.params[k] + '" ';

  s += 'swLiveConnect="true" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />';

  s += '</object>';
  return s;
}

Flash.prototype.render = function()
{
  document.write(this.toString());

  // fix for flashplayer 9.0.16 bug with ExternalInterface
  if (!Flash.unloadSet) {
    if(window.attachEvent)  // only in IE
      window.attachEvent("onbeforeunload", function() { __flash_unloadHandler = function(){}; __flash_savedUnloadHandler = function(){};});
    Flash.unloadSet = true;
  }

  // fix for flashplayer 9.0.16 bug with ExternalInterface
  if (!Flash.unloadSet) {
    if(window.attachEvent)  // only in IE
      window.attachEvent("onbeforeunload", function() { __flash_unloadHandler = function(){}; __flash_savedUnloadHandler = function(){};});
    Flash.unloadSet = true;
  }
}