
var Flash = {

	plugin : (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0,

	/**
	 * returns true if flash player is available for version
	 */
	hasVersion : function(major, minor, revision) {

		var a = this.getVersion().split(",");
		var nWant = major * 100000 + minor * 1000 + revision;
		var nHas = parseInt(a[0]) * 100000 + parseInt(a[1] * 1000) + parseInt(a[2]);
		
		return nHas >= nWant;
	},

	/**
	 * returns flash player version (e.g. 10,1,52)
	 */
	getVersion : function() {
		try {
			try {
				// avoid fp6 minor version lookup issues
				// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
				var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
				try { axo.AllowScriptAccess = 'always'; }
				catch(e) { return '6,0,0'; }
			} catch(e) {}
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
		// other browsers
		} catch(e) {
			try {
				if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
					return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
				}
			} catch(e) {}
		}
		return '0,0,0';
	},

	/**
	 * returns html code for embedding a swf file
	 */
	embed : function(filename, w, h, parameters, flashVars) {

		// setup beginning of string
		var s = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0"';
		s += 'width="' + w + '" height="' + h + '">\n';
		// setup parameters
		var options = {
			allowScriptAccess: "sameDomain",
			allowFullScreen: "false",
			quality: "high",
			bgcolor: "#000000"
		}
		var prop = "";
		var i;
		
		for (prop in parameters) { options[prop] = parameters[prop]; }
		options.movie = filename;
		// add parameters to string
		for (prop in options) {
			s += '\t<param name="' + prop + '" value="' + options[prop] + '"/>\n';
		}
		// add flashVars to string
		if (flashVars != undefined) {
			i = 0;
			s += '\t<param name="FlashVars" value="';
			for (prop in flashVars) {
				if (i > 0) { s += "&" }
				s += prop + "=" + escape(flashVars[prop]);
				i++;
			}
			s += '"/>\n'
		}
		
		options.src = filename;
		options.type = "application/x-shockwave-flash";
		options.pluginspage = "http://www.macromedia.com/go/getflashplayer";
		options.width = w;
		options.height = h;
		s += "<embed\n";
		for (prop in options) {
			if (prop != "movie") { s += "\t" + prop + '="' + options[prop] + '"\n'; }
		}
		// add flashVars to embed
		if (flashVars != undefined) {
			i = 0;
			s += ' FlashVars="';
			for (prop in flashVars) {
				if (i > 0) { s += "&"; }
				s += prop + "=" + escape(flashVars[prop]);
				i++;
			}
			s += '"';
		}

		s += "/>\n</object>";

		return(s);
	}


}

