function loadCalendario(callback){
	jQuery.getJSON(
			blogThemeJs + '/json-tornei.php', 
	        function(json) {callback(json)}
	);
}
function createRow(StartDate,Name,GameType,LimitType,TableType,BuyIn,PrizePool,Status){
	 return '<tr><td>'+StartDate+'</td><td>'+Name+'</td><td>'+GameType+'</td><td>'+LimitType+'</td><td>'+TableType+'</td><td>'+BuyIn+'</td><td>'+PrizePool+'</td><td>'+Status+'</td></tr>';	
}
$(document).ready(function(){	
	$("#mini-col-right-calendario").ajaxStart(function(){
		$("#loading").show();
		 });
	$("#mini-col-right-calendario").ajaxComplete(function(){
		$("#loading").hide();
		 });
	//se il div calendario tornei esiste
	if ( $("#calendario-tornei").length > 0 ) 
	{
		// Allora devo costruire la tabella
		loadCalendario(
				function (json) {
					table = '';
				    table += "<div id='scroller'><table id='calendario-table' class='tablesorter'><thead>";
				    table += "<tr><th>Data d’inizio</th><th>Nome</th><th>Gioco</th><th>Limite</th><th>Tavolo</th><th>Buy-In</th><th>Montepremi</th><th>Stato</th></th></thead><tbody>";
					
				    jQuery.each(json.Tournaments, function(i,Tournament){
				    	table += createRow(Tournament.StartDate,Tournament.Name,Tournament.GameType,Tournament.LimitType,Tournament.TableType,Tournament.BuyIn,Tournament.PrizePool,Tournament.Status);
					});
					
					table += "</tbody></table></div>"
					
					$("#mini-col-right-calendario").append(table);
					$("#calendario-table").tablesorter();
				}
		);
	}
	//se il div calendario tornei home esiste
/*	else if ($("#calendario-tornei-home").length > 0)
	{
		//allora devo costruire il box in homepage
		alert("box in homepage");
	}*/
	
});