var Film = Class.create();

Film.prototype = 
{
    initialize: function(films) 
    {
		this.films = films;
		this.blocker = null;
    },
	getFilm: function(id)
	{
		for(var i = 0; i < this.films.length; i++)
		{
			if(this.films[i].id == id)
			{
				return this.films[i];
			}
		}
		
		return null;
	},
	showDetails: function(id)
	{
		var film = this.getFilm(id);
		if(film == null)
		{
			alert('Unknown film id: '+id);
			return false;
		}
		
		//popuplate details page
		$('film_thumbnail').src = 'thumbnail/'+film.id+'.jpg';
		$('film_title').innerHTML = film.title;
		$('film_year').innerHTML = film.year;
		$('film_cast').innerHTML = film.cast.replace(/\r\n|\r|\n/g, "<br/>");
		$('film_genre').innerHTML = film.genres.join('<br/>');
		$('film_runtime').innerHTML = film.runtime+'';
		$('film_trailer_div').style.display = 'none';
		$('film_trailer_div').innerHTML = '';
		
		$('film_synopsis').innerHTML = film.synopsis.replace(/\r\n|\r|\n/g, "<br/>");
		
		var width = RicoUtil.windowWidth();
		$('details_popup').style.top = (RicoUtil.docScrollTop()+50)+'px';
		$('details_popup').style.left = ((width-620)/2)+'px';
		$('details_popup').style.display = 'block';
		$('ui_block').style.width = width+'px';
		$('ui_block').style.height = document.body.clientHeight+'px';
		$('ui_block').style.display = 'block';
		//$('ui_block').style.width = width+'px';
		
		if(film.trailer.length > 0)
		{
			$('film_trailer_div').style.display = 'block';
			//$('film_trailer_div').innerHTML = '<embed width="450" height="269" border="0" bgcolor="#000000" controller="true" target="webbrowser" pluginspage="http://www.apple.com/quicktime/download/" scale="Aspect" autoplay="true" src="trailer/'+film.trailer+'"/>';
			/*$('film_trailer_div').innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0"'+
									'width="450" height="269" align="middle">'+
									'<param name="src" value="trailer/'+film.trailer+'" />'+
									'<param name="autoplay" value="true" />'+
									'<embed src="trailer/'+film.trailer+'" autoplay="true" width="450" '+
									'height="269" align="middle" bgcolor="black" '+
									'pluginspage="http://www.apple.com/quicktime/download/"> '+
									'</embed>'+
								'</object>';
				*/				
			$('film_trailer_div').innerHTML	= QT_WriteOBJECT_XHTML (
					"trailer/"+film.trailer, "450", "269", "",
					"autoplay","true",
					"border","0",
					"bgcolor","#000000",
					"target","webbrowser",
					"scale","Aspect",
					"controller","true"
				);

		}
		
	},
	hideDetails: function()
	{
		$('ui_block').style.display = 'none';
		$('details_popup').style.display = 'none';
		$('film_trailer_div').innerHTML = '';
	}	
}
