//SlideShow.js
// Applied Knowledge, Inc
// Author:  Phil Jesch - Dec 12, 2005
// Revised: Jim Hart - Jan 12, 2006

//Debugging flags
var debugMode = false;
var showMode = false;

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000;
// Duration of crossfade (seconds)
var crossFadeDuration = 3;
// Specify the image files
var Pic = new Array();

// do not edit anything below this line
var t;
var j = 0;
var p = Pic.length;
var preLoad = new Array();
for (i = 0; i < p; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}
//-----------------------------------------			
// Call ShowPictures() as the last line in your webpage body;
// this guarantees that the PictureTable has been rendered if it exists.
function ShowPictures() {
	if(document.all.PictureTable) {
		Pic = LoadPicArray();
		p = Pic.length;
		for (i = 0; i < p; i++) {
			preLoad[i] = new Image();
			preLoad[i].src = Pic[i];
			}
		runSlideShow(); }
	}
//-----------------------------------------		
function runSlideShow() {
	if (p > 0) {
	if (document.all) {
		document.images.SlideShow.style.filter="blendTrans(duration=2)";
		document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
		document.images.SlideShow.filters.blendTrans.Apply();
	}
	document.images.SlideShow.src = preLoad[j].src;
	if (document.all) {
		document.images.SlideShow.filters.blendTrans.Play();
	}
	j = j + 1;
	if (j > (p - 1)) j = 0;
	t = setTimeout('runSlideShow()', slideShowSpeed);
	} }
//-----------------------------------------		
function LoadPicArray(){
	var pics = new Array();
	var idx = 0;
	var idx2 = 0;
	
	if(document.images.SlideShow){
		pics[0] = document.images.SlideShow.src;
	}
// This code below works too.------------
//	var target;		
//	target = contentimages.children[0];	//findObject(SlideShow);		 
//	if(target != null){
//		if(target.tagName == "IMG"){
//			pics[0] = target.src;
//		}
//		else{
//			alert("'SlideShow' is not an image!");
//		}
//	}
//	else{
//		alert("Cannot find object 'SlideShow'!");
//	}
//-----------------------------------------
	var imgs = findChildren(PictureTable, "tagName", "IMG");
	for (var i = 0; i < imgs.length; i++) {
		pics[pics.length] = imgs[i].src;
	}

	if(showMode){
		for(var i = 0; i < pics.length; i++){
			alert("Got img"+ i+ ": "+ pics[i]);
		}
	}
	return pics;
}

/******************************************************************************/
/******************************************************************************/
// Support functions:

function findChildren(el, type, value) {
    var children = el.children;
	var tmp = new Array();
	if (!children) return tmp;
	var j=0;

	for (var i=0; i<children.length; i++) {
		if (eval("children[i]." + type + "==\"" + value + "\"")) {
			if (children[i].title!="") {
				tmp[tmp.length] = children[i];
			}
		}
		tmp = tmp.concat(findChildren(children[i], type, value));
	}
	return tmp;
}

