//	http://www.alistapart.com/articles/flashsatay/

var Flash = Class.create({
	initialize: function(id, src, width, height, vars, xlate) {
		this.id		= id || "";
		this.src	= src || "";
		this.width	= width || "";
		this.height	= height || "";
		this.vars	= vars || "";
		this.xlate	= xlate || {"title" : "", "error" : "", "text" : ""};
	},
		  
	toString: function() {
		var txt = "";
		
		if (Flash.hasFlash()) {
			txt	+= "<object data='" + this.src + "' width='" + this.width + "px' height='" + this.height + "px' id='" + this.id + "' title='" + this.xlate.title + "' type='application/x-shockwave-flash'>";
			txt	+= "<param name='movie' value='" + this.src + "'/>";
			txt	+= "<param name='flashvars' value='" + this.vars + "'/>";
			txt += "<param name='quality' value='high'/>";
			txt	+= "<param name='wmode' value='transparent'/>";
			txt	+= "<param name='allowfullscreen' value='true'/>";
			txt	+= "<param name='allowScriptAccess' value='sameDomain'/>";
			
			if (this.xlate.text && this.xlate.text != "") {
				txt	+= "<p>" + this.xlate.text + "</p>";
			}
			
			txt	+= "</object>";
		} else {
			txt	+= Flash.showError(this.width, this.height, this.xlate.error);
		}
			
		return txt; 
	}
});

Object.extend(Flash, {
	hasFlash: function() {
		var version = null;
	
		if (navigator.plugins && navigator.mimeTypes.length) {
			var plugin = navigator.plugins["Shockwave Flash"];
	
			if (plugin && plugin.description) {
				version = plugin.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
			}
		} else if (window.ActiveXObject) {
			try {
				var xobject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				version = xobject.GetVariable("$version").split(" ")[1].split(",");
			} catch(e) {}
		}
		
		/*
		if (version) {
			version[0] = parseInt(version[0], 10);
			version[1] = parseInt(version[1], 10);
			version[2] = parseInt(version[2], 10);
			
			Common.log("Flash player v." + version[0] + "." + version[1]);
		}
		*/
		
		return version;
	},
	
	showError: function(width, height, error) {
		var txt = "";
	
		txt	+= "<table style='width:" + width + "px; height:" + height + "px; border-spacing:0px; filter:alpha(opacity=60); opacity:0.6'>";
		txt	+= "<tr><td align='center' style='background-color:#F2FED4; border:1px dashed #666666;'>";
		
		if (error && error != "") {
			txt	+= "<a href='http://get.adobe.com/flashplayer/' target='flash'>" + error + "</a>";
		}
		
		txt	+= "</td></tr>";
		txt	+= "</table>";
	
		return txt;
	}
});


