/** * FlashTag.js * ----------- * Adapted from Macromedia's JavaScript integration kit. * * @author: Jeff Clarke * @version: 1.1 * @modified: April 11, 2007 *  * Generates a browser-specific Flash tag. Create a new instance, set whatever * properties you need, then call either toString() to get the tag as a string, or * call write() to write the tag out. *//** * 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, version){    if (arguments.length <4){    	var e = new Error("A new Flash Tag must be instantiated with src, width, height and version arguments.");		e.name = "FlashTag Instantiation Error";		throw (e);	}	for (var i=0; i<arguments.length; i++){		if (arguments[i] == null || arguments[i] == undefined){			var e = new Error("All FlashTag arguments must be defined values.");			e.name = "FlashTag Instantiation Error"			throw(e);		}	}		// required parameters	this.src       = src;    this.width     = width;    this.height    = height;    this.version   = version;	    this.id        = null;    this.flashVarsString = null;	this.flashVars = null	this.flashParam = new Object();	}/** * 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. */	setId: function(id){ 	   this.id = id;	},/** * Specifies the location (URL) of the Flash content to be loaded. */	setSource:function(src) {		this.src = src; 	},	/** * Specifies the width of the Flash content in either pixels or percentage of browser window.  */	setWidth:function(w) {		this.width = width; 	},/** * Specifies the height of the Flash content in either pixels or percentage of browser window.  */	setHeight:function(h) {		this.h = height; 	},/** * The required version of the Flash Player for the specified content.  */	setVersion:function(v) {		this.version = v;	},/** * Sets any variables to be passed into the Flash content.  */	setFlashvarString:function(fvs)	{		this.flashVarString = fvs;	},/** * Used to send root level variables to the Flash content. You can add as many name/value pairs as * you want. The formatting of the Flash vars (turning them into a query string) is handled automatically. */	addFlashVar:function(n, v) {		if (this.flashVars == null) {			this.flashVars = new Object();		}			this.flashVars[n] = v;	},/** * Used to remove Flash vars. This is primarily useful if you want to reuse an instance of the FlashTag * but you don't want to send the same variables to more than one piece of Flash content.  */	removeFlashVar:function(n) {		if (this.flashVars != null) {			this.flashVars[n] = undefined;		}	},/** * (window, opaque, transparent) Sets the Window Mode property of the Flash content for transparency, * layering, and positioning in the browser.  */	setWmode:function(wm) {		wm = wm.toLowerCase();		if (wm != 'window' && wm != 'opaque' && wm != 'transparent') {			var e = new Error("Supported values are 'window', 'opaque', and 'transparent'.");			e.name = "Unsupported FlashTag Value (setMode)";			throw(e);		}		this.flashParam['wmode'] = wm;	},/** * (low, high, autolow, autohigh, best) Sets the quality at which the Flash content plays. */	setQuality:function(q) {		q = q.toLowerCase();		if (q != 'low' && q != 'high' && q != 'autolow' && q != 'autohigh' && q != 'best') {			var e = new Error("Supported values are 'low', 'high', 'autolow', 'autohigh', and 'best'.");			e.name = "Unsupported FlashTag Value (setQuality)";			throw(e);		}		this.flashParam['quality'] = q;	},/*** sets script access for the flash tag to allow JS access from Flash*/	setScriptAccess:function(sa) {		sa = sa.toLowerCase();		if (sa != 'always' && sa != 'never') {			var e = new Error("Supported values are 'always' and 'never'.");			e.name = "Unsupported FlashTag Value (scriptAccess)";			throw(e);		}		this.flashParam['allowScriptAccess'] = sa;	},/*** sets the background color for the swf*/	setBgColor:function(color) {		if (color.charAt(0) != '#') {			color = '#' + color;		}		this.flashParam['bgcolor'] = color;	},/*** sets the background color for the swf*/	setMenu:function(useMenu) {		if (useMenu != 'true' && useMenu != 'false') {			var e = new Error("Supported values are 'true' and 'false'.");			e.name = "Unsupported FlashTag Value (setMenu)";			throw(e);		}		this.flashParam['menu'] = useMenu;	},/** * Get the Flash tag as a string.  */	toString:function(){		var ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;		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="movie" value="'+this.src+'"/>';						for (var n in this.flashParam) {				if (this.flashParam[n] != undefined && this.flashParam[n] != null){					flashTag += '<param name="'+n+'" value="'+this.flashParam[n]+'"/>';				}			}						if (this.flashVars != null || this.flashVarString != null){				var fvs = this.getFlashVarsAsString();				if (fvs.length >0){					flashTag += '<param name="flashvars" value="'+this.flashVars+'"/>';				}			}			flashTag += '</object>';		}		else		{			flashTag += '<embed src="'+this.src+'" ';			flashTag += 'width="'+this.width+'" ';			flashTag += 'height="'+this.height+'" ';			flashTag += 'type="application/x-shockwave-flash" ';			if (this.id != null){				flashTag += 'name="'+this.id+'" ';			}						for (var n in this.flashParam) {				if (this.flashParam[n] != undefined && this.flashParam[n] != null){					flashTag += (' '+n+'="'+this.flashParam[n]+'"');				}			}							if (this.flashVars != null || this.flashVarString != null){				var fvs = this.getFlashVarsAsString();				if (fvs.length >0){					flashTag += 'flashvars="'+fvs+'" ';				}			}						flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';			flashTag += '</embed>';		}		return flashTag;	},/* Function: getFlashVarsAsString * ------------------------------ * Iterates throrugh the flashvars object for valid name value pairs * and concats them to a string.  Then concats this string to the  * current flashvar string, if there is one. */	getFlashVarsAsString:function() {		var fvs = "";		for (var n in this.flashVars) {			if (this.flashVars[n] != undefined && this.flashVars[n] != null) {				fvs += (escape(n)+'='+escape(this.flashVars[n])+'&');			}		}				if (this.flashVarString != null) {			return fvs + this.flashVarString;		}		return fvs.substring(0, fvs.length-1);			},/** * Write the Flash tag out. Pass in a reference to the document to write to.  */	write:function(doc){		doc.write(this.toString());	},/* Function :fillElementById * ------------------------ * bypasses current limitations in Active Content code with IE by writing the Flash Content * inside of the Flash Tag js file. This bypasses the 'Click To Activate' problem. */	fillElementById:function(e){		var fc = document.getElementById(e);		fc.innerHTML = this.toString();	}}
