// Tween Class
// David Kirkbride, 1st May 2008
function Tween(el, attr, tMin, tMax, inc, vel) {
	this.el = el;
	this.attr = attr;
	this.tMin = tMin;
	this.tCur = this.tMin;
	this.tMax = tMax;
	this.inc = inc;
	this.vel = vel;
	this.start();
}

Tween.prototype.start = function() {	
	this.updatePos();
	var t = this;
	this.tweenTimer = setInterval(function() { t.tween(); }, this.vel);
}

Tween.prototype.updatePos = function() {
	switch(this.attr) {
		case "x": this.el.style.left = this.tCur + "px"; break;
		case "y": this.el.style.top = this.tCur + "px"; break;
		case "a":
			this.el.style.opacity = this.tCur / 10;
			this.el.style.filter = 'alpha(opacity=' + this.tCur * 10 + ')';
		break;
	}
}

Tween.prototype._onTweenStopped = function() {
	clearInterval(this.tweenTimer);
	this.onTweenStopped();
}

Tween.prototype.tween = function() {
	if(this.tMin < this.tMax) {
		if(this.tCur < this.tMax) { this.tCur += this.inc; } else { this._onTweenStopped(); }
	} else {
		if(this.tCur > this.tMax) { this.tCur -= this.inc; } else { this._onTweenStopped(); }
	}
	this.updatePos();
}