var start = 0;
var count = 20;

function loadList(operation)
{
	var showingNonNumbered = false;
	if(operation == "")
		showingNonNumbered = true;
	if(start < 0 && !showingNonNumbered)
	{
		start = 0;
	}
	if(start > 10320)
	{
		start = 10320;
	}
	$.get("getgibuses.php", { 'op' : operation, 'start' : start, 'count' : count },
		function(data) {
			$("#gibuslist").html(data.html);
			$("#gentime").text(data.time);
			if(!showingNonNumbered)
			{
				window.location.hash = start + 1;
				$("input#gotoNum").val(start+1);
			}
		}, "json");
}

function doLoadPrev() {
	if(start != 0)
	{
		count = 20;
		start = start - 20;
		loadList("withnum");
	}
	return false;
}

function doLoadNext() {
	count = 20;
	start = start + 20;
	loadList("withnum");
	return false;
}

$(function() {
	if(window.location.hash != "" && window.location.hash != "#")
	{
		start = parseInt(window.location.hash.substring(1)) - 1;
	}
	loadList();
});

$(function() {
	$("a#loadPrevTop").click(doLoadPrev);
	$("a#loadPrev").click(doLoadPrev);
	$("a#loadNextTop").click(doLoadNext);
	$("a#loadNext").click(doLoadNext);
	$("a#showAll").click(function() {
		count = 12000;
		start = 0;
		$("#gibuslist").text("Loading...");
		loadList("withnum");
	});
	$("button#gotoBtn").click(function() {
		count = 20;
		start = parseInt($("input#gotoNum").val()) - 1;
		loadList("withnum");
	});
});
