function scrollCarousel(start, count)
{
	if (start == null)
	{
		start = 0;
	}
	if (count == null)
	{
		count = 100;
	}

	// calculate the amount we nede to scroll by
	var cw = $("#scrollercontainer").width();
	var dw = $("#scrolldata").width();
	var diff = cw - dw;

	// calculate a reasonable scroll rate for the animate function
	var l = $("#scrolldata").position().left;
	var duration = (l - diff) * 15; // increase 15 to make slower

	// add the events to pause scrolling if mouseover
	$("#scrollercontainer").mouseover(function()
	{
		if (carousel_paused == false)
		{
			$("#scrolldata").pauseAnimation();
			carousel_paused = true;
		}
	});
	$("#scrollercontainer").mouseout(function()
	{
		if (carousel_paused == true)
		{
			$("#scrolldata").resumeAnimation();
			carousel_paused = false;
		}
	});

	// start scrolling data
	$("#scrolldata").startAnimation({ left: diff }, duration, 'linear', function()
	{
		// fix at the right size so we can remove items on left without moving it
		$("#scrolldata").css("right", "0px");
		$("#scrolldata").css("left", "");

		// remove half the items in the set
		var halfsize = $("#scrolldata .scrollitem").size() / 2;
		for (var i = 0; i < halfsize; i++)
		{
			$("#scrolldata .scrollitem:first").remove();
		}

		// calculate the new starting position to resume scrolling
		cw = $("#scrollercontainer").width();
		dw = $("#scrolldata").width();
		diff = cw - dw;
		// fix it at the left so we can now add items to the right
		$("#scrolldata").css("left", diff + "px");
		$("#scrolldata").css("right", "");

		// get next set of items and add into the list
		$.ajax({
			type: "POST",
			url: "/service.asmx/GetCarousel",
			data: "{start:" + start + ", count:" + (halfsize != 0 ? halfsize : count) + "}",
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			success: function(response)
			{
				// add items into list
				var data = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
				for (var i = 0; i < data.Count; i++)
				{
					$("#scrolldata").append("<span class=\"scrollitem\">" + data.Names[i] + " | </span>");
				}
				$.cookie("carousel_start", (data.Start + data.Count));
				$.cookie("carousel_total", data.Total);
				// scroll again
				scrollCarousel(data.Start + data.Count, count);
			},
			failure: function(msg)
			{
				//alert(msg);
				scrollCarousel();
			}
		});

	});
}

var carousel_paused = false;

function startCarousel()
{
	var start = $.cookie("carousel_start");
	if (start == null || start.length == 0)
	{
		start = 0;
	}
	setTimeout("scrollCarousel(" + start + ", 20)", 250);
}


