// Flash Detection Object with variable support
// -----------------------------------------------------------------------------

var Flash = {

	hasVersion: function (versionRequired) {
		if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
			var description = navigator.plugins["Shockwave Flash"].description;
			var version = parseInt (description.charAt (description.indexOf (".") - 1));
			return version >= versionRequired;
		}
		if (navigator.appVersion.indexOf ("Windows") != -1 && window.execScript) {
			this.hasVersionResult = null;
			execScript ('on error resume next: Flash.hasVersionResult=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + versionRequired + '"))','VBScript');
			return this.hasVersionResult;
		}
		return false;
	},

	redirect: function (versionRequired, noFlashPage, noRedirectFlag) {
		if (document.referrer.indexOf (noFlashPage) != -1) return;
		if (noRedirectFlag && window.location.search.indexOf (noRedirectFlag) != -1) return;
		if (!this.hasVersion (versionRequired)) window.location.href = noFlashPage;
	}

}


var Flashtag = function(version, movie, width, height) { 
	this.flashversion = version;
	this.movie = movie;
	this.width = width;
	this.height = height;
	this.flashprops = new Array();
	this.flashvars = new Array();
};

Flashtag.prototype = {
	
	addProperty: function (name, value) {
		this.flashprops[name] = value;
	},
	
	addVariable: function (name, value) {
		this.flashvars[name] = value;
	},
	
	render: function () {
		f = "";
		
		for (var i in this.flashvars)  {
			if (typeof(this.flashvars[i]) != 'function') {
				f += 1 + "=" + this.flashvars[i] + "&";
			}
		}
		
		this.addProperty("FlashVars", f);
		
		tag = '<object';
		
		tag += ' width="' + this.width + '"';
		tag += ' height="' + this.height + '"';
		tag += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		tag += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.flashversion + ',0,0,0">';
		tag += '<param name="movie" value="' + this.movie + "?" + f + '" />';
		
		for (var i in this.flashprops) {
			if (typeof(this.flashprops[i]) != 'function') {
				tag += '<param name="' + i + '" value="' + this.flashprops[i] + '" />';
			}
		}
		
		tag += '<embed src="' + this.movie + "?" + f + '"';
		tag += ' type="application/x-shockwave-flash"';
		tag += ' pluginspage="http://www.macromedia.com/go/getflashplayer"';
		tag += ' width="' + this.width + '"';
		tag += ' height="' + this.height + '"';
		
		for (var i in this.flashprops) {
			if (typeof(this.flashprops[i]) != 'function') {
				tag += ' ' + i + '="' + this.flashprops[i] + '"';
			}
		}
		
		tag += '><\/embed>';
		tag += '<\/object>';
		
		return tag;
	}

}