$(function() {
	// Inizializza le tabs di jquery
	$('#box_news > ul').tabs({ selected: lang, fx: { opacity: 'toggle' } });
	$('#box_news').show();
	// Carica la pagina della squadra al variare della select
	$('#menu select').change(function () { window.location = '/squadre/' + $('#menu select option:selected').val() + '/'; } );
	$('#rubriche > ul').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '61px' });
	$('#rubriche_contenitore').show();
});

// Player
var player;
var curVideo = 0;

function playerReady(obj) {
	var id = obj['id'];
	var version = obj['version'];
	var client = obj['client'];
	player = document.getElementById(id);
	player.addControllerListener("ITEM","onNextVideo");
	$('#video_corrente > h1').text($('#video_0 h2 a').text());
};

function onNextVideo(obj) {
	$('#' + curVideo + ' h2 a').css({ 'color' : '#000' });
	var nextVideo = 'video_' + obj['index'];
	// Se non è il primo filmato, visualizza i controlli video e inserisce gli onclick sul palinsesto
	if (obj['index'] > -1) { 
		$('#player_wrapper').animate( { height: '228px' }, 'normal' );
//			$('.video h2').each(function(i) {
//				this.html('<a href="#" onclick="play(\'' + i + '\'); return false;">' + this.text() + '<\/a>');
//			});
	}
	$('#' + nextVideo + ' h2 a').css({ 'color' : '#F00' });
	$('#video_corrente > h1').text($('#' + nextVideo + ' h2 a').text());
	$('#lista_video').scrollTo('#' + nextVideo, 800, { axis : 'y' });
	curVideo = nextVideo;
}

function play(id) {
	player.sendEvent('ITEM', id);
}