function FSFlashTag(src, width, height) {
	this.src     = src;
	this.width   = width;
	this.height  = height;
	this.version   = '7,0,14,0';
	this.id    = null;
	this.bgcolor   = 'ffffff';
	this.flashVars = null;
	this.salign = null;
	this.scale = null;
	this.wmode = null;
	this.wmodeFF = null;
}

FSFlashTag.prototype.setVersion = function(v) {  this.version = v;}
FSFlashTag.prototype.setId = function(id) {  this.id = id;}
FSFlashTag.prototype.setBgcolor = function(bgc) {  this.bgcolor = bgc;}
FSFlashTag.prototype.setSalign = function(sa) {  this.salign = sa;}
FSFlashTag.prototype.setScale = function(scl) {  this.scale = scl;}
FSFlashTag.prototype.setWmode = function(wm ){  this.wmode = wm;}
FSFlashTag.prototype.setWmodeFF = function(wmff) {  this.wmodeFF = wmff}
FSFlashTag.prototype.setFlashvars = function(fv) {  this.flashVars = fv;}

FSFlashTag.prototype.toString = function(){
  var ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
  var fsFlashTag = new String();
  if (ie)
  {
    fsFlashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
    if (this.id != null)
    {
      fsFlashTag += 'id="'+this.id+'" ';
    }
    fsFlashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+'" ';
    fsFlashTag += 'width="'+this.width+'" ';
    fsFlashTag += 'height="'+this.height+'">';
    fsFlashTag += '<param name="movie" value="'+this.src+'"/>';
    fsFlashTag += '<param name="quality" value="high"/>';
    fsFlashTag += '<param name="bgcolor" value="#'+this.bgcolor+'"/>';
    if (this.wmode != null)
    {
      fsFlashTag += '<param name="wmode" value="'+this.wmode+'"/>';
    }
    if (this.salign != null)
    {
      fsFlashTag += '<param name="salign" value="'+this.salign+'"/>';
    }
    if (this.scale != null)
    {
      fsFlashTag += '<param name="scale" value="'+this.scale+'"/>';
    }
    if (this.flashVars != null)
    {
      fsFlashTag += '<param name="flashvars" value="'+this.flashVars+'"/>';
    }
    fsFlashTag += '</object>';
  }
  else {
    fsFlashTag += '<embed src="'+this.src+'" ';
    fsFlashTag += 'quality="high" '; 
    fsFlashTag += 'bgcolor="#'+this.bgcolor+'" ';
    fsFlashTag += 'width="'+this.width+'" ';
    fsFlashTag += 'height="'+this.height+'" ';
    fsFlashTag += 'type="application/x-shockwave-flash" ';
    if (this.wmodeFF != null)
    {
      fsFlashTag += 'wmode="'+this.wmodeFF+'" ';
    }
    if (this.scale != null)
    {
      fsFlashTag += 'scale="'+this.scale+'" ';
    }
    if (this.flashVars != null)
    {
      fsFlashTag += 'flashvars="'+this.flashVars+'" ';
    }
    if (this.id != null)
    {
      fsFlashTag += 'name="'+this.id+'" ';
    }
    if (this.salign != null)
    {
      fsFlashTag += 'salign="'+this.salign+'" ';
    }
    fsFlashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
    fsFlashTag += '</embed>';
  }
  return fsFlashTag;
}

FSFlashTag.prototype.write = function(doc){  doc.write(this.toString());}

function FlashSerializer(useCdata){  this.useCdata = useCdata;}

FlashSerializer.prototype.serialize = function(args) {
  var qs = new String();

  for (var i = 0; i < args.length; ++i)
  {
    switch(typeof(args[i]))
    {
      case 'undefined':
        qs += 't'+(i)+'=undf';
        break;
      case 'string':
        qs += 't'+(i)+'=str&d'+(i)+'='+escape(args[i]);
        break;
      case 'number':
        qs += 't'+(i)+'=num&d'+(i)+'='+escape(args[i]);
        break;
      case 'boolean':
        qs += 't'+(i)+'=bool&d'+(i)+'='+escape(args[i]);
        break;
      case 'object':
        if (args[i] == null)
        {
          qs += 't'+(i)+'=null';
        }
        else if (args[i] instanceof Date)
        {
          qs += 't'+(i)+'=date&d'+(i)+'='+escape(args[i].getTime());
        }
        else // array or object
        {
          try
          {
            qs += 't'+(i)+'=xser&d'+(i)+'='+escape(this._serializeXML(args[i]));
          }
          catch (exception) {}
        }
        break;
      default:
    }
    if (i != (args.length - 1)) {
      qs += '&';
    }
  }
  return qs;
}

FlashSerializer.prototype._serializeXML = function(obj){
  var doc = new Object();
  doc.xml = '<fp>'; 
  this._serializeNode(obj, doc, null);
  doc.xml += '</fp>'; 
  return doc.xml;
}

