/**
 * Videoplayer behavior
 */
var FnVideo = Class.create();
FnVideo.prototype = {

	/**
	 * Initialize
	 */
	initialize : function(elm){
		this.baseElm = elm;
    this.playButton = new Element('a').addClassName('play').insert('Play').writeAttribute('href', '#');
    this.playScreen = this.baseElm.select('img').first();
    this.noFlash = this.baseElm.select('p').first();
    this.videoUrl = this.baseElm.select('p a.download').first().readAttribute('href');

    // save width & height
    this.baseElm.setStyle({ width: '270px', height: '200px' });

    // prepare player
    this.player = new SWFObject('/ui/javascripts/flash/player.swf','mpl','270','200','4');
    this.player.addParam('allowscriptaccess','always');
    this.player.addParam('allowfullscreen','false');
    this.player.addParam('flashvars','&file='+this.videoUrl+'&frontcolor=000000&lightcolor=000000&screencolor=000000&autostart=true');
    
    // set initial behavior
    this.noFlash.hide();
		this.playButton.observe('click', this.handlePlayClick.bind(this)); 
    this.baseElm.insert(this.playButton);
	},

	/**
	 * Play video
	 */
	play : function(){
  
    this.playButton.hide();
    this.playScreen.hide();

    this.player.write(this.baseElm);

	},

	/**
	 * Handle click event on play button
	 */
	handlePlayClick : function(event){
		event.stop();
		this.play();
	}


  

}

