/**
 * Constructor
 */
function Flash(url, width, height, quality, isSecure)
{
    // Public Variables
    
    this.url    = url        || '';     // URL to the flash movie
    this.width   = width     || '';     // width of the flash movie
    this.height  = height    || '';     // height of the flash movie
    this.quality = quality   || 'HIGH'; // quality of the flash movie
    this.isSecure = isSecure || false;  // whether or not to use https in the codebase URL (to avoid IE complaining when loading SWF files over a secure connection)
    
    // Protected Variables
    
    this.flashVarsObject = ''; // stores FlashVars data for the <object> tag
    this.flashVarsEmbed  = ' flashVars="'; // stores FlashVars data for the <embed> tag
    this.flashHTML;            // stores the HTML to output
    
};

/**
 * Methods
 */
Flash.prototype = {
    
    /**
     * Detect Flash Player version
     * Returns false if player is not present, otherwise returns the version number
     */
    detect : function()
    {
        var version = 0;
        
        // Most browsers store plugin information in navigator.plugins...
        if (navigator.plugins && navigator.plugins.length) {
            
            var n = navigator.plugins["Shockwave Flash"];
            
            if(n && n.description) {
                var d = n.description;
                version = d.charAt(d.indexOf('.') - 1);
            }
        }
        
        // Internet Explorer, however, needs some VBScript for it's detection
        else {
            result = false;
            for(var i = 15; i >= 3 && result != true; i--) {
                execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
                version = i;
            }
        }
        
        return version;  
    },
   
    /**
    * Add Flash Variable
    * access public
    */
    addFlashVar : function(key, value)
    {
        this.flashVarsObject += '<param name="FlashVars" value="' + key + '=' + value + '">';
        this.flashVarsEmbed  += key + '=' + value + '&"';
    },
    
    /**
     * Outputs the HTML
     * access public
     */
    write : function()
    {
        this.compile();
        document.write(this.flashHTML);
    },

    /**
     * Builds HTML to embed
     * access protected
     */
    compile : function()
    {
        var secure = this.isSecure ? 's' : '';
        
        this.flashHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http' + secure + '://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + this.width + '" height="' + this.height + '">'
         + '<param name="movie" value="' + this.url + '" />'
         + '<param name="quality" value="' + this.quality + '" />'
         + this.flashVarsObject
         + '<embed src="' + this.url + '" quality="' + this.quality + '"' + this.flashVarsEmbed + ' pluginspage="http' + secure + '://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + this.width + '" height="' + this.height + '"></embed>'
         + '</object>';
    }
};