//Encapsulates Flash Object/Embed html as a Javascript object
function FlashObject() {
  this.httpPrefix = "http";
  this.width = "400";
  this.height = "400";
  this.id = "AutismPro Flash Movie";
  this.align = ""; // l | t | r | b (default centered)
  this.allowScriptAccess = "sameDomain"; //never | always | sameDomain
  this.movieUrl;
  this.quality = "high"; //low | high | autolow | autohigh | best
  this.bgColor = "E0EAF4";
  this.play = "true"; //true | false
  this.loop = "false"; //true | false
  this.menu = "false"; //true | false
  this.swfLiveConnect = "false"; //true | false  
  this.scale = "showall" //showall | noborder | exactfit 
  this.flashVars = ""; //url encoded key/values
  this.codeBase = "://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0";
} //FlashObject

//writes the flash object/embed tags to the client
FlashObject.prototype.writeFlashObject = function() {   
  document.write(this.toString());
}
  
//determines whether http or https is being used and sets prefix accordingly
FlashObject.prototype.setHttpOrHttps = function() {
  var documentUrl = document.URL;
  var prefix = documentUrl.substring(0, documentUrl.indexOf("://"));
  
  if (prefix != "") {
    this.httpPrefix = prefix;
  }
}
  
//builds the object/embed tags based on the FlashObject properties
FlashObject.prototype.getObjectEmbedCode = function() {
  this.setHttpOrHttps();
  
  var objectEmbedCode = 
    "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' \n" + 
            "codebase='" + this.httpPrefix + this.codeBase + "' \n" +
            "width='" + this.width + "' height='" + this.height + "' id='" + this.id + 
            "' align='" + this.align + "' VIEWASTEXT> \n" +
              "\t<param name='allowScriptAccess' value='" + this.allowScriptAccess + "' /> \n" +
              "\t<param name='movie' value='" + this.movieUrl + "' /> \n" +
              "\t<param name='quality' value='" + this.quality + "' /> \n" +
              "\t<param name='bgcolor' value='#" + this.bgColor + "' /> \n" +
              "\t<param name='flashVars' value='" + this.flashVars + "' /> \n" +
              "\t<param name='play' value='" + this.play + "' /> \n" +
              "\t<param name='loop' value='" + this.loop + "' /> \n" +
              "\t<param name='scale' value='" + this.scale + "' /> \n" +
              "\t<param name='menu' value='" + this.menu + "' /> \n" +
              "\t<embed src='" + this.movieUrl + "' \n" +
                "\t\tquality='" + this.quality + "' \n" + 
                "\t\tbgcolor='#" + this.bgColor + "' \n" + 
                "\t\twidth='" + this.width + "' height='" + this.height + "' \n" +
                "\t\tname='" + this.id + "' align='" + this.align + "' \n" +
                "\t\tallowScriptAccess='" + this.allowScriptAccess + "' \n" + 
                "\t\tplay='" + this.play + "' \n" +
                "\t\tloop='" + this.loop + "' \n" + 
                "\t\tflashVars='" + this.flashVars + "' \n" +
                "\t\tscale='" + this.scale + "' \n" +
                "\t\tmenu='" + this.menu + "' \n" +
                "\t\tswfLiveConnect='" + this.swfLiveConnect + "' \n" +
                "\t\ttype='application/x-shockwave-flash' \n" +
                "\t\tpluginspage='http://www.macromedia.com/go/getflashplayer' />\n" +
          "</object>";
          
    return objectEmbedCode;
}

//returns a string representation of the FlashObject
FlashObject.prototype.toString = function() {
  return this.getObjectEmbedCode();
}

//sets the specified FlashObject property when the value specified is 
//something other than an empty string
FlashObject.prototype.setPropertyConditionally = 
        function(propertyName, possibleValue) {
  if (possibleValue != "") {
    this[propertyName] = possibleValue;
  }
}

//*********************************************************************
//***********User-defined methods for writing Flash object*************
//*********************************************************************

//writes flash object/embed code to Response 
//need to pass only 4 required parameters
function writeFlashObject(movieUrl, id, width, height) {
  var myFlashObject = new FlashObject();

  myFlashObject.movieUrl = movieUrl;
  myFlashObject.id = id;
  myFlashObject.width = width;
  myFlashObject.height = height;
  
  myFlashObject.writeFlashObject();
}

//Writes flash object/embed code to Response; need to pass all parameters 
//To use the default for any particular parameter, pass in an empty string. 
function writeFlashObjectExtended(movieUrl, id, width, height, align, 
        allowScriptAccess, quality, bgColor, play, loop, menu, swfLiveConnect, 
        scale, flashVars) {
        
    var myFlashObject = new FlashObject();

    myFlashObject.movieUrl = movieUrl;
    myFlashObject.id = id;
    myFlashObject.width = width;
    myFlashObject.height = height;
    
    myFlashObject.setPropertyConditionally("align", align);
    myFlashObject.setPropertyConditionally("allowScriptAccess", 
            allowScriptAccess);
    myFlashObject.setPropertyConditionally("quality", quality);
    myFlashObject.setPropertyConditionally("bgColor", bgColor);
    myFlashObject.setPropertyConditionally("play", play);
    myFlashObject.setPropertyConditionally("loop", loop);
    myFlashObject.setPropertyConditionally("menu", menu);
    myFlashObject.setPropertyConditionally("swfLiveConnect", swfLiveConnect);
    myFlashObject.setPropertyConditionally("scale", scale);
    myFlashObject.setPropertyConditionally("flashVars", flashVars);

    myFlashObject.writeFlashObject();
 }
