/*
  Animation.js 
  Copyright 2010, Kipp Software Corporation
*/
function Animation(action, duration) {
    this.action = action;
    this.millisPerFrame = 1000 / 20;
    this.whichFrame = 0;
    this.numFrames = duration / this.millisPerFrame;
    this.go();
}

Animation.prototype.go = function() {
    this.whichFrame++;
    this.action(this.whichFrame, this.numFrames);
    if (this.whichFrame <= this.numFrames) {
	var animation = this;
	setTimeout(function(){ animation.go(); }, this.millisPerFrame);
    }
}

function linear(start, end, whichStep, numSteps) {
    return (numSteps == 0) ? end : start + (whichStep * (end - start) / numSteps);
}

function easeIn(start, end, whichStep, numSteps) {
    var stepsLeft = numSteps - whichStep;
    return (numSteps == 0) ? end : start + (end - start) * (1 - stepsLeft * stepsLeft / numSteps / numSteps);
}

function easeOut(start, end, whichStep, numSteps) {
    return (numSteps == 0) ? end : start + (end - start) * whichStep * whichStep / numSteps / numSteps;
}

