/**
Quick port of Adobe Flash Tween class
Can be used with jQuery

@author Sergey Chikuyonok (gonarch@design.ru)
@version 1.1
*/

function Tween(E,K,D,M,A,F,J){this.time=0;this.duration=F;this.percent=0;if(E instanceof Array||(typeof (jQuery)!="undefined"&&E instanceof jQuery)){this._list=E}else{if(typeof (E)=="string"){this._list=[document.getElementById(E)]}else{this._list=[E]}}this._prop=null;if(K instanceof Array){this._prop=[];for(var I=0;I<K.length;I++){this._prop.push(this._toCamelCase(K[I]))}}else{if(K){this._prop=[this._toCamelCase(K)]}}this._ease=D;this._isColor=false;if(this._prop&&this._prop.join(",").toLowerCase().indexOf("color")!=-1){this._c1=new TweenColor(M);this._c2=new TweenColor(A);this._isColor=true;M=0;A=1}this.position=M;this._start=parseFloat(M);this.finish=parseFloat(A);this._change=this.finish-this._start;this._animate=false;this._units=(typeof (J)=="undefined")?"px":J;if(this._prop){for(var I=0,L=this._prop.length;I<L;I++){var B=this._prop[I];switch(B){case"opacity":if(Tween.browser.msie){for(var G=0,H=this._list.length;G<H;G++){var C=this._list[G];C.style.zoom=1;C.style.filter=C.style.filter.replace(/alpha\([^\)]*\)/gi,"")+"alpha(opacity="+M*100+")"}}break}}}this.play()}Tween._stack=[];Tween._idPoll=null;Tween._poll=function(){var A=Tween._stack.length;for(var B=0;B<A;B++){if(Tween._stack[B]){Tween._stack[B]._onMotion()}}};Tween._add=function(A){Tween._stack[Tween._stack.length]=A};Tween._remove=function(C){var A=Tween._stack.length;for(var B=0;B<A;B++){if(Tween._stack[B]==C){Tween._stack.splice(B,1);break}}};new function(){var A=navigator.userAgent.toLowerCase();Tween.browser={safari:/webkit/.test(A),opera:/opera/.test(A),msie:/msie/.test(A)&&!/opera/.test(A),mozilla:/mozilla/.test(A)&&!/(compatible|webkit)/.test(A)};Tween.boxModel=!Tween.browser.msie||document.compatMode=="CSS1Compat"};Tween._startPoll=function(){Tween._idPoll=setInterval(Tween._poll,23)};Tween._stopPoll=function(){clearInterval(Tween._idPoll);Tween._idPoll=null};Tween._inStack=function(C){var A=this._stack.length;for(var B=0;B<A;B++){if(this._stack[B]==C){return true}}return false};Tween.prototype={_onMotion:function(){if(this._animate){if(this.time<this.duration){this.time++;this.position=this._ease(this.time,this._start,this._change,this.duration);var G=this.position,I=this._units,A=this._prop;this.percent=Math.abs((G-this._start)/this._change);if(this._isColor){this.position=G=this._c1.mix(this._c2,G).toString();I=""}for(var F=0,H=this._list.length;F<H;F++){var C=this._list[F],J=C.style;this.target=C;if(A){for(var D=0,E=A.length;D<E;D++){var B=A[D];switch(B){case"opacity":if(Tween.browser.msie){J.filter=J.filter.replace(/alpha\([^\)]*\)/gi,"")+"alpha(opacity="+G*100+")"}else{if(Tween.browser.mozilla&&G==1){G=0.9999}J[B]=G}break;default:J[B]=G+I}}}this.onMotionChanged(C)}this.onMotionChangeComplete()}else{this.percent=1;for(var F=0,H=this._list.length;F<H;F++){var C=this._list[F];this.target=C;this.onMotionFinished(C)}this.onMotionFinishComplete();this.stop()}}},_toCamelCase:function(A){return A.replace(/\-(\w)/ig,function(C,B){return B.toUpperCase()})},onMotionChanged:function(A){return },onMotionChangeComplete:function(A){return },onMotionFinished:function(A){return },onMotionFinishComplete:function(){return },play:function(){if(!this._animate){this._animate=true;this.time=0;if(!Tween._inStack(this)){Tween._add(this)}}if(!Tween._idPoll){Tween._startPoll()}},stop:function(){this._animate=false;Tween._remove(this);if(!Tween.length){Tween._stopPoll()}},resume:function(){this._animate=true;if(!Tween._inStack(this)){Tween._add(this)}}};function TweenColor(){this.set.apply(this,arguments)}TweenColor.mix=function(C,A,B){return(new TweenColor(C)).mix(new TweenColor(A),B)};TweenColor.prototype={set:function(){if(arguments.length==1&&typeof (arguments[0])=="string"){if(typeof (arguments[0])=="string"){var A=arguments[0].replace("#","");this.r=parseInt(A.substr(0,2),16);this.g=parseInt(A.substr(2,2),16);this.b=parseInt(A.substr(4,2),16)}else{if(arguments[0] instanceof TweenColor){var A=arguments[0];this.r=A.r;this.g=A.g;this.b=A.b}}}else{if(arguments.length==3){this.r=parseInt(arguments[0]);this.g=parseInt(arguments[1]);this.b=parseInt(arguments[2])}}this.value=(this.r<<16|this.g<<8|this.b)},get:function(){return this.value},mix:function(B,A){A=A||0;return new TweenColor(this.r+(B.r-this.r)*A,this.g+(B.g-this.g)*A,this.b+(B.b-this.b)*A)},toHex:function(){return this.value.toString(16)},toString:function(){var B=this.toHex();for(var C=B.length,A=6;C<A;C++){B=0+B}return"#"+B}};var EEQ={};EEQ.linear=function(B,A,D,C){return D*B/C+A};EEQ.Quadratic={easeIn:function(B,A,D,C){return D*(B/=C)*B+A},easeOut:function(B,A,D,C){return -D*(B/=C)*(B-2)+A},easeInOut:function(B,A,D,C){if((B/=C/2)<1){return D/2*B*B+A}return -D/2*((--B)*(B-2)-1)+A}};EEQ.Cubic={easeIn:function(B,A,D,C){return D*(B/=C)*B*B+A},easeOut:function(B,A,D,C){return D*((B=B/C-1)*B*B+1)+A},easeInOut:function(B,A,D,C){if((B/=C/2)<1){return D/2*B*B*B+A}return D/2*((B-=2)*B*B+2)+A}};EEQ.Quartic={easeIn:function(B,A,D,C){return D*(B/=C)*B*B*B+A},easeOut:function(B,A,D,C){return -D*((B=B/C-1)*B*B*B-1)+A},easeInOut:function(B,A,D,C){if((B/=C/2)<1){return D/2*B*B*B*B+A}return -D/2*((B-=2)*B*B*B-2)+A}};EEQ.Quintic={easeIn:function(B,A,D,C){return D*(B/=C)*B*B*B*B+A},easeOut:function(B,A,D,C){return D*((B=B/C-1)*B*B*B*B+1)+A},easeInOut:function(B,A,D,C){if((B/=C/2)<1){return D/2*B*B*B*B*B+A}return D/2*((B-=2)*B*B*B*B+2)+A}};EEQ.Sine={easeIn:function(B,A,D,C){return -D*Math.cos(B/C*(Math.PI/2))+D+A},easeOut:function(B,A,D,C){return D*Math.sin(B/C*(Math.PI/2))+A},easeInOut:function(B,A,D,C){return -D/2*(Math.cos(Math.PI*B/C)-1)+A}};EEQ.Exponential={easeIn:function(B,A,D,C){return(B==0)?A:D*Math.pow(2,10*(B/C-1))+A},easeOut:function(B,A,D,C){return(B==C)?A+D:D*(-Math.pow(2,-10*B/C)+1)+A},easeInOut:function(B,A,D,C){if(B==0){return A}if(B==C){return A+D}if((B/=C/2)<1){return D/2*Math.pow(2,10*(B-1))+A}return D/2*(-Math.pow(2,-10*--B)+2)+A}};EEQ.Circular={easeIn:function(B,A,D,C){return -D*(Math.sqrt(1-(B/=C)*B)-1)+A},easeOut:function(B,A,D,C){return D*Math.sqrt(1-(B=B/C-1)*B)+A},easeInOut:function(B,A,D,C){if((B/=C/2)<1){return -D/2*(Math.sqrt(1-B*B)-1)+A}return D/2*(Math.sqrt(1-(B-=2)*B)+1)+A}};EEQ.Elastic={easeIn:function(C,A,G,F){var D=1.70158;var E=0;var B=G;if(C==0){return A}if((C/=F)==1){return A+G}if(!E){E=F*0.3}if(B<Math.abs(G)){B=G;var D=E/4}else{var D=E/(2*Math.PI)*Math.asin(G/B)}return -(B*Math.pow(2,10*(C-=1))*Math.sin((C*F-D)*(2*Math.PI)/E))+A},easeOut:function(C,A,G,F,B,E){var D=1.70158;var E=0;var B=G;if(C==0){return A}if((C/=F)==1){return A+G}if(!E){E=F*0.3}if(B<Math.abs(G)){B=G;var D=E/4}else{var D=E/(2*Math.PI)*Math.asin(G/B)}return B*Math.pow(2,-10*C)*Math.sin((C*F-D)*(2*Math.PI)/E)+G+A},easeInOut:function(C,A,G,F,B,E){var D=1.70158;var E=0;var B=G;if(C==0){return A}if((C/=F/2)==2){return A+G}if(!E){E=F*(0.3*1.5)}if(B<Math.abs(G)){B=G;var D=E/4}else{var D=E/(2*Math.PI)*Math.asin(G/B)}if(C<1){return -0.5*(B*Math.pow(2,10*(C-=1))*Math.sin((C*F-D)*(2*Math.PI)/E))+A}return B*Math.pow(2,-10*(C-=1))*Math.sin((C*F-D)*(2*Math.PI)/E)*0.5+G+A}};EEQ.Back={easeIn:function(B,A,E,D,C){if(C==null){C=1.70158}return E*(B/=D)*B*((C+1)*B-C)+A},easeOut:function(B,A,E,D,C){if(C==null){C=1.70158}return E*((B=B/D-1)*B*((C+1)*B+C)+1)+A},easeInOut:function(B,A,E,D,C){if(C==null){C=1.70158}if((B/=D/2)<1){return E/2*(B*B*(((C*=(1.525))+1)*B-C))+A}return E/2*((B-=2)*B*(((C*=(1.525))+1)*B+C)+2)+A}};EEQ.Bounce={easeIn:function(B,A,D,C){return D-EEQ.Bounce.easeOut(C-B,0,D,C)+A},easeOut:function(B,A,D,C){if((B/=C)<(1/2.75)){return D*(7.5625*B*B)+A}else{if(B<(2/2.75)){return D*(7.5625*(B-=(1.5/2.75))*B+0.75)+A}else{if(B<(2.5/2.75)){return D*(7.5625*(B-=(2.25/2.75))*B+0.9375)+A}else{return D*(7.5625*(B-=(2.625/2.75))*B+0.984375)+A}}}},easeInOut:function(B,A,D,C){if(B<C/2){return EEQ.Bounce.easeIn(B*2,0,D,C)*0.5+A}return EEQ.Bounce.easeOut(B*2-C,0,D,C)*0.5+D*0.5+A}};if(window.jQuery){if(!jQuery.easing){jQuery.easing={}}jQuery.each(EEQ,function(A,B){if(B.constructor==Object){jQuery.each(B,function(D,C){if(C.constructor==Function){var E={};E[A+"."+D]=function(){return C.apply(C,[].slice.call(arguments,1))};jQuery.extend(jQuery.easing,E)}})}})};
