this.PSP = this.PSP || {};
this.PSP.Widgets = this.PSP.Widgets || {};

this.PSP.Widgets.Video = new Class({

	Implements: [Options, Events],

	options: { type: null,
			   file: null,
			   id: null,
			   width: 640,
			   height: 480,
			   padding: 10,
			   urls: { baseUrl: null } },

	initialize: function(element, options)
	{
		this.setOptions(options);

		$(element).addEvent('click',function(e)
		{
			var liteboxWidth = parseInt(this.options.width) + this.options.padding * 2;
			var liteboxHeight = parseInt(this.options.height) + this.options.padding * 2;

			var box = new PSP.Litebox(
			{
				formEl: {width: liteboxWidth, height: liteboxHeight },
				closeEl: {src: this.options.urls.baseUrl + 'public/website/images/closed.png' }
			});

			box.addEvent('shown', function(formEl)
			{
				new Element(
					'div',
					{
						id: 'play-video-wrapper',
						styles:
							{
								margin: this.options.padding,
								border: '1px solid #000',
								width: this.options.width,
								height: this.options.height
							}
					}
				).inject(formEl);

				this._getVideoObj();

			}.bind(this));

			box.show();

		}.bind(this)
		);


	},

	_getVideoObj: function()
	{
		var displayHeight = this.options.height - 18;

		var FO ={
				movie: this.options.urls.baseUrl + 'public/website/components/widgets/video/flvplayer.swf',
				width: this.options.width,
				height: this.options.height,
				flashvars: ('type=' + this.options.type
						+ '&file=' + encodeURIComponent(this.options.file)
						+ '&id=' + encodeURIComponent(this.options.id)
						+ '&overstretch=true'
						+ '&usefullscreen=true'
						+ '&displayheight=' + displayHeight
						+ '&backcolor=0x000000'
						+ '&frontcolor=0xffffff'
						+ '&lightcolor=0xa9f249'
						+ '&repeat=list'
						+ '&shuffle=false'
						+ '&autostart=true'),
			  allowfullscreen: true,
			  majorversion: 8,
			  build: 0
		  };

		UFO.create(FO, 'play-video-wrapper');
	}
});
