
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 3000;

// Duration of crossfade (seconds)
var crossFadeDuration = 2;

// Specify the image files
var url; //initial URL

var j = 0;
var t;

var nWhichSlideshow = 1;	// NJK


// Set the Slideshow container to hold the n'th image in the slideshow.
function setSlideshowImage(nSlideshowID, n)
{
	if (!eval("document.images.Slideshow" + nSlideshowID))
	{
		return;	// Stop if no slideshow!
	}
	
	var sTarget;
	var sURL;
	eval("sTarget = SlideshowPicturesTargetArray" + nSlideshowID + "[n]");
	eval("sURL = SlideshowPicturesURLArray" + nSlideshowID + "[n]");


	// here will control the movement of the slideshow
	var oSlideshowDoc;
	if (document.all) 
	{
		oSlideshowDoc = document.getElementById("Slideshow" + nSlideshowID);

		oSlideshowDoc.style.filter = "blendTrans(duration=2)";
		oSlideshowDoc.style.filter = "blendTrans(duration=crossFadeDuration)";
		oSlideshowDoc.filters.blendTrans.Apply();
	}

	if (sTarget == 'popup')
	{		
		eval("document.images.Slideshow" + nSlideshowID + ".src = preLoad" + nSlideshowID + "[n].src");
		eval("document.getElementById('SlideshowAnchor" + nSlideshowID + "').href = \"javascript:windowOpen('" + sURL + "', 600, 500);\"");
		eval("document.getElementById('SlideshowAnchor" + nSlideshowID + "').target = '_self'");
	}
	else
	{
		eval("document.images.Slideshow" + nSlideshowID + ".src = preLoad" + nSlideshowID + "[n].src");
		eval("document.getElementById('SlideshowAnchor" + nSlideshowID + "').href = sURL");
		eval("document.getElementById('SlideshowAnchor" + nSlideshowID + "').target = SlideshowPicturesTargetArray" + nSlideshowID + "[n]");
	}

	if (document.all)
	{
		oSlideshowDoc.filters.blendTrans.Play();
	}
	
}


// Initialise and then run the slideshow loop.
function runSlideshow()
{
	// Preload!!!
	for (var x = 1; x <= nTotalNumOfSlideshow; x++)
	{
		var sID;
		sID = nSlideshow[x];
			// Get the corresponding Slideshow ID.

		if (sID && window["SlideshowPictures" + sID])
		{
			for (i = 0; i < eval("SlideshowPictures" + sID + ".length"); i++)
			{
				eval("preLoad" + sID + "[i] = new Image()");
				eval("preLoad" + sID + "[i].src = SlideshowPictures" + sID + "[i]");
			}
		}
	}

	if (nTotalNumOfSlideshow > 0)
	{
		runSlideshowLoop();
	}
}


// Go to next slideshow with no checks, just the wrap around from last to first (1).
function incrementSlideshow()
{
	nWhichSlideshow++;
	if (nWhichSlideshow > nTotalNumOfSlideshow)
	{
		nWhichSlideshow = 1;
	}
}


// Find next slideshow with images.
// If none found, return 0.
function nextSlideshow()
{
	var nNumIncrements = 0;
	while (nNumIncrements <= nTotalNumOfSlideshow)
	{
		incrementSlideshow();
		nNumIncrements = nNumIncrements + 1;
		var sID = nSlideshow[nWhichSlideshow];
		if (sID && window["SlideshowPictures" + sID])
		{
			var ss;
			eval ("ss = SlideshowPictures" + sID);
			if (ss)
			{
				return nWhichSlideshow;
			}
		}
	}
	return 0;
}


// Run the slideshow loop.
// Once this function is called, a setTimeout() will
// continue the calls to this function.
// NOTE: NO Preloading is done in this function!
function runSlideshowLoop() 
{
	var x = nextSlideshow();
	//alert(x);
	if (x)
	{
		var sID = nSlideshow[x];

		// Get the "cursor" for this slideshow.
		var nCursor;
		eval("nCursor = SlideshowCursor" + sID);

		// Set the image.
		setSlideshowImage (sID, nCursor);
		
		// Increment the cursor, and wrap if required.
		nCursor++;
		var l;
		eval("l = SlideshowPictures" + sID + ".length");
		if (nCursor >= l)
		{
			nCursor = 0;
		}

		// Remember the "cursor" for the slideshow...
		eval("SlideshowCursor" + sID + " = nCursor");

		// Thank you. Come again!
		t = setTimeout('runSlideshowLoop()', slideShowSpeed);
	}
}

