/*
   scaScroll.js
   Copyright (C) Deryck Hodge 2005 <hodgedg@auburn.edu>

   released under the GNU GPL v.2 or later
*/

var img;
var id = 'sca_info';
var imgX = 500;
var n = 0;
var stopwatch = 0;
var i, w, l;
var sId;
var h = 255;

var notes = new Array( 
	 'The Andrew Jones Family, Autauga County, Alabama, 1925.',
	 'Grinding Sugar Cane, Marshall County, Alabama, 1925.', 
	 'Mrs. Smith’s White Leghorns, Mobile County, Alabama, 1925.', 
	 'A Boy and His Hogs, Limestone County, Alabama, 1926.', 
	 'Mrs. Cheeseman’s New Pump, Mobile County, Alabama, 1926.', 
	 'Marketing Turkeys, Dallas County, Alabama, 1927.', 
	 'The Cream Truck, Marion County, Alabama, 1927.', 
	 'Marketing Flowers, Tuscaloosa County, Alabama, 1928.' 
);

function changeText(id, text) 
{
	document.getElementById(id).innerHTML = text;
}

function fadeOutText()
{
	if (h > 50) {
		h -= 5
		document.getElementById('sca_footer').style.color = 'rgb(' + h + ', ' + h + ', ' + h + ')';
		setTimeout('fadeOutText()', 0);
	} else {
		document.getElementById('sca_info').style.visibility = 'hidden';
		changeText('sca_info', notes[n])
	}

}

function fadeInText()
{
	document.getElementById('sca_info').style.visibility = 'visible';
	if (h < 255) {
		h += 5
		document.getElementById('sca_footer').style.color = 'rgb(' + h + ', ' + h + ', ' + h + ')';
		setTimeout('fadeInText()', 20);
	}
}

function initScroll()
{
	// Set initial values
	i = 1;

	img = document.getElementById('sca0');
	w = img.width;

	// Start the scrolling
	scrollImg();
}

function delayScroll()
{
	sId = setTimeout('scrollImg();', 25);
}

function scrollImg()
{
	sId = setTimeout('scrollImg();', 25);

	if (i < (w - imgX))  {
		img.style.left = '-' + i + 'px';
		i++

		if ( i == 495 ||
			i == 995 ||
			i == 1495 ||
			i == 1995 ||
			i == 2495 ||
			i == 2992 ||
			i == 3490 ) {	
				clearTimeout(sId);
				fadeOutText();
				fadeInText();
				n++;
				setTimeout('delayScroll();', 3000);
		} 
	}
}
