var TweenController = (function(){
	function constructor(obj,property,time,ease){
		this.obj = obj;
		this.property = property;
		this.ov = 0;
		this.fv = 1;
		this.intervalRate = 10;
		this.position = 0;
		this.steps = Math.round(time/this.intervalRate);
		this.d;
		this.playing;
		this.ease = ease;
		this.callback;
		this.obj[this.property] = this.position;
	}
	function easeSinColor(instance){//returns a number between instance.ov and instance.fv
		var f = instance.fv;
		var o = instance.ov;
		var t = Math.sin((instance.position/instance.steps)*Math.PI/2);
		var r =(((f&0xff0000)>>16)*t+(1-t)*((o&0xff0000)>>16));
		var g =(((f&0x00ff00)>>>8)*t+(1-t)*((o&0x00ff00)>>>8));
		var b = ((f&0x0000ff)*t+(1-t)*(o&0x0000ff));
		return (r<<16|g<<8|b).toString(16);
	}
	function easeCos(instance){//returns a number between instance.ov and instance.fv
		return (Math.cos((instance.position/instance.steps)*Math.PI/2-Math.PI/2)*(instance.fv-instance.ov)+instance.ov);
	}
	function easeSin(instance){//returns a number between instance.ov and instance.fv
		return (Math.sin((instance.position/instance.steps)*Math.PI/2)*(instance.fv-instance.ov)+instance.ov);
	}
	function startInterval(instance){
		instance.playing = setInterval(function(){instance.animate()}, instance.intervalRate);
	}
	constructor.prototype.play = function(callback){
		if(!this.playing){
			this.callback = callback;
			this.position = 0;
			this.d = 1;
			startInterval(this);
		}
	};
	constructor.prototype.stop = function(){
		clearInterval(this.playing);
		this.playing = false;
	};
	constructor.prototype.animate = function(d){
		this.position += this.d;
		this.obj[this.property] = (eval(this.ease))(this);
		(this.obj[this.callback])();
		if(this.position == this.steps){
			if(this.onTweenFinished){
				this.onTweenFinished();
			} else {
				this.stop();
			}
		}
	};

	return constructor;
})();