// Based on FlashTag.js class by Macromedia
// Thanks to FlashObject sample /tutorials (http://blog.deconcept.com/flashobject/) by Geoff Stearns for the Flash Detection method basis

function FlashElement(src, width, height){
	this.src = src;
	this.width = width;
	this.height = height;
	this.version = "8,0,15,0";
	this.id = "flashMovie";
	this.className = "";
	this.style = "";
	this.bgcolor = "#ffffff";
	this.quality = "high";
	this.scaleMode = "noscale";
	this.stageAlign = "LT";
	this.allowScriptAccess = "always";
	this.flashVars = null;
	this.isPlugin = this._detectPlugin();
}

var p = FlashElement.prototype;

p.toString = function(){
    var isMS = (navigator.appName.indexOf ("Microsoft") != -1) ? true : false;
    var str = "";
    if (isMS)
    {
        str += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" type="application/x-shockwave-flash" ';
        str += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.version + '" ';
		str += 'id="' + this.id + '" ';
		str += 'className="' + this.className + '" ';
		str += 'style="' + this.style + '" ';
		str += 'width="' + this.width + '" ';
        str += 'height="' + this.height + '">';
        str += '<param name="movie" value="' + this.src + '" />';
		str += '<param name="src" value="' + this.src + '" />';
		str += '<param name="bgcolor" value="' + this.bgcolor + '" />';
        str += '<param name="quality" value="' + this.quality + '" />';
		str += '<param name="scale" value="' + this.scaleMode + '" />';
		str += '<param name="salign" value="' + this.stageAlign + '" />';
		str += '<param name="allowScriptAccess" value="' + this.allowScriptAccess + '" />';
        if(this.flashVars != null)
        {
            str += '<param name="flashvars" value="' + this.flashVars + '" />';
        }
        str += '</object>';
    }
    else
    {
        str += '<embed src="' + this.src + '" ';
        str += 'width="' + this.width + '" ';
        str += 'height="' + this.height + '" ';
		str += 'id="' + this.id + '" ';
		str += 'name="' + this.id + '" ';
		str += 'className="' + this.className + '" ';
		str += 'style="' + this.style + '" ';
		str += 'bgcolor="' + this.bgcolor + '" ';
		str += 'quality="' + this.quality + '" ';
		str += 'scale="' + this.scaleMode + '" ';
		str += 'salign="' + this.stageAlign + '" ';
		str += 'allowScriptAccess="' + this.allowScriptAccess + '" ';
		if (this.flashVars != null){
            str += 'flashvars="' + this.flashVars + '" ';
        }
        str += 'type="application/x-shockwave-flash" ';
        str += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
        str += '</embed>';
    }
    return str;
}

p.write = function(){
	if(this.isPlugin){
		var str = this.toString();
		document.write(str);
	}
}

p._detectPlugin = function(){
	var b = false;
	var plugin;
	if(navigator.plugins && navigator.mimeTypes.length){
		plugin = navigator.plugins["Shockwave Flash"];
		if(plugin && plugin.description) {
			b = true;
		}
	}else if (window.ActiveXObject){
		try {
		   plugin = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
		   b = true;
		}catch (e) {
			// do nothing
		}
	}
	return b;
}

delete p;


