/**
 * @author p.stenzel
 */
if(!com) var com={};
if(!com.videotaxi) com.videotaxi={};
if(!com.videotaxi.trailer) com.videotaxi.trailer={};

com.videotaxi.trailer = {
	vtid: 0,
	trailer_url: "",
	ani: true,
	title: "",
	registerHandlers: function()	{
//		$('einleitung').getElementById("plz").observe('change',function(event)	{})
		var self = this;
		var els = $$('[trailer=true]');
		els.each(function(el){
			el.observe('click',function(event){
				self.initTrailer(el);
			})
		})
	},
	initTrailer: function(el)	{
		this.trailer_url = el.readAttribute('trailer_url');
		this.title = el.readAttribute('title');
		
		var content = "<div id='headline'>"
			+this.title
			+"<img id='modal_closebutton' src='/images/default/icons/cross.png' />"
		+"</div>";
		if(this.login_einleitung)	content+="<div id='einleitung'>"+this.login_einleitung+"</div>";
		content += "<center><object "
			+"classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' "
			+"codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' "
			+"width='384' "
			+"height='216' "
			+"id='Klappe_Trailer_Player' "
			+"align='middle'>"
			+"<param "
				+"name='allowScriptAccess' "
				+"value='sameDomain' />"
			+"<param "
				+"name='movie' "
				+"value='"+this.trailer_url+"' />"
			+"<param "
				+"name='quality' "
				+"value='high' />"
			+"<param "
				+"name='bgcolor' "
				+"value='#000000' />"
			+"<embed "
				+"src='"+this.trailer_url+"' "
				+"quality='high' "
				+"bgcolor='#000000' "
				+"width='384' "
				+"height='216' "
				+"name='Klappe_Trailer_Player' "
				+"align='middle' "
				+"allowScriptAccess='sameDomain' "
				+"type='application/x-shockwave-flash' "
				+"pluginspage='http://www.macromedia.com/go/getflashplayer' />"
		+"</object></center>";
		var mod = com.videotaxi.boxes.insertModal();
		if(mod)	{
			this.showTrailer(content);
			var controller='artikelliste';
			if(document.URL.include('vorschau')){
				controller = 'vorschau';
			}
			Utilities.trackEvent(controller,'trailer',this.title,this.trailer_url);
		}	else	{
			/**
			 * @TODO Bessere Fehlermeldung. Globale Methode zur Fehlerausgabe?
			 */
			alert("Ein Fehler ist aufgetreten.\nBitte versuche es zu einem späteren Zeitpunkt noch einmal.")
		}
	},
	showTrailer: function(content)	{
		$('modalfg_content').update(content);
		$('modal_closebutton').observe('click',function()	{
			com.videotaxi.boxes.toggleModal(true);
		})
		
		com.videotaxi.boxes.toggleModal(this.ani);
	}
}
