$(function() {
	filter('nb_games','','top_games.php'); filter('nb_inlive','','top_inlive.php');
	time_games();
});

// compte le temps passe sur une table
function time_games()
{
	$(".time").find('.timer').each(function(){
		var id = $(this).attr('id');
		var date_recup = $('#'+id+'_date').html();

		setInterval(function() {
			var date = new Date();// Date actuelle
			var diff = Math.floor((date.getTime()/1000)-date_recup);

			var temps = diff%3600;
			var diff_h = (diff-temps)/3600;
			var diff_s = temps%60;
			var diff_m = (temps-diff_s)/60;
			if(diff_s<10) { diff_s = "0"+diff_s; }
			if(diff_m<10) { diff_m = "0"+diff_m; }
			if(diff_h<10) { diff_h = "0"+diff_h; }

			$("#"+id).html("");
			$("#"+id).append(diff_h+"h"+diff_m+"min");

		}, 1000);
	});
}

// change le type de table
function choice_table(type)
{
	$("#blind_add_view").hide();
	$('#blind_cash').hide();
	$('#blind_tournoi').hide();
	$('#blind_sit_go').hide();
	// cash games
	if(type=="1")
	{
		$('#hands_cash').show();
		$('#hands_tournoi').hide();
		$('#hands_sit_go').hide();
		$('#blind_cash_txt').show();
		$('#blind_tournoi_txt').hide();
		$('#blind_sit_go_txt').hide();
		$('#blind_cash').show();
		$('#blind_tournoi').hide();
		$('#blind_sit_go').hide();
		$('#help_depot').show();
		$('#create_depot_1').val('');
		var value_select = $('#create_blinds_cash_1 :selected').text();
		var big = value_select.split('-');
		$("#big_depot").html(big[1]);
		$("#big_1").html(big[1]*100);
		$("#big_2").html(big[1]*100/2);
		$("#big_4").html(big[1]*100/4);
		$('#create_type_view').hide();
		$('#type_all_in_txt').hide();
		$('#type_all_in').hide();
		$('#view_place').hide();
		$('#create_total_place_1').val('');
	}
	// tournoi
	else if(type=="2")
	{
		$('#hands_cash').hide();
		$('#hands_tournoi').show();
		$('#hands_sit_go').hide();
		$('#blind_cash_txt').hide();
		$('#blind_tournoi_txt').show();
		$('#blind_sit_go_txt').hide();
		$('#blind_cash').hide();
		$('#blind_tournoi').show();
		$('#blind_sit_go').hide();
		$('#help_depot').hide();
		var value_select = $('#create_blinds_tournoi_1 :selected').text();
		var big = value_select.split("+");
		var big_tot = parseFloat(big[0])+parseFloat(big[1]);
		$('#create_depot_1').val(big_tot.toFixed(2));
		$('#create_type_view').show();
		$('#type_all_in_txt').show();
		$('#type_all_in').show();
		$('#view_place').show();
		var value_seat = $('#create_hands_tournoi_1 :selected').text();
		if(value_seat.match("seats"))
		{
			var seat = value_seat.split(" seats");
			$('#create_total_place_1').val(seat[0]);
		}
		else { $('#create_total_place_1').val(''); }
	}
	// sit and go
	else if(type=="3")
	{
		$('#hands_cash').hide();
		$('#hands_tournoi').hide();
		$('#hands_sit_go').show();
		$('#blind_cash_txt').hide();
		$('#blind_tournoi_txt').hide();
		$('#blind_sit_go_txt').show();
		$('#blind_cash').hide();
		$('#blind_tournoi').hide();
		$('#blind_sit_go').show();
		$('#help_depot').hide();
		var value_select = $('#create_blinds_sit_go_1 :selected').text();
		var big = value_select.split("+");
		var big_tot = parseFloat(big[0])+parseFloat(big[1]);
		$('#create_depot_1').val(big_tot.toFixed(2));
		$('#create_type_view').show();
		$('#type_all_in_txt').hide();
		$('#type_all_in').hide();
		$('#view_place').show();
		var value_seat = $('#create_hands_sit_go_1 :selected').text();
		if(value_seat.match("seats"))
		{
			var seat = value_seat.split(" seats");
			$('#create_total_place_1').val(seat[0]);
		}
		else { $('#create_total_place_1').val(''); }
	}
}

// change le nombre de places totales pour les tournois
function change_seat(type)
{
	var hands_txt;
	if(type=="2") { hands_txt = "tournoi"; }
	else if(type=="3") { hands_txt = "sit_go"; }
	var value_seat = $('#create_hands_'+hands_txt+'_1 :selected').text();
	if(value_seat.match("seats"))
	{
		var seat = value_seat.split(" seats");
		$('#create_total_place_1').val(seat[0]);
	}
	else { $('#create_total_place_1').val(''); }
}

// affiche le div pour créer les blinds
function create_blind(value,type)
{
	$('#game_type_blind').val(type);
	if(value=="add") { $("#blind_add_view").show(); $("#small").focus(); }
	else { $("#blind_add_view").hide(); }
	// cash
	if(type=="1")
	{
		$('#sep_blind').html("-");
		$('#add_blind_txt').show();
		$('#add_buyin_txt').hide();
		$('#help_depot').show();
		var value_select = $('#create_blinds_cash_1 :selected').text();
		var big = value_select.split("-");
		$("#big_depot").html(big[1]);
		$("#big_1").html(big[1]*100);
		$("#big_2").html(big[1]*100/2);
		$("#big_4").html(big[1]*100/4);
	}
	// tournoi et sit and go
	else if(type=="2" || type=="3")
	{
		$('#sep_blind').html("+");
		$('#add_blind_txt').hide();
		$('#add_buyin_txt').show();
		$('#help_depot').hide();
		var blind_txt;
		if(type=="2") { blind_txt = "tournoi"; }
		else if(type=="3") { blind_txt = "sit_go"; }
		var value_select = $('#create_blinds_'+blind_txt+'_1 :selected').text();
		var big = value_select.split("+");
		var big_tot = parseFloat(big[0])+parseFloat(big[1]);
		$('#create_depot_1').val(big_tot.toFixed(2));
	}
}
