/*:._.:*:._.:*:._.:*:._.:*:._.:*:._

Flash Detect & Insertion Class

Copyright (c) 2004 Polychrome Studio, Inc.
http://www.polychrome.org/
- - - - - - - - - - - - -
Created:   2004/08/06
Modified:  2005/10/30
Author(s): Christian Rocha <christian@polychrome.com>

CHANGELOG:

2005/10/03
    .flashDetect() is now a method of the Flash
    object and is now called 'detect()'

*:._.:*:._.:*:._.:*:._.:*:._.:*:._.:*/

/**
 * Constructor
 */
function Flash(url, width, height, quality)
{
    // 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
    
    // Protected Variables
    
    this.flashVarsObject = ''; // stores FlashVars data for the <object> tag
    this.flashVarsEmbed  = ''; // 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  += ' flashVars="' + key + '=' + value + '">';
    },
    
    /**
     * Outputs the HTML
     * access public
     */
    write : function()
    {
        this.compile();
        document.write(this.flashHTML);
    },

    /**
     * Builds HTML to embed
     * access protected
     */
    compile : function()
    {
        this.flashHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://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 + '" />'
		 + '<param name="wmode" value="opaque" />'
         + this.flashVarsObject
         + '<embed src="' + this.url + '" quality="' + this.quality + '"' + this.flashVarsEmbed + ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="opaque" width="' + this.width + '" height="' + this.height + '"></embed>'
         + '</object>';
    }
};
