// Adapted from JavaScript Slide Show by Alanna Spence
// http://www.webmonkey.com/03/18/index3a.html

// Adapted from Onload Image Fades Without Flash by Richard Rutter
// http://clagnut.com/sandbox/imagefades/

var interval		=	6000;	// This is how long images are displayed for.  1 second = 1,000

// Rotate the photos
imageArray = new Array();
var imageNum		=	0;
for (i=1;i<=numImages;i++)
	{
	imageArray[imageNum++] = new imageItem(imageDir + i + ".jpg");
	}

var totalImages		=	imageArray.length;

function imageItem(image_location) {
	this.image_item = new Image();
	this.image_item.src = image_location;
	}

function get_ImageItemLocation(imageObj) {
	return(imageObj.image_item.src)
	}

function randNum(x, y) {
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
	}

function getNextImage() {
	if (random_display) 
		{
		imageNum = randNum(0, totalImages-1);
		}	else	{
		imageNum = (imageNum+1) % totalImages;
		}
	var new_image = get_ImageItemLocation(imageArray[imageNum]);
	return(new_image);
	}

// Fade out the initial photo and then call the image switching function,
// if JavaScript is disabled or nonexistent, the user will simply see the initial photo
function initializeRotatePhotos(place)
	{
	timerInitial = setTimeout("fadeOut(slideElementName,100)",4800);
	timerInitialSwitch = setTimeout("switchImage('"+place+"')",interval);
	}

function switchImage(place) 
	{
	timerFadeOut = setTimeout("fadeOut(slideElementName,100)",4800);
	var new_image = getNextImage();
	document[place].src = new_image;
	var recur_call = "switchImage('"+place+"')";
	timerID = setTimeout(recur_call, interval);
	initImage();
	}

// Fade the photos in and out
function initImage()
	{
	imageId = slideElementName;
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = 'visible';
	fadeIn(imageId,0);
	}

function setOpacity(obj, opacity) 
	{
	opacity = (opacity == 100)?99.999:opacity;
  
	// IE/Win
 	obj.style.filter = "alpha(opacity:"+opacity+")";
  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
  
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	}

function fadeIn(objId,opacity)
	{
	if (document.getElementById)
		{
		obj = document.getElementById(objId);
		if (opacity <= 100)
			{
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
			}
		}
	}

function fadeOut(objId,opacity)
	{
	if (document.getElementById)
		{
		obj = document.getElementById(objId);
		if (opacity >= 0)
			{
			setOpacity(obj, opacity);
			opacity -= 10;
			window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 100);
			}
		}
	}