// Slide Show Script

// Slideshow Mode
// Add images using AddImage, then call RunSlideShow

// Gallery Mode
// Either, Add images use AddImage, then switch using FadeImage, 
// or add using AddImage2Reference, and switch using FadeImageReference


// Add Image to Slideshow
// AddImage2Reference - Allows 2 comments to be added to an image, and use a reference for the image
// AddImage2Reference - Allows 2 comments to be added to an image, and no reference. all access is by array index
// AddImage - Allows 1 comment to be added to an image and no reference. all access is by array index

// Fade Images
// FadeImageReference - Allows the image to be changed by using the image reference
// FadeImage - Allows the image to be changed using the array index

// RunSlideShow - Starts the slideshow running


// Variables
var slideShowSpeed = 5000;					// Picture Duration
var crossFadeDuration = 3;					// Fade Time
var IMGName = ["SlideShow1", "SlideShow2", "SlideShow3"];	// IMG ID's for Slide Show
var DescriptionName = ["SLTitle", "SLTitle2"];		// Description p ids for first slide show


// Globals
var j = new Array();		// Array of Index's of next image to show when using slideshow
var preLoad = new Array();		// Array of Images
var valid = new Array();		// Array showing which of the slideshows is valid
var IMGDescription = new Array();	// Array of Descriptions for first Slide Show
var IMGDescription2 = new Array();	// Array of second descriptions for first slide show
var ImgRef = new Array();		// Reference for Image if not using array index for first slideshow

// ImageName - path and filename for image
// Index - Which SlideShow to use
// Description - First Description to use
// Ref - Unique Reference for this image
// Description2 - Second Description to use
function AddImage2Reference(ImageName,Index,Ref,Description,Description2)
{
	ImgRef.push(Ref);
	IMGDescription2.push(Description2);
	AddImage(ImageName,Index,Description);
}

function AddImage2(ImageName,Index,Description,Description2)
{
	IMGDescription2.push(Description2);
	AddImage(ImageName,Index,Description);
}

function AddImage(ImageName,Index,Description)
{
	var newimage;

	Index--;
	if(preLoad[Index]==null)
	{
		valid[Index]=1;
		j[Index]=0;
		preLoad[Index] = new Array();
	}

	newimage=preLoad[Index].length;
	IMGDescription.push(Description);
	preLoad[Index][newimage]= new Image();
	preLoad[Index][newimage].src=ImageName;
}

function FadeImageReference(Index, Reference)
{
	UseImage=-1;

	for(i=0; i<ImgRef.length; i++)
	{
		if(ImgRef[i]==Reference)
			UseImage=i;
	}

	if(UseImage!=-1)
		FadeImage(Index,UseImage);
}

function FadeImage(Index, PicLoad)
{
	UseImage=PicLoad;

	if(PicLoad>(preLoad[Index].length-1))
		UseImage=PicLoad-(preLoad[Index].length-1);

	if (document.all) 
	{
		document.images[IMGName[Index]].style.filter="blendTrans(duration=2)";
		document.images[IMGName[Index]].style.filter="blendTrans(duration=crossFadeDuration)";
		document.images[IMGName[Index]].filters.blendTrans.Apply();

	}
	document.images[IMGName[Index]].src = preLoad[Index][UseImage].src;
	if (document.all) 
	{
		document.images[IMGName[Index]].filters.blendTrans.Play();
	}

	if(document.getElementById(DescriptionName[0])!=null)
	{
		document.getElementById(DescriptionName[0]).innerHTML = IMGDescription[UseImage];
	}
	if(document.getElementById(DescriptionName[1])!=null)
	{
		document.getElementById(DescriptionName[1]).innerHTML = IMGDescription2[UseImage];
	}
}

function runSlideShow() 
{
	var i;
	var t;

	for (i=0; i<3; i++)
	{
		if(valid[i]==1)
		{
			FadeImage(i, j[i]);

			j[i] = j[i] + 1;
			if (j[i] > (preLoad[i].length-1)) 
				j[i] = 0;
		}
	}

	t = setTimeout('runSlideShow()', slideShowSpeed);
}

