var VideoPlayer = new Class({
	options: {
		width: 275,
		height: 226,
		autostart: false,
		playerTarget: 'player',
		playerSWF: 'flvplayer.swf'
	},
	initialize: function(options){
		this.setOptions(options);		
		$$('a').forEach(function(elem) {
			if (elem.rel == 'video') {
				elem.url_flv = elem.href;
				elem.addEvent('click', this.click.bindWithEvent(this, [elem.url_flv, elem.getAttribute('title'), true]));
				elem.href = '#' + elem.id.substr(6);			
			}
		}, this);
		this.videoTitle = $('videoTitle');		
	},	
	click: function (event, url_flv, title, autostart) {
		//event.stop();
		this.play(url_flv, title, autostart);
	},
	play: function(url_flv, title, autostart) {
		if (typeof autostart == 'undefined') {
			autostart = this.options.autostart;
		}
		if (typeof title != 'undefined') {
			this.videoTitle.innerHTML = title
		} else {
			this.videoTitle.innerHTML = '';
		}
		
		var file = url_flv;		
		var so = new SWFObject(this.options.playerSWF, "mpl", this.options.width, this.options.height, '7');
		so.addParam('allowfullscreen', 'true');
		so.addParam('allowscriptaccess', 'true');
		so.addVariable('file', file);
		so.addVariable('height', this.options.height);
		so.addVariable('width', this.options.width);
		so.addVariable('autostart', autostart);
		so.addVariable('repeat', 'list');
		so.addVariable('shuffle', 'false');
		so.addVariable("enablejs","true");
		so.addVariable("javascriptid","mpl");
		so.write(this.options.playerTarget);
	},
	load: function(id) {
		var elem = $(id);
		if (elem) {
			this.play(elem.url_flv, elem.getAttribute('title'), false);
		}		
	}
});
VideoPlayer.implement(new Options, new Events);

