/**
 * Provides the functionality to embed flash content.
 * The code is basically lifted/borrowed from SWFObject written by Geoff Stearns.
 * Plugin Object was originally based on QtObject written by Geoff Stearns.
 * http://blog.deconcept.com/swfobject/
 */
// add the extension translations
PluginObject.Util.ExtensionTranslation.Flash = ['swf'];
PluginObject.Util.AliasTranslation.Flash = ['swf', 'flash'];

PluginObject.Plugins.Flash = function()
{
};

PluginObject.Plugins.Flash.prototype = {

	options:{
		upgrade_url			: 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash',
		_class_id			: 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
		_type				: 'application/x-shockwave-flash',
		quality				: 'high',
		use_express_install	: false,
		do_express_install	: false,
		xi_redirect_url		: window.location
	},

	_initiate: function(constructor, src, options)
	{
//		merge the default options with the plugin defaults
		PluginObject.Util.mergeObjects(constructor.options, this.options || {});

		constructor.installedVer = this._getPlayerVersion(constructor);
		constructor.addParam('quality', constructor.options.quality);
		var colour = constructor.options.bgcolor ? constructor.options.bgcolor : (constructor.options.bgcolour ? constructor.options.bgcolour : false);
		if(colour)
		{
			constructor.addParam('bgcolor', constructor.options.bgcolor);
		}
		constructor.setAttribute('useExpressInstall', constructor.options.use_express_install);
		constructor.setAttribute('doExpressInstall', constructor.options.do_express_install);
		constructor.setAttribute('xiRedirectUrl', constructor.options.xi_redirect_url);

		constructor.registerEvent('preExplorerBuild', {func:function(constructor)
		{
			if (constructor.getAttribute('do_express_install'))
			{
				constructor.addParam('MMplayerType', 'ActiveX');
				constructor.addParam('wmode', 'transparent');
			}
			var pairs = constructor.getVariablePairs().join('&');
			if(pairs.length > 0)
			{
				constructor.addParam('flashvars', pairs);
			}
		}});
		constructor.registerEvent('preNetscapeBuild', {func:function(constructor)
		{
			if (constructor.getAttribute('do_express_install'))
			{
				constructor.addVariable('MMplayerType', 'PlugIn');
			}
			var pairs = constructor.getVariablePairs().join('&');
			if (pairs.length > 0)
			{
				constructor.addParam('flashvars', pairs);
			}
		}});
	},

	_getPlayerVersion: function(constructor)
	{
		var PlayerVersion = new PluginObject.Util.PlayerVersion([0,0,0]);
		if(navigator.plugins && navigator.mimeTypes.length)
		{
			var x = navigator.plugins["Shockwave Flash"];
			if(x && x.description)
			{
				PlayerVersion = new PluginObject.Util.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
			}
		}
		else
		{
			try
			{
				var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
				for (var i=3; axo!=null; i++)
				{
					axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.'+i);
					PlayerVersion = new PluginObject.Util.PlayerVersion([i,0,0]);
				}
			}
			catch(e){}
			var reqVer = constructor.getAttribute('version');
			// version is ok, skip minor detection
			if (reqVer && PlayerVersion.major > reqVer.major)
			{
				return PlayerVersion;
			}
			// this only does the minor rev lookup if the user's major version
			// is not 6 or we are checking for a specific minor or revision number
			// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			if (!reqVer || ((reqVer.minor != 0 || reqVer.rev != 0) && PlayerVersion.major == reqVer.major) || PlayerVersion.major != 6 || constructor.options.use_express_install)
			{
				try
				{
					PlayerVersion = new PluginObject.Util.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
				}
				catch(e){}
			}
		}
		return PlayerVersion;
	},

	_detect: function(constructor, version)
	{
		return (constructor.installedVer.versionIsValid(version));
	}

};

/* fix for video streaming bug */
PluginObject.Util.cleanupSWFs = function()
{
	var objects = document.getElementsByTagName('object');
	for (var i=0; i < objects.length; i++)
	{
		for (var x in objects[i])
		{
			if (typeof objects[i][x] == 'function')
			{
				objects[i][x] = null;
			}
		}
	}
};
PluginObject.Util.observeEvent(window, 'unload',  function()
{
	PluginObject.Util.cleanupSWFs();
});
