/*
** 7/28/05: Initial version
**          finished scrolling and looping backwards.
*/

var scrollspeed = 33             <!-- Lower is faster -->
var scrollstep=1

var contentwidth = 0;
var topimage = 0;
var position = 0;
var scrolltimer = 0;
var images = Array(new Image(), new Image());
var contentobj = getElement("content");
var image1     = getElement("image");
var image2     = getElement("nimage");

function getElement(name) {
    return(document.getElementById ? 
            document.getElementById(name) : document.all[name]);
}


function nextImage() {
    // Load the next image, and start pre-loading the one after it.
	if (scrollstep < 0) {	// If we're going backwards, skip back two images
		topimage = topimage -2;
		if (topimage < 0) topimage += imageInfo.length;
	}
		
	images[0].onload = getContentWidth;
	images[0].src = imageInfo[topimage].filename;
	images[1].src = imageInfo[(topimage+1) % imageInfo.length ].filename;

	image1.src = images[0].src
	image2.src = images[1].src;

	topimage = (topimage + 1) % imageInfo.length;

	if (scrollstep < 0) {	// if we're going backwards, start at the end
		position = -images[0].width+1
	} else {
		position = 0;
	}
	contentobj.style.left = position + "px";

	if (window.opera) {          // opera won't call the onload function
		getContentWidth();
	}
}


// When our main image is through loading, 
// get the image size, and start scrolling it.
function getContentWidth() {
    if (images[0].width == 0) {				// Not ready yet.  Come back
        setTimeout("getContentWidth()",1000)
    } else {
        contentwidth=images[0].width;
        scrolltimer = setTimeout("scrollit()", scrollspeed);
    }
}

function scrollit() {
	if (position > 0) { // Do nothing because we'll fall off the left end
        nextImage();
	} else if (position-scrollstep < -contentwidth) { // hit the right end
        nextImage();
    } else {
		position -= scrollstep;
        contentobj.style.left = position + "px";
        scrolltimer = setTimeout("scrollit()", scrollspeed);
    }
}
window.onload=nextImage;
