var EmbedInfo = {};

function ShowTrailer(MovieObj){

	var MovieSlice = MovieObj.get('id').split("_");
	if(!$chk(EmbedInfo[MovieSlice[1]]))
		return ;
	var MovieInfo = EmbedInfo[MovieSlice[1]];

	var DivBack = new Element('div', {'styles': {
		'position': 'fixed',
		'background': '#000',
		'color':'#fff',
		'top':'0',
		'left':'0',
		'right':'0',
		'bottom':'0',
		'z-index':'10000'
	}, 'html': '&nbsp;', 'id':'DivBackTrailer'}).set('opacity','0.01').inject($('BodyMain'));

	new Fx.Tween(DivBack, {duration:1000, onComplete:function(){

		var EmbedContent = '<object width="'+MovieInfo.width+'" height="'+MovieInfo.height+'"><param name="movie" value="'+MovieInfo.url+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+MovieInfo.url+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+MovieInfo.width+'" height="'+MovieInfo.height+'"></embed></object>';
		var DivBack = $('DivBackTrailer');
		var CloseBarHeight = 30;
		var CloseLinkWidth = 80;

		var Container = new Element('div', {'styles':{
			'z-index':'10010',
			'position':'absolute',
			'width':MovieInfo.width+"px",
			'height':MovieInfo.height+"px",
			'background':'#fff',
			'overflow':'hidden'
		}, 'id':'DivTrailerContainer'}).inject($('BodyMain'));

		Container.set('html', EmbedContent);
		Container.setPosition({x:(DivBack.getSize().x/2).toInt()-(MovieInfo.width/2).toInt(), y:(DivBack.getSize().y/2).toInt()-(MovieInfo.height/2).toInt()+$('BodyMain').getScroll().y});

		var CloseBar = new Element('div', {'styles':{
			'z-index':'10005',
			'position':'absolute',
			'width':MovieInfo.width+"px",
			'height':CloseBarHeight+"px",
			'background':'#fff',
			'overflow':'hidden',
			'line-height':CloseBarHeight+"px",
			'font-weight':'bold',
			'visibility':'hidden'
		}, 'id':'DivTrailerCloseBar'}).inject($('BodyMain'));

		var MovieTitle = $('DivMovieTitle_'+MovieSlice[1]).get('html');
		MovieTitle = MovieTitle.replace(/\<br(\s*\/)?\>/i, ' <span style="font-weight:normal;">');
		MovieTitle += '</span>';

		new Element('div', {'styles': {
			'width':(MovieInfo.width-CloseLinkWidth-5)+"px",
			'float':'left',
			'padding-left':'5px',
			'text-align':'left',
			'font-size':'13px'
		}, 'html':MovieTitle}).inject(CloseBar);

		new Element('a', {'styles': {
			'color':'#a00',
			'text-decoration':'none'
		}, 'events': {
			'click':function(e){
				e = new Event(e).stop();
				$('DivBackTrailer').fireEvent('click');
			}
		}, 'text':'Fechar [X]', 'href':'#'}).inject(
			new Element('div', {'styles': {
				'width':(CloseLinkWidth-5)+"px",
				'padding-right':'5px',
				'float':'right',
				'text-align':'right'
			}}).inject(CloseBar)
		);

		CloseBar.setPosition({x:(DivBack.getSize().x/2).toInt()-(MovieInfo.width/2).toInt(), y:(DivBack.getSize().y/2).toInt()-(MovieInfo.height/2).toInt()+$('BodyMain').getScroll().y});
		DivBack.addEvent('click', function(e){ $('DivTrailerCloseBar').destroy(); $('DivTrailerContainer').destroy(); this.destroy(); });

		(function(){ CloseBar.setStyle('visibility','visible'); new Fx.Tween(CloseBar, {duration:1500, transition:Fx.Transitions.Sine.easeOut}).start('margin-top', CloseBarHeight*-1); }).delay(2000);

	}}).start('opacity','0.8');

}

window.addEvent('domready', function(e){
	$$('.DivMovieImg a').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
			ShowTrailer(this);
		});
	});
	$$('.DivMovieDescRight a').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
			ShowTrailer(this);
		});
	});
});

