// Note: make sure that the window.onload function doesn't
// get overrriden by any other scripts on this page.
function doScrollThumbnails(wrapper, thumbnailId)
{
	var oldOnload = window.onload;
	
	window.onload = function()
	{
		if (wrapper.scrollLeft == 0)
		{
			scrollThumbnails(wrapper, thumbnailId);
		}
		oldOnload();
	}
}

function scrollThumbnails(wrapper, thumbnailId)
{
	var thumbnails = wrapper.getElementsByTagName("a");

	var currentThumbnail = "null";
	
	for (var i=0; i < thumbnails.length; i++)
	{
		if (thumbnails[i].getAttribute("name") == "thumb" + thumbnailId)
		{
			currentThumbnail = thumbnails[i];
		}
		
	}
	
	// Scroll so that the thumbnail ends up in the middle:
	if (currentThumbnail)
	{
		wrapper.scrollLeft = Math.max(currentThumbnail.offsetLeft - (wrapper.offsetWidth - currentThumbnail.offsetWidth) / 2, 0);
	}
}

function getThumbnailIdFromUrl(url)
{
	url = "" + url; // cast to string, manipulate by hand
	var urlPath = url.split("#")[0].split("?")[0];
	var matches = urlPath.match("[0-9][0-9]*/([0-9][0-9]*)/?$");
	if (matches)
	{
		return matches[1];
	}
	else
	{
		return null;
	}
}