//array for performer pictures
var Pic = new Array();

//preload images in new array
var preLoad = new Array();

//array for performer names
var Names = new Array();

//number of images in array
var pLength;

//current image
var iCurrentImage;

//array for preloaded images
var preLoad;

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000;

// Duration of crossfade (seconds)
var crossFadeDuration = 2;

//new image
var iNewImag;

//array with last shown images
var arrShownImages = new Array();

//max number of allowed images in shown array
var iMaxImages = 3;

//set image path
strImagePath = "performers/";

function fnImages()
{
	// Specify the image files
	Pic[0] = strImagePath + 'LarryClinton.jpg';
	Pic[1] = strImagePath + 'BarryFrank.jpg';
	Pic[2] = strImagePath + 'TomJerry1.jpg';
	Pic[3] = strImagePath + 'BettyJohnson.jpg';
	Pic[4] = strImagePath + 'EdnaMcGriff.jpg';
	Pic[5] = strImagePath + 'BobCrosby.jpg';
	Pic[6] = strImagePath + 'CabCalloway.jpg';
	Pic[7] = strImagePath + 'DickPowell.jpg';
	Pic[8] = strImagePath + 'DorseyBrothers.jpg';
	Pic[9] = strImagePath + 'EnochLight.jpg';
	Pic[10] = strImagePath + 'HelenForrest.jpg';
	Pic[11] = strImagePath + 'RayEberle.jpg';
	Pic[12] = strImagePath + 'DaleRoy1.jpg';
	Pic[13] = strImagePath + 'SnookyLanson.jpg';
	Pic[14] = strImagePath + 'RandyHughes.jpg';
	Pic[15] = strImagePath + 'EllieRussell.jpg';

	//specify the performer names
	Names[0] = "Larry Clinton";
	Names[1] = "Barry Frank";
	Names[2] = "Tom & Jerry";
	Names[3] = "Betty Johnson";
	Names[4] = "Edna McGriff";
	Names[5] = "Bob Crosby";
	Names[6] = "Cab Calloway";
	Names[7] = "Dick Powell";
	Names[8] = "Dorsey Brothers";
	Names[9] = "Enoch Light";
	Names[10] = "Helen Forrest";
	Names[11] = "Ray Eberle";
	Names[12] = "R. Rogers, D. Evans";
	Names[13] = "Snooky Lanson";
	Names[14] = "Randy Hughes";
	Names[15] = "Ellie Russell";
	
	//get number of images in array	
	pLength = Pic.length;
	
	//reset current image value
	iCurrentImage = 0;
	
	for (i = 0; i < pLength; i++)
	{
		preLoad[i] = new Image();
		preLoad[i].src = "images/"+ Pic[i];
	}
	
	var strLink = "index.php?wp=performers";
	var strTitle = "Go to the performers page";
	
	//put info in div
	document.getElementById('performer-slideshow').innerHTML = "<a title='" + strTitle + "' href='" + strLink + "'><h2 class='margin-b-10'>BELL performers</h2><img class='padding-5 clear' name='SlideShow' id='slideshow' src='images/performers/BettyJohnson.jpg' width='123px' height='123px' /><h3 id='performer-name'></h3></a>";
	
	//start the slide show
	//var s = fnInitImage();
	var t = fnRunSlideShow();
	
}

function fnInitImage(what) 
{
	imageId = 'slideshow';
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	//image.style.visibility = "visible";
	
	if (what == "in")
	{
		fadeIn(imageId, 0);
	}
	else if (what == "out")
	{
		fadeOut(imageId, 100);
	}
	
	
}

function fadeIn(objId, opacity) 
{
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 50;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
}

function fadeOut(objId, opacity) 
{
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity >= 0) {
			setOpacity(obj, opacity);
			opacity -= 50;
			window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 50);
		}
		else
		{
			var vSlide = fnRunSlideShow();
		}
	}
}

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 fnRunSlideShow()
{
	//get random new image number
	iNewImage = Math.round(Math.random() * (pLength-1));
	
	//number of images in shown array
	var iShownImages = arrShownImages.length;
	
	//if new image number already in shown array then select another
	if (iNewImage == arrShownImages[0] || iNewImage == arrShownImages[1] || iNewImage == arrShownImages[2])
	{
		while (iNewImage == arrShownImages[0] || iNewImage == arrShownImages[1] || iNewImage == arrShownImages[2])
		{
			iNewImage = Math.round(Math.random() * (pLength-1));
		}
	}
		
	//set the current image to the new image value
	iCurrentImage = iNewImage;
	
	//put new image in shown array
	if (iShownImages < iMaxImages)
	{
		//add new image to beginning of array
		var iAddedImage = arrShownImages.unshift(iCurrentImage);
	}
	else
	{
		//remove last image from array
		var iRemovedImage = arrShownImages.pop();
		
		//add new image to beginning of array
		var iAddedImage = arrShownImages.unshift(iCurrentImage);
	}
	
	document.images.SlideShow.src = preLoad[iCurrentImage].src;
	document.getElementById("performer-name").innerHTML = Names[iCurrentImage];
	//var s = fnInitImage("in");
		
	//var vSlide = setTimeout('fnInitImage("out")', slideShowSpeed);
	
	var vSlide = setTimeout('fnRunSlideShow()', slideShowSpeed);
	
	
}
