/**
 * PluginObject Package.
 *
 * Embeds different type of plugins.
 * Easy Useable. Easily extendable.
 *
 * PluginObject is based upon the excellent work of Geoff Stearns and does
 * indeed re-use much code from both SWFObject or QtObject.
 *
 * PluginObject Copyright (c) 2007 to Author:
 *          Oliver Lillie <publicmail@buggedcom.co.uk> <http://www.buggedcom.co.uk/>
 *
 * SWFObject and QtObject Copyright (c) 2007 to Author:
 *			Geoff Stearns <geoff@deconcept.com> <http://www.deconcept.com/>
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
var PluginObject = function(src, options)
{
/**
 * Default options
 */
	this.options = {
		version					: 1,
		version_fail_message	: 'The current version of the %PluginType% plugin is too old. You currently have version %PluginVersion% but you need at least version %PluginRequiredVersion% to view this plugin. We suggest that you upgrade %PluginType% to the latest version. To upgrade please <a href="%PluginUpgradeUrl%" target="_blank">click here</a>. However, you may wish to try running the plugin in your current version <a href="%PluginObjectNoDetectUrl%">click here</a>.',
		version_fail_redirect	: false,
		detect_key				: 'detect_plugin',
		auto_embed				: true,
		embed_id				: undefined,
		memorise_detect_status	: true,
		cookie_expiry			: new Date().getTime()+31449600000,
		cookie_path				: '/',
		cookie_domain			: null,
		cookie_secure			: false,
		placeholder				: false,
		placeholder_alt			: 'PluginObject placeholder.',
		placeholder_title		: 'Click to view plugin.',
		width					: 100,
		height					: 100,
		id						: null,
		use_plugin				: null,
		file_extension			: null,
		params					: {},
		variables				: {},
		attributes				: {}
	};
	this.Controller = null;
	this.Plugin = null;
	this._id = null;
	this._initiate(src, options)
};

// intiate the instances of the plugin and controls
PluginObject.Plugins = new Object();
PluginObject.Controls = new Object();
PluginObject.References = new Object();

RETURN_HTML = -1239876450;

