// Scroll the games list.
var scrollTimeout = false;
scrollGames = function(element, direction)
{

	// If we're not already scrolling,
	if (!scrollTimeout)
	{

		// set element to div.games
		if (typeof(element) == "string")
			element = document.getElementById(element);
		else if (!element.getAttribute("id"))
			element = element.parentNode.parentNode;
		var games = element.getElementsByTagName("div").item(2);

		// The new scrollLeft value
		var newScroll = games.scrollLeft + (direction * 350);

		// Thou shalt not scrollith further!
		// Lest thou needith scrolling or thou doesth not scrollith.
		if ((games.scrollWidth) && ((newScroll <= games.scrollWidth - 350) || (!direction)))
		{
			if (newScroll < 0)
				newScroll = 0;

			// Update the left/right arrow fades
			var scrolls = element.getElementsByTagName("img");
			var left = scrolls.item(0),
				right = scrolls.item(1);

			// If we're not as far left as possible, enable left arrow.
			left.setAttribute("src", ((newScroll) ? left.getAttribute("src").replace(/left\-fade\./, "left.") : left.getAttribute("src").replace(/left\./, "left-fade.")));
			left.style.cursor = ((newScroll) ? "pointer" : "default");

			// If we're not as far right as possible, enable right arrow.
			// games list needs to have already loaded
			var rightSrc = right.getAttribute("src");
			if (newScroll > games.scrollWidth - 700)
			{
				right.setAttribute("src", rightSrc.replace(/right\./, "right-fade."));
				right.style.cursor = "default";
			}
			else
			{
				right.setAttribute("src", rightSrc.replace(/right\-fade\./, "right."));
				right.style.cursor = "pointer";
			}

			// For every pixel between current scrollLeft and new scrollLeft,
			var id = element.getAttribute("id");
			if (direction)
			{
				for (var s = 1; s <= Math.abs(newScroll - games.scrollLeft); s++)
					scrollTimeout = setTimeout("document.getElementById(\"" + id + "\").getElementsByTagName(\"div\").item(2).scrollLeft = " + (games.scrollLeft + s * direction) + ";", s);
				setTimeout("scrollTimeout = false;", s + 1);
			}

			// If we need to load more games, and the default list isn't less than full
			if ((newScroll > games.scrollWidth - 700) && (games.scrollWidth > 700))
				setTimeout("loadGames(\"" + id + "\");", s + 2)
		}

		// Not loaded, try again.
		else if (!games.scrollWidth)
			setTimeout("scrollGames(\"" + element.getAttribute("id") + "\", " + direction + ");", 20);
	}
}