FlashSerializer.prototype._serializeNode = function(obj, doc, name){
  switch(typeof(obj))
  {
    case 'undefined':
      doc.xml += '<undf'+this._addName(name)+'/>';
      break;
    case 'string':
      doc.xml += '<str'+this._addName(name)+'>'+this._escapeXml(obj)+'</str>';
      break;
    case 'number':
      doc.xml += '<num'+this._addName(name)+'>'+obj+'</num>';
      break;
    case 'boolean':
      doc.xml += '<bool'+this._addName(name)+' val="'+obj+'"/>';
      break;
    case 'object':
      if (obj == null)
      {
        doc.xml += '<null'+this._addName(name)+'/>';
      }
      else if (obj instanceof Date)
      {
        doc.xml += '<date'+this._addName(name)+'>'+obj.getTime()+'</date>';
      }
      else if (obj instanceof Array)
      {
        doc.xml += '<array'+this._addName(name)+'>';
        for (var i = 0; i < obj.length; ++i)
        {
          this._serializeNode(obj[i], doc, null);
        }
        doc.xml += '</array>';
      }
      else
      {
        doc.xml += '<obj'+this._addName(name)+'>';
        for (var n in obj)
        {
          if (typeof(obj[n]) == 'function')
            continue;
          this._serializeNode(obj[n], doc, n);
        }
        doc.xml += '</obj>';
      }
      break;
    default:
      break;
  }
}

FlashSerializer.prototype._addName= function(name){
  if (name != null)
  {
    return ' name="'+name+'"';
  }
  return '';
}

FlashSerializer.prototype._escapeXml = function(str){
  if (this.useCdata)
    return '<![CDATA['+str+']]>';
  else
    return str.replace(/&/g,'&amp;').replace(/</g,'&lt;');
}


function FlashProxy(uid, proxySwfName){
  this.uid = uid;
  this.proxySwfName = proxySwfName;
  this.flashSerializer = new FlashSerializer(false);
}

FlashProxy.prototype.call = function(){
  if (arguments.length == 0)  {}
  var qs = 'lcId=' + escape(this.uid) + '&functionName=' + escape(arguments[0]);

  if (arguments.length > 1)
  {
    var justArgs = new Array();
    for (var i = 1; i < arguments.length; ++i)
    {
			
      justArgs.push(arguments[i]);
    }
    qs += ('&' + this.flashSerializer.serialize(justArgs));
  }

  var divName = '_flash_proxy_' + this.uid;
  if(!document.getElementById(divName))
  {
    var newTarget = document.createElement("div");
    newTarget.id = divName;
    document.body.appendChild(newTarget);
  }
  var target = document.getElementById(divName);
  var ft = new FSFlashTag(this.proxySwfName, 1, 1); //should be sized 1,1  - samr 6/16/05
  ft.setVersion('6,0,65,0');
  ft.setFlashvars(qs);
	target.innerHTML = ft.toString();
}

// returns an object that can be used to attach the flash movie to the dom
FSFlashTag.prototype.updateElement = function(element)
{
    var isIE = window["ActiveXObject"] ? true : false;
    var flash;
    
    // builds the param tag (cross browser)
    function _addAttribute(name, value)
    {
        if (value == null) {
            return;
        }
        
        // ie sometimes has trouble with the name attribute.
        if (isIE) {
            var node = '<param name="' + name + '" value="' + value + '" />';
            flash += node;
        } else {
            flash.setAttribute(name, value);
        }
    }
    
    
    // build the object/embed tag
    if (isIE) {
    // Internet Explorer (object tag)
        flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
        flash += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.version + '"';
        flash += this.id ? ' id="' + this.id + '"' : "";
        flash += ' width="' + this.width + '" height="' + this.height + '">';
        _addAttribute("src", this.src);
    } else {
    // Everybody else (embed tag)
        flash = document.createElement("embed");
        _addAttribute("src", this.src);
        _addAttribute("pluginspage", "http://www.macromedia.com/go/getflashplayer");
        _addAttribute("wmode", this.wmodeFF);
        _addAttribute("height", this.height);
        _addAttribute("width", this.width);
        _addAttribute("id", this.id);
    }
    
    // common attributes/params
    _addAttribute("bgcolor", "#" + this.bgcolor);
    _addAttribute("wmode", this.wmode);
    _addAttribute("salign", this.salign);
    _addAttribute("scale", this.scale);
    _addAttribute("flashvars", this.flashVars);
    _addAttribute("quality", "high");
    _addAttribute("type", "application/x-shockwave-flash");
    
    
    if (isIE) {
        flash += "</object>";
        element.innerHTML = flash;
    } else {
        while (element.firstChild) {
            element.removeChild(element.firstChild);
        }
        element.appendChild(flash);
    }
}

FlashProxy.callJS = function() {
  var functionToCall = eval(arguments[0]);
  var argArray = new Array();
  for (var i = 1; i < arguments.length; ++i)
  {
    argArray.push(arguments[i]);
  }
  functionToCall.apply(functionToCall, argArray);
}

