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

   Creates a loop of fading images.
   Only used on the main library webpage.

   This script may be freely used, modified, or redistributed 
   as long as the above copyright and this statement are preserved.

   TODO: Need to randomize the image so that there are no repeats.
         Need to add several images.
*/

var img_id = 'fadeImg';
var stopwatch = 0;

scrapBook = new Array( '/images/red_flowers.png', 
			'/images/aubcat.png', 
			'/images/sunspot_building.png',
			'/images/elevator_shaft.png',
			'/images/terminal_kids.png',
			'/images/bookshelf.png',
			'/images/wallflower_hanging.png',
			'/images/walkway.png' );
	

function setOpacity(level, id) 
{
	var img = document.getElementById(id);
		img.style.MozOpacity = ( level / 100 );
		img.style.KhtmlOpacity = ( level / 100 );
		img.style.filter = "alpha(opacity=" + level + ")"; 
		img.style.opacity = ( level / 100 );
}

function changePic(src) 
{
	document.fadeImg.src = src
}

function fadeIn() 
{
	for( l=0; l<=99; l++ ) {
		setTimeout( "setOpacity(" + l + ",'" + img_id + "')",( stopwatch * 30 ) );
		stopwatch++;
	}
}

function fadeOut()
{
	for( l=99; l>=0; l-- ) {
		setTimeout( "setOpacity(" + l + ",'" + img_id + "')",( stopwatch * 30 ) );
   		stopwatch++;
	}
}

function randomImg() {
	n = Math.floor( Math.random() * scrapBook.length );
	changePic(scrapBook[n]);
}

function crossFade() {
	fadeOut();
	setTimeout( "randomImg()", ( stopwatch * 30 ) );
	fadeIn();
}

