/**
 * @author Federico
 */

var VideoSz = new Class({
	
	Implements: [Events, Options],
	
	element: $empty,
	
	initialize: function($el, $options) {
		if(!$defined($el)) return;		
		this.setOptions($options);
		this.element = $type($el) == 'string' ? $($el) : $el;
		if(!$defined(this.element.get("id"))) return;
		this.json = JSON.decode(this.element.get("id"));		
		this.init();		
	},
	
	init: function() {
		var flashvars = {};
		var src = '';
		
		if (parseInt(this.json.easyplayer) == 1) {
			flashvars.flv = this.json.url;
			flashvars.width = this.json.width;
			flashvars.height = this.json.height;
			flashvars.img = $defined(this.json.imgUrl) ? this.json.imgUrl : '';
			src = "/pubblico/public/inc/swf/EasyPlayer.swf";
		} else {
			src = this.json.url;
		}
		
		if( src.substring(src.length-1) == '\\' )
			src = src.substring(0,src.length-1);
		
		this.swiff = new Swiff(src, {
			id: 'VideoSzEmbed_' + this.json.videoid,
			container: this.element,
			width: "100%",
			height: "100%",
			params: {
				wMode: 'opaque',					
				allowFullScreen: "true",
				bgcolor: '#000000'
			},
			vars: flashvars
		});
		this.element.setStyle("height", (this.element.getSize().x*9)/16);	
	}	
	
});
 
var VideoSzManager = new Class({
	
	Implements: [Events, Options],
	items: $empty,
	
	initialize: function($option) {
		this.setOptions($option);
		this.items = [];
		this.init();
	},
	
	init: function($options){
		$$('.videoszembed').each(function($el){
			this.items.push(new VideoSz($el));		
		},this);
	}
});
