// JavaScript Document
var accel = 0;

function setSampleImage(in_source, in_alt)
{
	//see page 446 JsDHTML Cookbook
	/* Find the container on the page. */
	var sample = document.getElementById("sample");
	/* Create an image tag to display the image. */
	var image = document.createElement("img");
	image.setAttribute("src", in_source);
	image.setAttribute("alt", in_alt);
	/* Replace the old contents (previous containers or whitespace) with the new container. */
	/* FIXME: This needs to know the height/width of the image so that we can appropriately size everything.  We probably will want another container to ensure that the swap is automic. */
	sample.replaceChild(image, sample.firstChild);
}

function scrollDown()
{
	stopScrolling();
	var thumbs = document.getElementById("thumbs_wrapper");
	var thumbs_scrolled = document.getElementById("thumbs_scrolled");
	if (thumbs && thumbs_scrolled) {
		var bottom = thumbs.clientHeight - thumbs_scrolled.scrollHeight;
		thumbs_scrolled.scrolling = setInterval(function() {
														/* Get the current top of the thumbnails */
														var top = parseInt(thumbs_scrolled.style.top) || 0;
														if (top > bottom) {
															/* More to scroll */
															top -= 6 + Math.min(32 - 6, accel++);
															if (top < bottom) {
																/* Went to far */
																top = bottom;
																stopScrolling();
															}
															thumbs_scrolled.style.top = top + 'px';
														}
														}, 50);
	}
	return false;
}

function scrollUp()
{
	stopScrolling();
	var thumbs_scrolled = document.getElementById("thumbs_scrolled");
	if (thumbs_scrolled) {
		thumbs_scrolled.scrolling = setInterval(function() {
														/* Get the current top of the thumbnails */
														var top = parseInt(thumbs_scrolled.style.top) || 0;
														if (top < 0) {
															/* More to scroll */
															top += 6 + Math.min(32 - 6, accel++);
															if (top > 0) {
																/* Went to far */
																top = 0;
																stopScrolling();
															}
															thumbs_scrolled.style.top = top + 'px';
														}
														}, 50);
	}
	return false;
}

function stopScrolling()
{
	var thumbs_scrolled = document.getElementById("thumbs_scrolled");
	if (thumbs_scrolled && thumbs_scrolled.scrolling) {
		clearTimeout(thumbs_scrolled.scrolling);
		thumbs_scrolled.scrolling = null;
	}
	accel = 0;
	return false;
}
