///<Summary>
///     The FlashPlugin class represents the actual Macromedia Flash 
///     Plugin control responsible for rendering .swf files.
///</Summary>
///<Remarks>
///     The class constructor accepts 3 paramaters:
///     1. The path to the .swf file
///     2. The width the movie should render
///     3. The height the movie should render
///</Remarks>
function FlashPlugin(swfPath,width,height) {
    var self = this;
    var m_swfPath = swfPath;
    var m_width = width;
    var m_height = height;
    var objectReference = null;
    var objectId = Math.round(Math.random()*100000000); 
    
    var navigatorPluginModel = function() 
    {
        if(navigator.plugins && navigator.mimeTypes.length)
        { 
            return navigator.plugins["Shockwave Flash"];
        }
        else 
        {
            return null;
        }
    }
    
    
    var iExplorerPluginModel = function() 
    {
        if(window.ActiveXObject)
        { 
            try
            {   
                var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                return axo;
            }
            catch(e)
            {
                return null;
            }
        }
        else
        {
            return null;
        }
    }
    
    
    this.toString = function()
    {
        var objTag = "";
        objTag += "<object id=" + objectId + " classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,14,0\" width=" + width + " height=" + height + " VIEWASTEXT>";
	    objTag += "<param name=\"movie\" value=" + m_swfPath + ">";
	    objTag += "<param name=\"quality\" value=\"high\">";
	    objTag += "<param name=\"flashvars\" value=\"\">";
	    objTag += "<embed name=" + objectId + " src=" + m_swfPath + " flashvars=\"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=" + width + " height=" + height + ">";
	    objTag += "</embed></object>";
	    return objTag;
    }
    
    
    
    this.SetVariable = function(varName, varValue) 
    {
        if(objectReference == null) 
        {
             objectReference = (navigator.appName.indexOf ("Microsoft") != -1)? document.getElementById(objectId):window.document[objectId];
        }
		objectReference.SetVariable(varName, varValue);
    }
    
    
    
    this.GetVersion = function() //Integer
    {        
        var playerVersion = 0;

	    if(this.IsInstalled()) 
        {
	        if (iExplorerPluginModel()) 
	        {
	            try 
	            {
   		            playerVersion = iExplorerPluginModel().GetVariable("$version").split(" ")[1].split(",");
	            } 
	            catch (e) {playerVersion = 0;}
	        }
	        else if(navigatorPluginModel())
	        {
		        if(navigatorPluginModel().description) 
		        {
			        playerVersion = navigatorPluginModel().description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
		        }
	        } 
        }
	    playerVersion = parseInt(playerVersion.toString().substring(0,1));
	    return playerVersion;
    }
    
    
    
    
    this.IsInstalled = function() //: Boolean
    {
        if(null != navigatorPluginModel())
        {
            return true;
        } 
        else if(null != iExplorerPluginModel()) 
        {
            return true;
        }
        return false;
    }
}

