Animator = {
      animations : new Array(),
      interval : null,
      intervalTime : 40,
      add : function(el, attr, options) {
	    this.animations.push({el:el, 
									  attr:attr,
									  from: (options.from!=undefined) ? options.from : 0, 
									  to:(options.to!=undefined) ? options.to : 0,
									  duration:(options.duration!=undefined) ? options.duration : 0,
									  prefix:(options.prefix!=undefined) ? options.prefix : "", 
									  postfix:(options.postfix!=undefined) ? options.postfix : "",
									  wait:(options.wait!=undefined) ? options.wait : 0,
									  time:0,
									  startCallback: (options.startCallback!=undefined) ? options.startCallback : null,
									  finishCallback: (options.finishCallback!=undefined) ? options.finishCallback : null,
									  frameCallback: (options.frameCallback!=undefined) ? options.frameCallback : null});
	    if(this.interval==null) this.interval = window.setInterval(function() {Animator.calulateAnimations();},this.intervalTime);
      },

      calulateAnimations : function() {
			  for(key in this.animations) {
				if(isNaN(parseInt(key))) continue;
						this.animations[key].time+=this.intervalTime;
						if(this.animations[key].wait>0) {
						  if(this.animations[key].time>this.animations[key].wait) {
								this.animations[key].time=this.intervalTime;
								this.animations[key].wait=0;
								if (typeof this.animations[key].startCallback == "function") this.animations[key].startCallback();
						  } else continue;
						}
						
						var val=this.easeInOutCubic(this.animations[key].time,
									    this.animations[key].from,
									    this.animations[key].to-this.animations[key].from, 
									    this.animations[key].duration);
						if(this.animations[key].el != null) 
							this.animations[key].el[this.animations[key].attr]=this.animations[key].prefix+val.toString()+this.animations[key].postfix;
						if (typeof this.animations[key].frameCallback == "function") this.animations[key].frameCallback(val);
						if(this.animations[key].time>=this.animations[key].duration) {
							if(this.animations[key].el != null) 
						    	this.animations[key].el[this.animations[key].attr]=this.animations[key].prefix + this.animations[key].to+this.animations[key].postfix;
						    if (typeof this.animations[key].finishCallback == "function") this.animations[key].finishCallback(this.animations[key].el);
						    this.animations.splice(key, 1);
						    if(this.animations.length==0) {
									window.clearInterval(this.interval);
									this.interval=null;
						    }
						}
			  }
      },

			
      easeInOutSine : function(t,b,c,d) {
		  return (c/2*(1-Math.cos(Math.PI*t/d)))+b;
      },

      easeInOutCubic : function(t,b,c,d) {
	  if((t/=d/2)<1)
	    return (c/2 * Math.pow(t,3))+b;
	    return (c/2*(Math.pow(t-2,3)+2))+b;
      },

      easeInOutQuadric : function(t,b,c,d) {
	  if((t/=d/2)<1)
	    return (c/2 * Math.pow(t,2))+b;
	    return ((c-(c/2*(Math.pow(t-2,2)+2)))+c)+b;
      }


};
