
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 3500;
// Duration of crossfade (seconds)
var crossFadeDuration = 2;
// Index of current image
var currIndex = 0;
// Index of previous image
var prevIndex = 0;

runSlideShow();

function runSlideShow() {
	// numPhotos holds the number of images loaded from Raptor (all images in the 'raptor' div besides underImage and overImage)
	var numPhotos = document.getElementById('raptor').getElementsByTagName('img').length - 2;
	//alert(numPhotos);

	// path holds the source of an image loaded from Raptor, ex. the first image from Raptor will be titled image_0
	try{
		var path = document.getElementById('image_' + currIndex).src; 
	}
	catch(ex){
		
	}
	
	blendimage('underImage','overImage', path, 1000);
	
	// only call next iteration of slideshow if more than one photo is available
	if(numPhotos > 1){
	
		prevIndex = currIndex;
		
		currIndex = Math.floor(Math.random() * (numPhotos - 1) );
		
		//ensure that the same picture isn't displayed twice in a row
		while(currIndex == prevIndex){
			currIndex = Math.floor(Math.random() * (numPhotos - 1) );
		}
		
		var t = setTimeout('runSlideShow()', slideShowSpeed);
	}
}

function blendimage(underImg, overImg, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //set the current image as background
	document.getElementById(underImg).src = document.getElementById(overImg).src;
	
    //make foreground image transparent
    changeOpac(0, overImg);
	
    //make new image
    document.getElementById(overImg).src = imagefile;
	//document.getElementById("overImageLink").href = imagefile;

    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + overImg + "')",(timer * speed));
        timer++;
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
