$(function() {
	// Inizializza le tabs di jquery
	$('#box_news > ul').tabs({ selected: lang, fx: { opacity: 'toggle' } });
	// Carica la pagina della squadra al variare della select
	$('#menu select').change(function () { window.location = '/squadre/' + $('#menu select option:selected').val() + '/'; } );
});

// 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");
	//player.addControllerListener("LINK","onLink");
	$('#video_corrente > h1').text($('#video_0 h2 a').text());
};
function onLink(obj) {
	alert('ok');
}
function myFunction() {
	alert('You clicked !\n\nExecute your function here...');
}
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);
}