$D.tween = function(pt) {
	for (var k in pt) this[k] = pt[k];
	this.timer.interval = this.precision;
	var out = this;
	this.timer.ontime = function(){out._ontime();};
};
$D.tween.prototype = {
	'timer': new $D.timer(),
	'type': 'linear',
	'precision': 25,
	'init': 0,
	'end': 100,
	'time': 1,
	'delay': 0,
	'_ontime': function(){
		this.timeNow += this.precision;
		if (this.timeNow >= (this.time*1000+this.delay*1000)) this.timer.stop();
		if (this.timeNow >= this.delay*1000) this.ontime($D.findTweenValue(this.init, this.end, this.delay*1000, this.timeNow, (this.time*1000+this.delay*1000), this.type));
		if (this.timeNow >= (this.time*1000+this.delay*1000)) this.callback();
	},
	'play': function(){
		this.timeNow = 0;
		this.timer.play();
	},
	'ontime': function(a){},
	'callback': function(){}
};

$D.findTweenValue = function (_propStart, _propDest, _timeStart, _timeNow, _timeDest, _animType, _extra1, _extra2) {
	var t = _timeNow-_timeStart;
	var b = _propStart;
	var c = _propDest-_propStart;
	var d = _timeDest-_timeStart;
	var a = _extra1;
	var p = _extra2;
	var s = _extra1;
	switch (_animType.toLowerCase()) {
	case "linear" :
		return c*t/d+b;
	case "easeinquad" :
		return c*(t /= d)*t+b;
	case "easeoutquad" :
		return -c*(t /= d)*(t-2)+b;
	case "easeinoutquad" :
		if ((t /= d/2)<1) {
			return c/2*t*t+b;
		}
		return -c/2*((--t)*(t-2)-1)+b;
	case "easeoutinquad" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeOutQuad")*.5+b;
		}
		return findTweenValue(0, c, 0, t*2-d, d, "easeInQuad")*.5+c*.5+b;
	case "easeincubic" :
		return c*(t /= d)*t*t+b;
	case "easeoutcubic" :
		return c*((t=t/d-1)*t*t+1)+b;
	case "easeinoutcubic" :
		if ((t /= d/2)<1) {
			return c/2*t*t*t+b;
		}
		return c/2*((t -= 2)*t*t+2)+b;
	case "easeoutincubic" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeOutCubic")*.5+b;
		}
		return findTweenValue(0, c, 0, t*2-d, d, "easeInCubic")*.5+c*.5+b;
	case "easeinquart" :
		return c*(t /= d)*t*t*t+b;
	case "easeoutquart" :
		return -c*((t=t/d-1)*t*t*t-1)+b;
	case "easeinoutquart" :
		if ((t /= d/2)<1) {
			return c/2*t*t*t*t+b;
		}
		return -c/2*((t -= 2)*t*t*t-2)+b;
	case "easeoutinquart" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeOutQuart")*.5+b;
		}
		return findTweenValue(0, c, 0, t*2-d, d, "easeInQuart")*.5+c*.5+b;
	case "easeinquint" :
		return c*(t /= d)*t*t*t*t+b;
	case "easeoutquint" :
		return c*((t=t/d-1)*t*t*t*t+1)+b;
	case "easeinoutquint" :
		if ((t /= d/2)<1) {
			return c/2*t*t*t*t*t+b;
		}
		return c/2*((t -= 2)*t*t*t*t+2)+b;
	case "easeoutinquint" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeOutQuint")*.5+b;
		}
		return findTweenValue(0, c, 0, t*2-d, d, "easeInQuint")*.5+c*.5+b;
	case "easeinsine" :
		return -c*Math.cos(t/d*(Math.PI/2))+c+b;
	case "easeoutsine" :
		return c*Math.sin(t/d*(Math.PI/2))+b;
	case "easeinoutsine" :
		return -c/2*(Math.cos(Math.PI*t/d)-1)+b;
	case "easeoutinsine" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeOutSine")*.5+b;
		}
		return findTweenValue(0, c, 0, t*2-d, d, "easeInSine")*.5+c*.5+b;
	case "easeinexpo" :
		return (t == 0) ? b : c*Math.pow(2, 10*(t/d-1))+b;
	case "easeoutexpo" :
		return (t == d) ? b+c : c*(-Math.pow(2, -10*t/d)+1)+b;
	case "easeinoutexpo" :
		if (t == 0) {
			return b;
		}
		if (t == d) {
			return b+c;
		}
		if ((t /= d/2)<1) {
			return c/2*Math.pow(2, 10*(t-1))+b;
		}
		return c/2*(-Math.pow(2, -10*--t)+2)+b;
	case "easeoutinexpo" :
		if (t == 0) {
			return b;
		}
		if (t == d) {
			return b+c;
		}
		if ((t /= d/2)<1) {
			return c/2*(-Math.pow(2, -10*t/1)+1)+b;
		}
		return c/2*(Math.pow(2, 10*(t-2)/1)+1)+b;
	case "easeincirc" :
		return -c*(Math.sqrt(1-(t /= d)*t)-1)+b;
	case "easeoutcirc" :
		return c*Math.sqrt(1-(t=t/d-1)*t)+b;
	case "easeinoutcirc" :
		if ((t /= d/2)<1) {
			return -c/2*(Math.sqrt(1-t*t)-1)+b;
		}
		return c/2*(Math.sqrt(1-(t -= 2)*t)+1)+b;
	case "easeoutincirc" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeOutCirc")*.5+b;
		}
		return findTweenValue(0, c, 0, t*2-d, d, "easeInCirc")*.5+c*.5+b;
	case "easeinelastic" :
		if (t == 0) {
			return b;
		}
		if ((t /= d) == 1) {
			return b+c;
		}
		if (!p) {
			p = d*.3;
		}
		if (!a || a<Math.abs(c)) {
			a = c;
			var s = p/4;
		} else {
			var s = p/(2*Math.PI)*Math.asin(c/a);
		}
		return -(a*Math.pow(2, 10*(t -= 1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;
	case "easeoutelastic" :
		if (t == 0) {
			return b;
		}
		if ((t /= d) == 1) {
			return b+c;
		}
		if (!p) {
			p = d*.3;
		}
		if (!a || a<Math.abs(c)) {
			a = c;
			var s = p/4;
		} else {
			var s = p/(2*Math.PI)*Math.asin(c/a);
		}
		return (a*Math.pow(2, -10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b);
	case "easeinoutelastic" :
		if (t == 0) {
			return b;
		}
		if ((t /= d/2) == 2) {
			return b+c;
		}
		if (!p) {
			p = d*(.3*1.5);
		}
		if (!a || a<Math.abs(c)) {
			a = c;
			var s = p/4;
		} else {
			var s = p/(2*Math.PI)*Math.asin(c/a);
		}
		if (t<1) {
			return -.5*(a*Math.pow(2, 10*(t -= 1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;
		}
		return (a*Math.pow(2, -10*(t -= 1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b);
	case "easeoutinelastic" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeOutElastic")*.5+b;
		}
		return findTweenValue(0, c, 0, t*2-d, d, "easeInElastic")*.5+c*.5+b;
	case "easeinback" :
		if (s == undefined) {
			s = 1.70158;
		}
		return c*(t /= d)*t*((s+1)*t-s)+b;
	case "easeoutback" :
		if (s == undefined) {
			s = 1.70158;
		}
		return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b;
	case "easeinoutback" :
		if (s == undefined) {
			s = 1.70158;
		}
		if ((t /= d/2)<1) {
			return c/2*(t*t*(((s *= (1.525))+1)*t-s))+b;
		}
		return c/2*((t -= 2)*t*(((s *= (1.525))+1)*t+s)+2)+b;
	case "easeoutinback" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeOutBack")*.5+b;
		}
		return findTweenValue(0, c, 0, t*2-d, d, "easeInBack")*.5+c*.5+b;
	case "easeinbounce" :
		return c-findTweenValue(0, c, 0, d-t, d, "easeOutBounce")+b;
	case "easeoutbounce" :
		if ((t /= d)<(1/2.75)) {
			return c*(7.5625*t*t)+b;
		} else if (t<(2/2.75)) {
			return c*(7.5625*(t -= (1.5/2.75))*t+.75)+b;
		} else if (t<(2.5/2.75)) {
			return c*(7.5625*(t -= (2.25/2.75))*t+.9375)+b;
		} else {
			return c*(7.5625*(t -= (2.625/2.75))*t+.984375)+b;
		}
	case "easeinoutbounce" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeInBounce")*.5+b;
		}
		return findTweenValue(0, c, 0, t*2-d, d, "easeOutBounce")*.5+c*.5+b;
	case "easeoutinbounce" :
		if (t<d/2) {
			return findTweenValue(0, c, 0, t*2, d, "easeOutBounce")*.5+b;
		}		return findTweenValue(0, c, 0, t*2-d, d, "easeInBounce")*.5+c*.5+b;
	}
};