PluginObject.prototype = {

	Version: '1.0.0',

//	private vars
	_events: {},

/**
 * Event management functions.
 */
	registerEvent: function(event, object)
	{
		this._events[event] = object;
	},
	hasEvent: function(event)
	{
		return typeof this._events[event] != 'undefined';
	},
	dispatchEvent: function(event, args)
	{
		if(this._events[event])
		{
			if(typeof this._events[event].func == 'function')
			{
				return this._events[event].func.apply(this._events[event].obj, args);
			}
		}
		return null;
	},
	removeEvent: function(event)
	{
		delete this._events[event];
	},

/**
 * Attribute and Param setter getters.
 */
	setMany: function(type, object)
	{
		for(var i in object)
		{
			this.options[type][i] = object[i];
		}
	},
	setAttributes: function(object)
	{
		this.setMany('attributes', object);
	},
	setAttribute: function(name, value)
	{
		this.options.attributes[name] = value;
	},
	getAttribute: function(name)
	{
		return this.options.attributes[name];
	},
	addParams: function(object)
	{
		this.setMany('params', object);
	},
	addParam: function(name, value)
	{
		this.options.params[name] = value;
	},
	getParams: function()
	{
		return this.options.params;
	},
	addVariables: function(object)
	{
		this.setMany('variables', object);
	},
	addVariable: function(name, value)
	{
		this.options.variables[name] = value;
	},
	getVariable: function(name)
	{
		return this.options.variables[name];
	},
	getVariables: function()
	{
		return this.options.variables;
	},
	getVariablePairs: function()
	{
		var variablePairs = [];
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},

/**
 * initiates the plugin object
 */
	_initiate: function(src, options)
	{
		if (!document.createElement || !document.getElementById)
		{
			return;
		}

		this.options.id = 'PluginObject_'+PluginObject.Util.generateRandomID(20);
		this._id = PluginObject.Util.generateRandomID(20);

//		merge the default options with those submitted
		PluginObject.Util.mergeObjects(this.options, options || {});

//		determine the plugin type
		var alias = this.options.use_plugin != null ? this.options.use_plugin : false;
		this.use_plugin = PluginObject.Util.getPluginType(src, alias, this.options.file_extension);

//		detect if the plugin should be detected or not
		this.options.detect_key += '_'+this.use_plugin.toLowerCase();
		var detection = PluginObject.Util.getRequestParameter(this.options.detect_key);
		this.skip_detect = detection == 'false';
		if(detection == 'true' || detection == 'false')
		{
			if(this.options.memorise_detect_status)
			{
				var t = new Date().getTime();
				var e = this.options.cookie_expiry;
				var c = 'PluginObject'+this.use_plugin+'Memory=' + detection
					+ '; expires=' + new Date(( t > e ? t + e : e )).toGMTString()
					+ (this.options.cookie_path ? '; path=' + this.options.cookie_path : '')
					+ (this.options.cookie_domain ? '; domain=' + this.options.cookie_domain : '')
					+ (this.options.cookie_secure ? '; secure' : '');
			}
		}
		else
		{
			if(this.options.memorise_detect_status)
			{
//				should detect from cookie if found
				var p = document.cookie.indexOf(escape('PluginObject'+this.use_plugin+'Memory')+'=');
				var cv = false;
				if(p != -1)
				{
					var pv = p + 'PluginObject'+this.use_plugin+'Memory='.length;
					var ep = document.cookie.indexOf(';', pv);
					if(ep != -1)
					{
						cv = unescape(document.cookie.substring(pv, ep));
					}
					else
					{
						cv = unescape(document.cookie.substring(pv));
					}
					this.skip_detect = true;
				}
			}
		}

//		set the attributes of the required data
		this.setAttribute('src', src);
		if(this.options.element_id)
		{
			this.setAttribute('id', this.options.element_id);
		}
		else
		{
			this.setAttribute('id', 'PluginObject_plugin_'+this._id);
		}
		this.setAttribute('width', this.options.width);
		this.setAttribute('height', this.options.height);

		if(this.options.version)
		{
			this.setAttribute('version', new PluginObject.Util.PlayerVersion(this.options.version.toString().split('.')));
		}
		else
		{
			this.setAttribute('version', new PluginObject.Util.PlayerVersion([1,0,0]));
		}

//		create the plugin item
		this.Plugin = new PluginObject.Plugins[this.use_plugin]();

//		absorb uncommon functions. This
		this._absorbUncommonFunctions();

//		if there is a control instance available initiate it
		if(typeof PluginObject.Controls[this.use_plugin] == 'function')
		{
			this.Controller = new PluginObject.Controls[this.use_plugin]();
		}

//		initiate plugin
		this.Plugin._initiate(this, src, this.options);
		this.setAttribute('classid', this.options._class_id);
		this.setAttribute('type', this.options._type);

//		if the item is to auto embed then write it out
		if(this.options.auto_embed)
		{
			this.write(this.options.embed_id);
		}

	},

/**
 * Creates references to uncommon functions declared in the sub plugin classes.
 */
	_absorbUncommonFunctions: function()
	{
//		loop through the plugin instance looking for functions to absorb
		for(var i in this.Plugin)
		{
			if(i.substr(0, 1) == '__')
			{
				if(typeof this.Plugin[i] == 'function')
				{
//					create a reference function
					this[i] = function()
					{
						var args = arguments;
						args.push(this);
						this.Plugin[i.substr(2, i.length)].apply(this.Plugin, args);
					};
				}
			}
		}
	},

/**
 * Replaces the placeholder with the plugin
 */
	_activateFromPlaceholder: function()
	{
		this.options.placeholder = null;
		var activate = true;
		if(this.hasEvent('placeholderActivation'))
		{
			activate = this.dispatchEvent('placeholderActivation', [this, 'PluginObject_placeholder_'+this._id, 'PluginObject_wrapper_'+this._id]);
		}
		if(activate)
		{
			this.activate();
		}
	},

	activate: function()
	{
		document.getElementById('PluginObject_placeholder_'+this._id).style.display = 'none';
		if(!this.options.element_id)
		{
			this.options.embed_id = 'PluginObject_wrapper_'+this._id;
		}
		else
		{
			this.options.embed_id = this.options.element_id;
		}
		this.write(this.options.embed_id);
	},

/**
 * Returns the placeholder html. First checks to see if the plugin has a function for returning the html.
 * If it does it returns that instead of the default.
 */
	_getPlaceholderHTML: function()
	{
		var html;
		if(!(html = this.dispatchEvent('prePlaceholderHTML', [this])))
		{
//			alias the callback
			PluginObject.References[this._id] = this;
			if(typeof this.Plugin._getPlaceholderHTML == 'function')
			{
				html = this.Plugin._getPlaceholderHTML(this);
			}
			else
			{
				html = '<img id="PluginObject_placeholder_'+this._id+'" src="'+this.options.placeholder+'" width="'+this.options.width+'" height="'+this.options.height+'" title="'+this.options.placeholder_title+'" alt="'+this.options.placeholder_alt+'" style="cursor:pointer;" onclick="PluginObject.References[\''+this._id+'\']._activateFromPlaceholder();" />';
			}
			if(!this.options.element_id)
			{
				html = '<div id="PluginObject_wrapper_'+this._id+'">'+html+'</div>';
			}
//			check modification of html
			var modified_html;
			if((modified_html = this.dispatchEvent('postPlaceholderHTML', [html])))
			{
				html = modified_html;
			}
		}
		return html;
	},

/**
 * Write out the html for the plugin.
 * NOTE: if element_id = RETURN_HTML, then the html is returned and not written
 */
	write: function(element_id)
	{
		var element;
		if(typeof element_id == 'string')
		{
			if(!(element = document.getElementById(element_id)))
			{
				throw('PluginObject [ERROR] - PluginObject was unable to write the '+this.use_plugin+' plugin ('+this.getAttribute('src')+') to "'+element_id+'" because the element was not found in the DOM.');
			}
		}
		this.dispatchEvent('preWriteGet', []);
		if(this.skip_detect || this.Plugin._detect(this, this.getAttribute('version')))
		{

			var init_controller = false;
			if (this.options.placeholder)
			{
				this.pluginHTML = this._getPlaceholderHTML();
			}
			else
			{
				this.pluginHTML = this._getHTML();
				init_controller = true;
			}

//			check modification of html
			var modified_html;
			if((modified_html = this.dispatchEvent('preWrite', [this, this.pluginHTML, (this.options.placeholder)])))
			{
				this.pluginHTML = modified_html;
			}

			if(element_id === RETURN_HTML)
			{
//				return the html if required
				return this.pluginHTML;
			}

//			output the html
			if(typeof element == 'undefined')
			{
				if(!PluginObject.Util.document_has_loaded)
				{
					document.write(this.pluginHTML);
				}
				else
				{
					throw('PluginObject [ERROR] - PluginObject was unable to write the '+this.use_plugin+' plugin ('+this.getAttribute('src')+') because the element the page has already loaded. You must specify an "embed_id" for PluginObject to write into.');
				}
			}
			else
			{
				element.innerHTML = this.pluginHTML;
			}

			this.dispatchEvent('postWrite', [this, element_id, (this.options.placeholder)]);

//			the controller can't be inited if we are outputting a place holder
			if(init_controller)
			{
//				if there is a controller instance initiate it
				if(this.Controller != null)
				{
					if(this.Controller._initiate)
					{
						this.Controller._initiate(element_id, PluginObject.References[this._id]);
					}
				}
			}
			return true;
		}
		else
		{
			if(this.options.version_fail_redirect)
			{
				document.location.replace(this.options.version_fail_redirect);
			}
			else
			{
//				output the version error message
				var message = this.options.version_fail_message;
				message = message.split('%PluginType%').join(this.use_plugin);
				message = message.split('%PluginVersion%').join(this.installedVer.toString());
				message = message.split('%PluginRequiredVersion%').join(this.getAttribute('version'));
				message = message.split('%PluginUpgradeUrl%').join(this.options.upgrade_url);
				var url = document.location.href;
				url += (url.indexOf('?') == -1 ? '?' : '&')+this.options.detect_key+'=false';
				message = message.split('%PluginObjectNoDetectUrl%').join(url);
				if(typeof element == 'undefined')
				{
					if(!PluginObject.Util.document_has_loaded)
					{
						document.write(message);
					}
					else
					{

					}
				}
				else
				{
					element.innerHTML = message;
				}
			}
		}
		return false;
	},

	_getHTML: function(embedable, force_embed)
	{
		if(typeof this.Plugin._getHTML == 'function')
		{
			return this.Plugin._getHTML(this, embedable, force_embed);
		}
		var html = '';
		var params = this.getParams();
//		netscape plugin architecture
		if ((PluginObject.Util.is_netscape && !embedable) || force_embed)
		{
			this.dispatchEvent('preNetscapeBuild', [this]);
			html = '<embed type="'+ this.getAttribute('type') +'" src="'+ this.getAttribute('src') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			html += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			for(var key in params)
			{
				html += [key] +'="'+ params[key] +'" ';
			}
			html += '/>';
			this.dispatchEvent('postNetscapeBuild', [this]);
		}
//		PC IE
		else
		{
			this.dispatchEvent('preExplorerBuild', [this]);
			html = '<object id="'+ this.getAttribute('id') +'" classid="'+ this.getAttribute('classid') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			html += '<param name="src" value="'+ this.getAttribute('src') +'" />';
			for(var key in params)
			{
				html += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			if(embedable)
			{
				html += this._getHTML(embedable, true);
			}
			html += "</object>";
			this.dispatchEvent('postExplorerBuild', [this]);
		}
		return html;
	},


/**
 * Returns an embedable html code. ie for embeding on blogs.
 * NOTE: it does not validate the plugin version.
 */
	getEmbedCode: function()
	{
		return this._getHTML(true).split(' id="'+ this.getAttribute('id') +'"').join('').split(' name="'+ this.getAttribute('id') +'"').join('');
	},
/**
 * Returns an embedable html code for MySpace.
 * NOTE: it does not validate the plugin version.
 */
	getMySpaceEmbedCode: function()
	{
		return this._getHTML(false, true).split(' id="'+ this.getAttribute('id') +'"').join('').split(' name="'+ this.getAttribute('id') +'"').join('');
	}

};
// alias the write function as embed
PluginObject.prototype.embed = PluginObject.prototype.write;

// Add Array.push if needed (ie5)
if (Array.prototype.push == null)
{
	Array.prototype.push = function(item)
	{
		this[this.length] = item;
		return this.length;
	};
}
if (Array.prototype.inArray == null)
{
	Array.prototype.inArray = function(item)
	{
		var l = this.length;
		for(var i=0; i<l; i++)
		{
			if(this[i] == item)
			{
				return true;
			}
		}
		return false;
	};
}
// intiate the plugin utilities
PluginObject.Util = new Object();
PluginObject.Util = {
	ExtensionTranslation: {},
	AliasTranslation: {},
	is_netscape: !(!(navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length)),
	oldLoad: function(){},
/**
 * Get a request parameter from the document url.
 */
	getRequestParameter: function(param)
	{
		var q = document.location.search || document.location.hash;
		if(q)
		{
			var startIndex = q.indexOf(param +'=');
			var endIndex = (q.indexOf('&', startIndex) > -1) ? q.indexOf('&', startIndex) : q.length;
			if (q.length > 1 && startIndex > -1) {
				return q.substring(q.indexOf('=', startIndex)+1, endIndex);
			}
		}
		return '';
	},
/**
 * Determines the plugin type from the extension of the src it's provided with
 */
	getPluginType: function(src, alias, extension)
	{
		if(alias)
		{
			var obj = PluginObject.Util.AliasTranslation;
		}
		else
		{
			var obj = PluginObject.Util.ExtensionTranslation;
			if(!extension)
			{
				var qmark_pos = src.indexOf('?');
				if(qmark_pos != -1)
				{
					src = extension.substr(0, qmark_pos);
				}
				extension = src.split('.').pop().toLowerCase();
			}
		}
		for(var plugin in obj)
		{
			if(obj[plugin].inArray(extension))
			{
				return plugin;
			}
		}
		if(alias)
		{
			throw('PluginObject [ERROR] : "'+extension+'" is not an alias of a known plugin type.');
		}
		else
		{
			throw('PluginObject [ERROR] : There is no plugin associated with files that have the extension "'+extension+'".');
		}
		return null;
	},

/**
 * Borrows heavily from the Prototype Javascript Library. see Object.extend
 * Merges to objects properties together.
 */
	mergeObjects: function(destination, source)
	{
		for (var property in source)
		{
			destination[property] = source[property];
		}
		return destination;
	},
/**
 * Observes DOM events.
 */
	observeEvent: function(element, name, observer, useCapture)
	{
		if (element.addEventListener)
		{
			element.addEventListener(name, observer, useCapture);
		}
		else if (element.attachEvent)
		{
			element.attachEvent('on' + name, observer);
		}
	},

/**
 * Generates a random id
 */
	generateRandomID: function(len)
	{
		var source = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789012345678901234567890123456789'.split('');
		var total = source.length;
		var str = '';
		for(var i=0; i<len; i++)
		{
			var index = Math.floor(Math.random()*total);
			str += source[index];
		}
		return str;
	}
};


/**
 * Creates a player version object.
 */
PluginObject.Util.PlayerVersion = function(arrVersion)
{
	this.major = parseInt(arrVersion[0]) != null ? parseInt(arrVersion[0]) : 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
};
PluginObject.Util.PlayerVersion.prototype.versionIsValid = function(version)
{
	if(this.major < version.major)
	{
		return false;
	}
	if(this.major > version.major)
	{
		return true;
	}
	if(this.minor < version.minor)
	{
		return false;
	}
	if(this.minor > version.minor)
	{
		return true;
	}
	if(this.rev < version.rev)
	{
		return false;
	}
	return true;
};
PluginObject.Util.PlayerVersion.prototype.toString = function()
{
	return this.major+'.'+this.minor+'.'+this.rev;
};

PluginObject.Util.document_has_loaded = false;
PluginObject.Util.observeEvent(window, 'load',  function()
{
	PluginObject.Util.document_has_loaded = true;
});

// Add a quick reference to the get from query string function
var GET = PluginObject.Util.getRequestParameter;

/**
 * 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();
});

// add the extension translations
PluginObject.Util.ExtensionTranslation.Quicktime = ['mov', 'mpeg', 'mpg', 'avi', 'mp3', 'acc', 'qt', 'wav', 'au', '3gp', '3gpp'];
PluginObject.Util.AliasTranslation.Quicktime = ['qt', 'quicktime'];

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

PluginObject.Plugins.Quicktime.prototype = {

	options:{
		upgrade_url			: 'http://www.apple.com/quicktime/download/',
		_class_id			: 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
		_type				: 'video/quicktime'
	},

	_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);
		if(options.bgcolor)
		{
			constructor.addParam('bgcolor', options.bgcolor);
		}
	},

	_getPlayerVersion: function(constructor)
	{
		var PlayerVersion = new PluginObject.Util.PlayerVersion([0,0,0]);
		var foundPlayerVersion;
		if(navigator.plugins && navigator.mimeTypes.length)
		{
			for (var i=0; i < navigator.plugins.length; i++)
			{
				var x = navigator.plugins[i];
				if (x.name.indexOf("QuickTime") > -1)
				{
					// if multiple plugins are installed, find the latest version
					if (!foundPlayerVersion)
					{
						PlayerVersion = new PluginObject.Util.PlayerVersion([1,0,0]);
					}
					foundPlayerVersion = new PluginObject.Util.PlayerVersion(x.name.replace(/([a-z]|[A-Z]|-|\s)+/, "").split("."));
					if (foundPlayerVersion.versionIsValid(PlayerVersion))
					{
						PlayerVersion = foundPlayerVersion;
					}
				}
			}
		}
		else
		{
			var axo = null;
			try
			{
				axo = new ActiveXObject("QuickTimeCheckObject.QuickTimeCheck.1");
			}
			catch(e)
			{
				axo = null;
			}
			if (axo)
			{
				PlayerVersion = new PluginObject.Util.PlayerVersion([1,0,0]);
				if (axo.QuickTimeVersion)
				{
					// get the leading 3 hex digits
					var v = axo.QuickTimeVersion >> 16;
					PlayerVersion = new PluginObject.Util.PlayerVersion([(v & 0xf00) >> 8, (v & 0x0f0) >> 4, v & 0x00f]);
				}
			}
		}
		return PlayerVersion;
	},

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

};
// add the extension translations
PluginObject.Util.ExtensionTranslation.WindowsMediaPlayer = ['wmv', 'wma', 'wvx', 'wax', 'asf', 'asx'];
PluginObject.Util.AliasTranslation.WindowsMediaPlayer = ['wmp', 'mediaplayer', 'windowsmedia', 'windowsmediaplayer', 'windowsmp'];

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

PluginObject.Plugins.WindowsMediaPlayer.prototype = {
	
	options:{
		upgrade_url			: 'http://www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx',
		_class_id			: 'clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6',
		_type				: 'application/x-mplayer2'
	},
	
	_initiate: function(constructor, src, options)
	{
//		merge the default options with the plugin defaults
		PluginObject.Util.mergeObjects(constructor.options, this.options || {});
		
		constructor.installed = this._getPlayerVersion(constructor);
		if(options.bgcolor) 
		{ 
			constructor.addParam('bgcolor', options.bgcolor); 
		}
	},
	
	_getPlayerVersion: function(constructor)
	{
		var PlayerVersion = false;
		if(navigator.mimeTypes && navigator.mimeTypes["application/x-mplayer2"] && navigator.mimeTypes["application/x-mplayer2"].enabledPlugin)
		{
			PlayerVersion = true;
		}
		else
		{
			execScript('on error resume next: mpObj = IsObject(CreateObject("MediaPlayer.MediaPlayer.1"))','VBScript');
			PlayerVersion = mpObj;
		}
		return PlayerVersion;
	},
	
	_detect: function(constructor)
	{
		return (constructor.installed)
	}
	
};