
function Animator(animType) {
  this.animType = animType || 'none';
};
Animator.prototype.delay = 5;

Animator.prototype.start = function(animFunc,startValue,endValue,animType,duration,onEnd) {
  if(!duration) duration = 1000;
  var startTime = (new Date()).getTime();
  var time;
  var interID;
  animType = this.easing[animType || this.animType];
  var step = function () {
    time = Math.round(((new Date()).getTime()-startTime));
    if(time>=duration) {
      clearInterval(interID);
      animFunc(endValue);
      if(onEnd)onEnd();
    }
    else {
      startValue = animType(time,startValue,endValue-startValue,duration);
      animFunc(startValue);
    }
  };
  this.interID = interID = setInterval(step,this.delay);
};

Animator.prototype.stop = function() {
  clearInterval(this.interID);
};

Animator.prototype.easing = {
  'cons':Math.PI/2,
  'none': function(time,start,delta,length) {
    return start+delta*(time/length);
  },
  'out': function(time,start,delta,length) {
    return start+delta*Math.sin((time/length)*Math.PI/2);
  }
};
