var MediaPlugin = Class.create({
	has: function (plugin) {
		if (plugin == 'divx') {
			return this._has('DivX® Web Player') || this._has('DivX Web Player') || this._has('DivX Browser Plug-In');
		} else if (plugin == 'flash') {
			return this._has('Shockwave Flash');
		} else if (plugin == 'qt') {
			return this._has('QuickTime Plug-in', false);
		}
		return true;
	},

	_has: function (plugin, fullmatch) {
		if(Prototype.Browser.IE)
			return true;
		if(typeof(fullmatch) == 'undefined' || fullmatch == true)
			return typeof(navigator.plugins[plugin]) != 'undefined';
		for(i=0; i<navigator.plugins.length; i++)
			if(navigator.plugins[i].name.indexOf(plugin) >= 0)
				return true;
		return false;
	},

	divxVersion: function (cb) {
		var plugin = $(Prototype.Browser.IE ? 'divx_ie' : 'divx_np');
		if (!plugin) {
			$$('body')[0].insert(this.divxNode({width: 220, height: 220, id: 'divxtest'}));
			plugin = $(Prototype.Browser.IE ? 'divxtest_ie' : 'divxtest_np');
			if (!plugin) {
				return 'unable to init plugin';
			}
			var remove = true;
		}
		var version = plugin.GetVersion();
		!remove || $('divxtest_ie').remove();
		return version;
	},

	divxNode: function (params) {
		('object' == typeof params) || (params = {});

		('undefined' != typeof params.src) || (params.src = '');
		var id = ('undefined' != typeof params.id) ? params.id : 'divx'; //  + Math.floor(Math.random() * 100 + 1);
		var width = ('undefined' != typeof params.width) ? params.width : '';
		var height = ('undefined' != typeof params.height) ? params.height : '';
		delete params.width;
		delete params.height;
		delete params.id;
//		var obj = new Element('object', {id: id + '_ie', classid: 'clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616', codebase: 'http://go.divx.com/plugin/DivXBrowserPlugin.cab', width: width, height: height});
//		var embed = new Element('embed', {id: id + '_np', type: 'video/divx', pluginspace: 'http://go.divx.com/plugin/download/', width: width, height: height});
		if (Prototype.Browser.IE || true) {
			var sparams = '';
			for (var param in params) {
				sparams += ' ' + param + '="' + params[param] + '"';
			}
			var embed = '<embed id="' + id + '_np" type="video/divx" pluginspace="http://go.divx.com/plugin/download/" width="' + width + '" height="' + height + '"' + sparams + '/>';
			sparams = '';
			for (var param in params) {
				sparams += '<param name="' + param + '" value="' + params[param] + '"/>';
			}
			return '<object id="' + id + '_ie" classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab" width="' + width + '" height="' + height + '">' + sparams + embed + '</object>';
		}
		var embed = document.createElement('div');
//		for (prop in params) {
//			alert(params.prop);
//		}
//		(new Hash(params)).each(function (item) {
/*			sparams += '<param name="' + item.key + '" value="' + item.value + '"/>';
			var p = document.createElement('param');
			p.setAttribute('name', item.key);
			p.setAttribute('value', item.value);
			obj.appendChild(p);
//			obj.appendChild((new Element('param', {name: item.key, value: item.value})).update());
			embed.writeAttribute(item.key, item.value);*/
//		});
//		obj.insert(sparams);
		obj.insert(embed);
		return obj;
	}
});