

var MoviePlayer = Class.create();
MoviePlayer.prototype = {
	
	initialize: function(element, options) {
		this.options = Object.extend({
			url:			null,
			preview:		null,
			type:			null,
			width:			320,
			height:			240,
			autostart:		false
		}, options || {});		
		
		this.element = $(element);
		
		if (this.options.url) {
			if (this.options.type == 'video/x-flv') {
				if (Plugin.isInstalled('Flash')) {
					Plugin.embed('Flash', {
						src: "/plugins/types/movie/player/flvplayer.swf?file=" + encodeURIComponent(this.options.url) + (this.options.preview ? '&image=' + this.options.preview : '') + '&autostart=' + (this.options.autostart ? 'true' : 'false') + '&type=flv&overstretch=fit', 
						width: this.options.width, 
						height: this.options.height + 20
					}, this.element); 
				} 
			} else {
				if (this.options.type) {
					var plugins = Plugin.getPluginsForMimeType(this.options.type);
				} else {
					var suffix = /([a-zA-Z0-9]+)(\?.*)?$/.exec(this.options.url);
					var plugins = Plugin.getPluginsForFileSuffix(suffix[1]);
				}
				
			
				if (plugins.length) {
					var plugin = plugins.pop();

					if (Plugin.isInstalled(plugin)) {
						Plugin.embed(plugin, {
							width: this.options.width, 
							height: this.options.height, 
							src: this.options.url, 
							autostart: this.options.autostart ? 'true' : 'false', 
							controller: 'true', 
							type: this.options.type}, 
						this.element);
					}
				}	
			}
		}
	}
};
