/**
 * Creates a new instance of the FlashTag.
 * src: The path to the SWF file.
 * width: The width of your Flash content.
 * height: the height of your Flash content.
 */
function FlashTag(src, width, height)
{
	// set defaults
	this.allowFullScreen = 'true';
	this.allowScriptAccess = 'samedomain';
    this.flashVars = null;
    this.height    = height;
    this.id        = null;
	this.seamlessTabbing = 'false';
    this.src       = src;
	this.variables = new Object();
    this.version   = '6,0,65,0';
    this.width     = width;
    //this.bgcolor   = 'ffffff';
}

/**
 * Sets the Flash version used in the Flash tag.
 */
FlashTag.prototype.setVersion = function(v)
{
    this.version = v;
}

/**
 * Sets the ID used in the Flash tag.
 */
FlashTag.prototype.setId = function(id)
{
    this.id = id;
}

/**
 * Sets the background color used in the Flash tag.
 */
FlashTag.prototype.setBgcolor = function(bgc)
{
    this.bgcolor = bgc;
}

/**
 * Sets any variables to be passed into the Flash content. 
 */
FlashTag.prototype.setFlashvars = function(fv)
{
    this.flashVars = fv;
}

/**
 * Add an individual flashvar
 */
FlashTag.prototype.addVariable = function(name, value){
	this.variables[name] = value;
}

/**
 * get all flashvars in ready-to-write format
 */
FlashTag.prototype.getFlashVars = function(){
	var variablePairs = new Array();
	var key;
	for(key in this.variables){
		variablePairs.push(key +"="+ variables[key]);
	}
	if(this.flashVars){
		variablePairs.push(this.flashVars);
	}
	return variablePairs.join("&");
}
/**
 * Get the Flash tag as a string. 
 */
FlashTag.prototype.toString = function()
{
    var ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
	this.getFlashVars();
    var flashTag = new String();
    if (ie)
    {
        flashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
        if (this.id != null)
        {
            flashTag += 'id="'+this.id+'" ';
        }
        flashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+'" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'">';
		flashTag += '<param name="allowFullScreen" value="'+this.allowFullScreen +'"/>';
		flashTag += '<param name="allowScriptAccess" value="'+this.allowScriptAccess+'"/>';
		flashTag += 'salign="">';
		flashTag += '<param name="base" value="."/>';
        flashTag += '<param name="movie" value="'+this.src+'"/>';
        flashTag += '<param name="quality" value="high"/>';
		flashTag += '<param name="seamlessTabbing" value="'+this.seamlessTabbing+'"/>';

		if(this.bgcolor != null)
		{
        	flashTag += '<param name="bgcolor" value="#'+this.bgcolor+'"/>';
		}
        if (this.flashVars != null)
        {
            flashTag += '<param name="flashvars" value="'+this.flashVars+'"/>';
        }
        flashTag += '</object>';
    }
    else
    {
        flashTag += '<embed src="'+this.src+'" ';
        flashTag += 'quality="high" '; 
		if(this.bgcolor != null)
		{
       		flashTag += 'bgcolor="#'+this.bgcolor+'" ';
		}	
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'" ';
        flashTag += 'align="middle" ';
		flashTag += 'base="." ';
        flashTag += 'allowFullScreen="'+this.allowFullScreen +'" ';
		flashTag += 'allowScriptAccess="'+this.allowScriptAccess+'" ';
        flashTag += 'type="application/x-shockwave-flash" ';
        if (this.flashVars != null)
        {
            flashTag += 'flashvars="'+this.flashVars+'" ';
        }
        if (this.id != null)
        {
            flashTag += 'name="'+this.id+'" ';
        }
        flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
		flashTag += 'seamlessTabbing="'+this.seamlessTabbing+'" ';
        flashTag += '</embed>';
    }
    return flashTag;
}

/**
 * Write the Flash tag out. Pass in a reference to the document to write to. 
 */
FlashTag.prototype.write = function(doc)
{
    doc.write(this.toString());

}

