//requires jb_DHTMLLib.js; jb_sequence.js if sequencing
/* rewrote on 7/11/06 to use actual time instead of some arbitrary framerate. The earlier version made the speed of the animation dependent upon processor speed, but now the animation will take a consistent amount of time (though it'll be jerkier on slower computers)
*/


function jb_fader(id, obj, seqRef, startOp, endOp, totalTime) {
//	this.imageName = id; //this is required to work around Safari bug
	this.id = id;
	this.obj = getRawObject(obj);
	this.startOp = startOp;
	this.endOp = endOp;
	this.currentOp = startOp;
	this.totalTime = totalTime * 1000;
	this.fps = 15;
	this.gRef = "jb_fader_"+this.id;
	eval(this.gRef+"=this");
	this.seqRef = seqRef;//somehow the seq has to pass its ref to this object, in case of multiple sequences...
}

jb_fader.prototype.init = function() {
	var d = new Date();
	this.startTime = d.getTime();
	this.currentOp = this.startOp;
	this.animate();
}

jb_fader.prototype.animate = function() {
	setOpacity(this.obj, this.currentOp);
/*	if (isSafari) { //Safari needs refreshing, for some reason
		changeImages('thumb' + this.imageName, document['thumb' + this.imageName].src);
	}*/
	if ((this.startOp < this.endOp && this.currentOp >= this.endOp) || (this.startOp > this.endOp && this.currentOp <= this.endOp)) {
		setOpacity(this.obj, this.endOp);
		clearTimeout(this.timer);
		if (this.seqRef) {
			eval(this.seqRef + ".nextStep()");
		}
	} else {
		var dDelta = new Date();
		this.deltaTime = dDelta.getTime() - this.startTime;
		this.delta = (this.endOp - this.startOp) * (this.deltaTime / this.totalTime);
		this.currentOp += this.delta;
		this.timer = window.setTimeout(this.gRef + ".animate()", 1000/this.fps);
	}
}

jb_fader.prototype.setOp = function(op) {
	this.currentOp = op;
	setOpacity(this.obj, this.currentOp);
	if (this.seqRef) {
		eval(this.seqRef + ".nextStep()");
	}
}

jb_fader.prototype.stopAnimation = function() {
	clearTimeout(this.timer);
}