Event.observe(window, 'load', init);

function init() {
	if($('active')) {
		Event.observe('active', 'click', unlink);
	}
	player_observe();
}

Ajax.Responders.register({
  onCreate: showLoading,
  onComplete: hideLoading
});

function showLoading() {
  if(Ajax.activeRequestCount > 0)
    $('loading').show();
}

function hideLoading () {
  if(Ajax.activeRequestCount <= 0)
    $('loading').hide();
}

function show_movie (e) {	
	Event.stop(e);
	$('player').show();
	$$('.news').invoke('hide');
	Event.observe('close_player', 'click', hide_movie);
}

function hide_movie(e) {
	Event.stop(e);
	$('player').hide();
	$$('.news').invoke('show');
}

function player_observe() {
	var playlinks = $$('.player');
	var len = playlinks.length;
	for (var i = 0; i<len; i++) {
		var player = playlinks[i];
		var id = player.identify();
		$(id).observe('click', show_movie)
	}
}

function unlink(e) {
	Event.stop(e);
}
