/*
	script by Warwick Adderley: warwick@pretzel.com.au
*/

var lgifanim = true;

isNav = !(!document.layers);
definedGifAnims = new Array();

function imgDomRef(theString) {
	var retObj = null;
	
	if (isNav)
		retObj = eval(theString);
	else {
		var lastDot = theString.lastIndexOf(".") + 1;
		var elementID = theString.substr(lastDot);
		
		retObj = eval("document.images." + elementID);
		}
	
	return retObj;
	}

function _swapImage(theSrc) {
	if (!this.isReset) {
		for (var i in this.targets) {
			theElement = eval(this.targets[i]);
			if (isNav)
				eval(this.targets[i]).src = theSrc;
			else {
				if (theElement.filters.length > 0) {
					if (typeof(theElement.filters[0]) == "object") {
						theElement.filters.blendTrans.Apply();
						theElement.src = theSrc;
						theElement.filters.blendTrans.Play()
						} else { theElement.src = theSrc; }	
					} else { theElement.src = theSrc; }			
				}				
			}
		}
	}

function gifPlay(theAnim) {
	if (window[theAnim]) {
		if (window[theAnim].play)
			window[theAnim].play();
		}
	}

function gifReset(theAnim) {
	if (window[theAnim]) {
		if (window[theAnim].reset)
			window[theAnim].reset();
		}
	}

function _doEndAction() {
	var delay = 1000 / this.fps;
	
	setTimeout(this.endAction, delay);
	}

function _play() {
	this.isReset = false;
	var delay = 1000 / this.fps;
	
	if (this.ready) {
		for (var i in this.frames) {
			if ((i == (this.frames.length - 1)) && this.endAction)
				setTimeout("definedGifAnims[" + this.id + "].swapImage('" + this.frames[i] + "'); definedGifAnims[" + this.id + "].doEndAction()", i * delay);
			else
				setTimeout("definedGifAnims[" + this.id + "].swapImage('" + this.frames[i] + "')", i * delay);
			}
		}
	}

function _reset() {
	this.swapImage(this.frames[0]);
	this.isReset = true;
	}

function imgAnim() {
	this.id = definedGifAnims.length;
	this.ready = false;
	this.isReset = false;
	this.endAction = false;
	
	this.frames = new String();
	this.fps = null;
	this.targets = new Array();
		
	this.frames = arguments[0];
	this.fps = arguments[1];
	
	for (var i = 2; i < arguments.length; i++) {
		this.targets[i - 2] = imgDomRef(arguments[i]);
		}
	
	this.play = _play;
	this.reset = _reset;
	this.swapImage = _swapImage;
	this.doEndAction = _doEndAction;
	
	definedGifAnims[this.id] = this;
	}