var t = 10 * 1000;	//  "t" for Time: Number of seconds * 1000 for the amount of milliseconds before the next image appears
var s = 1 * 10;	// "s" for Speed: Number of seconds * 10 for duration of fade effect
var arr = new Array();

function showImage() {	// Create image and begin timer for fade effect
	if (preBuffer.length != p) {	//display "Loading..." until imageBuffer is full
		document.write('<center><h3>Loading...</h3></center>');
		setTimeout('showImage()',1);
		return false;
	}
	var whichImage = Math.round(Math.random()*(p-1));
    document.write('<img src="'+theImages[whichImage]+'" id="splash" style="filters:alpha(opacity=0)">');
	setTimeout('changeImage()',t);
	fadeImage();
}

function changeImage() {
    //set the current image as background
    document.getElementById("splash").style.background = "url(" + document.getElementById("splash").src + ") no-repeat; ";
    
    //make image transparent
    changeOpac(0);
    
    //make new image
	var whichImage = Math.round(Math.random()*(p-1));
	
	//verify image has not yet been used in current cycle
	while (arr[whichImage] != null || document.getElementById("splash").src == preBuffer[whichImage].src) {
		whichImage = Math.round(Math.random()*(p-1));
	}
	arr[whichImage] = whichImage;
	if (arr.length == p) {
		var j=0;
		while (j <= arr.length) {
			if (arr[j] == null) break;
			else j++;
		}
		//if all images have been used, reset cycle
		if (j == p) arr = new Array();
	}

	//display new image
    document.getElementById("splash").src = preBuffer[whichImage].src;

    //fade in image
	setTimeout('changeImage()',t)
	fadeImage();
}

var i = 0;	// Opacity counter - DO NOT CHANGE
function fadeImage() {
	if (i <= 100) {
		changeOpac(i)
		setTimeout('fadeImage()',s)
		i++;
	} else {
		i=0;
	}
}

function changeOpac(opacity) {
    var object = document.getElementById("splash").style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}