// Library to animate a series of frames
// by Tom Farrell

// Before calling this library from a page, first call Tom's layercontrol.js 
// library as its functions are required for proper functionality.

// global variables for frame animation
var afLayers = new Array(); // contains the abstract references to the layers for the animation
var afInterval = null; // the interval handle for the animation
var afDoNext = null;

function animateFrames(prefix,suffix,maxFrames,delay) {
	afLayers = returnAllLayers(prefix,suffix,maxFrames);
	afInterval = setInterval("animateOneFrame()",delay);
	} //end function

function sequenceAnimateFrames(prefix,suffix,maxFrames,delay,doNext) {
	afDoNext = doNext;
	animateFrames(prefix,suffix,maxFrames,delay);
	} //end function

function animateOneFrame() {
	if (afLayers.length>0) {
		oneLayerSelect(afLayers,0);
		} //end if
	afLayers = afLayers.slice(1);
	if (afLayers.length==0) {
		clearInterval(afInterval);
		afInterval = null;
		} //end if
	if ((afInterval==null) && (afDoNext!=null)) {
		setTimeout(afDoNext,1);
		afDoNext = null;
		} //end if
	} //end function
