var allTimeStart = 0;
var allTimeCount = 10;
var todayStart = 0;
var todayCount = 10;

var allowAllTimeNext = true;
var allowTodayNext = true;

function loadAllTime(operation, start, count)
{
	if(allTimeStart < 0) {
		allTimeStart = 0;
	}
	if(todayStart < 0) {
		todayStart = 0;
	}
	if(start < 0) {
		start = 0;
	}
	$.get("gettop.php", { 'op' : operation, 'start' : start, 'count' : count },
		function(data) {
			$.each(data.players,
				function(i,item) {
					$("#" + data.table + "_n" + i).html(item.name);
					$("#" + data.table + "_c" + i).html(item.count);
				});
			for(i=data.players.length;i<10;i=i+1) {
				$("#" + data.table + "_n" + i).text("");
				$("#" + data.table + "_c" + i).text("");
			}
			$("#gentime").text(data.time);
			if(data.players.length < 10) {
				if(operation == "alltime") {
					allowAllTimeNext = false
				} else if(operation == "today") {
					allowTodayNext = false;
				}
			}
				
		}, "json");
}

$(function() {
	$("a#allTimePrev").click(function() {
		allTimeCount = 10;
		allTimeStart = allTimeStart - 10;
		allowAllTimeNext = true;
		loadAllTime("alltime", allTimeStart, allTimeCount);
		return false;
	});
	$("a#allTimeNext").click(function() {
		if(allowAllTimeNext) {
			allTimeCount = 10;
			allTimeStart = allTimeStart + 10;
			loadAllTime("alltime", allTimeStart, allTimeCount);
		}
		return false;
	});
	$("a#todayPrev").click(function() {
		todayCount = 10;
		todayStart = todayStart - 10;
		allowTodayNext = true;
		loadAllTime("today", todayStart, todayCount);
		return false;
	});
	$("a#todayNext").click(function() {
		if(allowTodayNext) {
			todayCount = 10;
			todayStart = todayStart + 10;
			loadAllTime("today", todayStart, todayCount);
		}
		return false;
	});
});
