var trailerwin;

Ext.onReady(function() {
	var hash = location.hash;
	if(hash.indexOf('info') != -1) {
		var id = hash.split('=')[1];
		
		if(!id.NaN) {
			showTrailer(id);
		}
	}
})


function placeRating(rating, id) {
	Ext.Ajax.request({
		url: '/inc/rating.php',
   		success: function(req) {
				var response = eval('(' + req.responseText + ')');
				
				if(typeof(response.ratingClass) !== 'undefined') {
					
					var el = Ext.query('.rating-' + id);
					
					Ext.each(el, function(item) {
						var item = Ext.fly(item);
						var stars = Ext.select('.rating-' + id + ' ul');
						var text = Ext.select('.rating-' + id + ' span');

						text.update(response.ratingCount + ' har stemt');
						stars.removeClass(['rating-no', 'rating-one', 'rating-two', 'rating-three', 'rating-four', 'rating-five']);
						stars.addClass(response.ratingClass);
						stars.removeClass('enabled');
						
						/*item.hide({
							callback: function() {
									text.update(response.ratingCount + ' har stemt');
									stars.removeClass(['rating-no', 'rating-one', 'rating-two', 'rating-three', 'rating-four', 'rating-five']);
									stars.addClass(response.ratingClass);
									stars.removeClass('enabled');
									item.show();		
								} 
						});*/
					});
				}
		},
   		failure: function() {
			},
		params: {
				rating: rating,
				id: id
		}
});

	
}

function showContent(title, url) {
			
	var win = new Ext.Window({
			width:820,
			 height: 'auto',
			 draggable: false,
			 resizable: false,
			 modal: true,
			 border: false,
			 bodyBorder: false,
			 autoLoad: {
				url: url,
				callback: function () {
		win.center();
		win.show();
				},
				scripts: true
				},
			title: title,
			renderTo: Ext.getBody()
	});
}

function showTrailer(id) {
	 
		location.href = '#info=' + id;
		var url = '/show-trailer.php?id=' + id;
		 
		trailerwin = new Ext.Window({
			width:820,
			id:'autoload-win',
			 height: 'auto',
			 draggable: false,
			 resizable: false,
			 modal: true,
			 border: false,
			 bodyBorder: false,
			 //disabled: true,
			 renderTo: Ext.getBody(),
			 autoLoad: {
				url: url,
				scripts: true,
				callback: function() {
					trailerwin.center();
					trailerwin.show();
			
				}
			},
			title: 'FILMINFO & TRAILER'
		    

		});
		
		trailerwin.on('close', function(){location.href = '#';});
}

function openFrameWindow(url, title, height) {
	 Ext.onReady(function() {
		
		var win = new Ext.Window({
			width:700,
			height: height,
			draggable: false,
			resizable: false,
			autoScroll:true,
			modal: true,
			shadow: 'drop',
			html: '<iframe src="' + url + '" border="0" frameborder="0" width="100%" height="' + (height-75) + '"></iframe>', 
			title: title
		});

		win.show();
	})}
