var FlashMovie = function(source, width, height, required)
{
	if (source == null) return;
	this.source = source;
	this.width = width;
	this.height = height;

	if (required)
	{
		required = new String(required).split(".");
		this.required = new Array(parseInt(required[0]), parseInt(required[1]), parseInt(required[2]));
	}
	else
	{
		this.required = new Array(7, 0, 0);
	}

	this.parameters = new Object();
	this.parameters['align'] = 'middle';
	this.parameters['salign'] = 'tl';
	this.parameters['menu'] = false;
	this.parameters['quality'] = "best";
	this.parameters['bgcolor'] = "#ffffff";
	this.parameters['allowScriptAccess'] = 'always';

	this.variables = new Object();
}

FlashMovie.prototype.getPlayerVersion = function()
{
	if (document.FLASH_PLAYER_VERSION) return document.FLASH_PLAYER_VERSION;

	if (navigator.plugins && navigator.mimeTypes.length)
	{
		var plugin = navigator.plugins["Shockwave Flash"];
		if (plugin && plugin.description)
		{
			version = plugin.description.split(" ");
			version = version[2] + '.' + String(version[4]).slice(1);
			version = version.split(".");
		}
	}
	else
	{
		try
		{
			var plugin = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			for (var i = 3; plugin != null; i++) { plugin = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i); }
			i--;
		}
		catch(error) { }

		if (i == 6) version = new Array(6, 0, 0);
		else if (i > 2)
		{
			try { var version = plugin.GetVariable("$version").split(" ")[1].split(","); }
			catch(error) { }
		}
	}

	if (version)
	{
		document.FLASH_PLAYER_VERSION = version;
		return new Array(parseInt(version[0]), parseInt(version[1]), parseInt(version[2]));
	}

	return new Array(0, 0, 0);
}

FlashMovie.prototype.generateHTML = function()
{
	var flashvars = new Array();
	for (var name in this.variables) { flashvars.push(name + "=" + this.variables[name]); }
	if (flashvars.length > 0) this.parameters['flashvars'] = flashvars.join("&");
	
	var html = '';

	if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length)
	{
		html = "<embed type=\"application/x-shockwave-flash\" src=\"" + this.source + "\" width=\"" + this.width + "\" height=\"" + this.height + "\"";
		if (this.id) html += " id=\"" + this.id + "\"";

		for (var name in this.parameters)
		{
			html += " " + name + "=\"" + this.parameters[name] + "\"";
		}

		html += " />";
	}
	else
	{
		html = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"" + this.width + "\" height=\"" + this.height + "\"";
		if (this.id) html += " id=\"" + this.id + "\"";
		html += "><param name=\"movie\" value=\"" + this.source + "\" />";

		for (var name in this.parameters)
		{
			html += "<param name=\"" + name + "\" value=\"" + this.parameters[name] + "\" />";
		}

		html += "</object>";
	}

	if (this.style != undefined) html = "<div style=\"" + this.style + "\">" + html + "</div>";

	return html;
}

FlashMovie.prototype.setVariable = function(name, value) { this.variables[name] = value; }
FlashMovie.prototype.setParameter = function(name, value) { this.parameters[name] = value; }

FlashMovie.prototype.create = function(id)
{
	if (id && this.hasPlayerVersion(this.getPlayerVersion()))
	{
		document.getElementById(id).innerHTML = this.generateHTML();
	}
}

FlashMovie.prototype.hasPlayerVersion = function(version)
{
	if (version[0] > this.required[0]) return true;
	else if (version[0] < this.required[0]) return false;
	else if (version[1] > this.required[1]) return true;
	else if (version[1] < this.required[1]) return false;
	else if (version[2] < this.required[2]) return false;
	return true;
}