﻿/*
Creates a flash object dynamically.
Gets around the EOLAS patent issue.

http://msdn2.microsoft.com/en-us/library/ms537508.aspx

*/
function FlashObject(containerId, movie, width, height)
{
    this.Container = document.getElementById(containerId);
    this.FlashVars = new Array();
    this.Height = height;
    this.Movie = movie;
    this.Params = new Array();
    this.Width = width;
}

FlashObject.prototype.AddFlashVar = function(name, value)
{
    var idx;
    
    idx = this.FlashVars.length;
    this.FlashVars[idx] = new Array();
    this.FlashVars[idx][0] = name;
    this.FlashVars[idx][1] = value;
}

FlashObject.prototype.AddParam = function(name, value)
{
    var idx;
    
    idx = this.Params.length;
    this.Params[idx] = new Array();
    this.Params[idx][0] = name;
    this.Params[idx][1] = value;
}


FlashObject.prototype.Draw = function()
{
    var html, embed, idx, param, flashVars, flashVar;
    
    html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + this.Width + '" height="' + this.Height + '">\r\n';
    html += '\t<param name="movie" value="' + this.Movie + '" />\r\n';
           
    if (this.FlashVars.length > 0)
    {
        flashVars = '';

        for (idx=0; idx<this.FlashVars.length; idx++)
        {
            flashVar = this.FlashVars[idx];
            flashVars += flashVar[0] + '=' + flashVar[1] + '&';
        }
        
        flashVars = flashVars.substring(0, flashVars.lastIndexOf('&'));
        
        this.AddParam('FlashVars', flashVars);
    }
    
    embed = '\t<embed src="' + this.Movie + '" width="' + this.Width + '" height="' + this.Height + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
    
    for (idx=0; idx<this.Params.length; idx++)
    {
        param = this.Params[idx];       
        html += '\t<param name="' + param[0] + '" value="' + param[1] + '" />\r\n';
        embed += param[0] + '="' + param[1] + '" ';
    }
    
    embed += '/>\r\n';
    
    html += embed;
    html += '</object>';
       
    this.Container.innerHTML = html;    
}

FlashObject.prototype.constructor = FlashObject;