/*
 * Yuichi Tateno. <hotchpotch@N0!spam@gmail.com>
 * http://rails2u.com/
 * 
 * The MIT License
 * --------
 * Copyright (c) 2007 Yuichi Tateno.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
var JSTweener={looping:false,frameRate:60,objects:[],defaultOptions:{time:1,transition:"easeoutexpo",delay:0,prefix:{},suffix:{},onStart:undefined,onStartParams:undefined,onUpdate:undefined,onUpdateParams:undefined,onComplete:undefined,onCompleteParams:undefined},inited:false,easingFunctionsLowerCase:{},init:function(){this.inited=true;for(var a in JSTweener.easingFunctions){this.easingFunctionsLowerCase[a.toLowerCase()]=JSTweener.easingFunctions[a]}},toNumber:function(b,a,c){if(!c){c="px"}return b.toString().match(/[0-9]/)?Number(b.toString().replace(new RegExp(c+"$"),"").replace(new RegExp("^"+(a?a:"")),"")):0},addTween:function(d,b){var a=this;if(!this.inited){this.init()}var f={};f.target=d;f.targetPropeties={};for(var c in this.defaultOptions){if(typeof b[c]!="undefined"){f[c]=b[c];delete b[c]}else{f[c]=this.defaultOptions[c]}}if(typeof f.transition=="function"){f.easing=f.transition}else{f.easing=this.easingFunctionsLowerCase[f.transition.toLowerCase()]}for(var c in b){if(!f.prefix[c]){f.prefix[c]=""}if(!f.suffix[c]){f.suffix[c]=""}var e=this.toNumber(d[c],f.prefix[c],f.suffix[c]);f.targetPropeties[c]={b:e,c:b[c]-e}}setTimeout(function(){f.startTime=(new Date()-0);f.endTime=f.time*1000+f.startTime;if(typeof f.onStart=="function"){if(f.onStartParams){f.onStart.apply(f,f.onStartParams)}else{f.onStart()}}a.objects.push(f);if(!a.looping){a.looping=true;a.eventLoop.call(a)}},f.delay*1000)},eventLoop:function(){var a=(new Date()-0);for(var g=0;g<this.objects.length;g++){var b=this.objects[g];var m=a-b.startTime;var j=b.endTime-b.startTime;if(m>=j){for(var k in b.targetPropeties){var c=b.targetPropeties[k];try{b.target[k]=b.prefix[k]+(c.b+c.c)+b.suffix[k]}catch(h){}}this.objects.splice(g,1);if(typeof b.onUpdate=="function"){if(b.onUpdateParams){b.onUpdate.apply(b,b.onUpdateParams)}else{b.onUpdate()}}if(typeof b.onComplete=="function"){if(b.onCompleteParams){b.onComplete.apply(b,b.onCompleteParams)}else{b.onComplete()}}}else{for(var k in b.targetPropeties){var c=b.targetPropeties[k];var f=b.easing(m,c.b,c.c,j);try{b.target[k]=b.prefix[k]+f+b.suffix[k]}catch(h){}}if(typeof b.onUpdate=="function"){if(b.onUpdateParams){b.onUpdate.apply(b,b.onUpdateParams)}else{b.onUpdate()}}}}if(this.objects.length>0){var l=this;setTimeout(function(){l.eventLoop()},1000/l.frameRate)}else{this.looping=false}}};JSTweener.Utils={bezier2:function(a,d,c,b){return(1-a)*(1-a)*d+2*a*(1-a)*c+a*a*b},bezier3:function(a,e,d,c,b){return Math.pow(1-a,3)*e+3*a*Math.pow(1-a,2)*d+3*a*a*(1-a)*c+a*a*a*b},allSetStyleProperties:function(c){var b;if(document.defaultView&&document.defaultView.getComputedStyle){b=document.defaultView.getComputedStyle(c,null)}else{b=c.currentStyle}for(var a in b){if(!a.match(/^\d+$/)){try{c.style[a]=b[a]}catch(d){}}}}};JSTweener.easingFunctions={easeNone:function(e,a,g,f){return g*e/f+a},easeInQuad:function(e,a,g,f){return g*(e/=f)*e+a},easeOutQuad:function(e,a,g,f){return -g*(e/=f)*(e-2)+a},easeInOutQuad:function(e,a,g,f){if((e/=f/2)<1){return g/2*e*e+a}return -g/2*((--e)*(e-2)-1)+a},easeInCubic:function(e,a,g,f){return g*(e/=f)*e*e+a},easeOutCubic:function(e,a,g,f){return g*((e=e/f-1)*e*e+1)+a},easeInOutCubic:function(e,a,g,f){if((e/=f/2)<1){return g/2*e*e*e+a}return g/2*((e-=2)*e*e+2)+a},easeOutInCubic:function(e,a,g,f){if(e<f/2){return JSTweener.easingFunctions.easeOutCubic(e*2,a,g/2,f)}return JSTweener.easingFunctions.easeInCubic((e*2)-f,a+g/2,g/2,f)},easeInQuart:function(e,a,g,f){return g*(e/=f)*e*e*e+a},easeOutQuart:function(e,a,g,f){return -g*((e=e/f-1)*e*e*e-1)+a},easeInOutQuart:function(e,a,g,f){if((e/=f/2)<1){return g/2*e*e*e*e+a}return -g/2*((e-=2)*e*e*e-2)+a},easeOutInQuart:function(e,a,g,f){if(e<f/2){return JSTweener.easingFunctions.easeOutQuart(e*2,a,g/2,f)}return JSTweener.easingFunctions.easeInQuart((e*2)-f,a+g/2,g/2,f)},easeInQuint:function(e,a,g,f){return g*(e/=f)*e*e*e*e+a},easeOutQuint:function(e,a,g,f){return g*((e=e/f-1)*e*e*e*e+1)+a},easeInOutQuint:function(e,a,g,f){if((e/=f/2)<1){return g/2*e*e*e*e*e+a}return g/2*((e-=2)*e*e*e*e+2)+a},easeOutInQuint:function(e,a,g,f){if(e<f/2){return JSTweener.easingFunctions.easeOutQuint(e*2,a,g/2,f)}return JSTweener.easingFunctions.easeInQuint((e*2)-f,a+g/2,g/2,f)},easeInSine:function(e,a,g,f){return -g*Math.cos(e/f*(Math.PI/2))+g+a},easeOutSine:function(e,a,g,f){return g*Math.sin(e/f*(Math.PI/2))+a},easeInOutSine:function(e,a,g,f){return -g/2*(Math.cos(Math.PI*e/f)-1)+a},easeOutInSine:function(e,a,g,f){if(e<f/2){return JSTweener.easingFunctions.easeOutSine(e*2,a,g/2,f)}return JSTweener.easingFunctions.easeInSine((e*2)-f,a+g/2,g/2,f)},easeInExpo:function(e,a,g,f){return(e==0)?a:g*Math.pow(2,10*(e/f-1))+a-g*0.001},easeOutExpo:function(e,a,g,f){return(e==f)?a+g:g*1.001*(-Math.pow(2,-10*e/f)+1)+a},easeInOutExpo:function(e,a,g,f){if(e==0){return a}if(e==f){return a+g}if((e/=f/2)<1){return g/2*Math.pow(2,10*(e-1))+a-g*0.0005}return g/2*1.0005*(-Math.pow(2,-10*--e)+2)+a},easeOutInExpo:function(e,a,g,f){if(e<f/2){return JSTweener.easingFunctions.easeOutExpo(e*2,a,g/2,f)}return JSTweener.easingFunctions.easeInExpo((e*2)-f,a+g/2,g/2,f)},easeInCirc:function(e,a,g,f){return -g*(Math.sqrt(1-(e/=f)*e)-1)+a},easeOutCirc:function(e,a,g,f){return g*Math.sqrt(1-(e=e/f-1)*e)+a},easeInOutCirc:function(e,a,g,f){if((e/=f/2)<1){return -g/2*(Math.sqrt(1-e*e)-1)+a}return g/2*(Math.sqrt(1-(e-=2)*e)+1)+a},easeOutInCirc:function(e,a,g,f){if(e<f/2){return JSTweener.easingFunctions.easeOutCirc(e*2,a,g/2,f)}return JSTweener.easingFunctions.easeInCirc((e*2)-f,a+g/2,g/2,f)},easeInElastic:function(g,e,k,j,f,i){var h;if(g==0){return e}if((g/=j)==1){return e+k}if(!i){i=j*0.3}if(!f||f<Math.abs(k)){f=k;h=i/4}else{h=i/(2*Math.PI)*Math.asin(k/f)}return -(f*Math.pow(2,10*(g-=1))*Math.sin((g*j-h)*(2*Math.PI)/i))+e},easeOutElastic:function(g,e,k,j,f,i){var h;if(g==0){return e}if((g/=j)==1){return e+k}if(!i){i=j*0.3}if(!f||f<Math.abs(k)){f=k;h=i/4}else{h=i/(2*Math.PI)*Math.asin(k/f)}return(f*Math.pow(2,-10*g)*Math.sin((g*j-h)*(2*Math.PI)/i)+k+e)},easeInOutElastic:function(g,e,k,j,f,i){var h;if(g==0){return e}if((g/=j/2)==2){return e+k}if(!i){i=j*(0.3*1.5)}if(!f||f<Math.abs(k)){f=k;h=i/4}else{h=i/(2*Math.PI)*Math.asin(k/f)}if(g<1){return -0.5*(f*Math.pow(2,10*(g-=1))*Math.sin((g*j-h)*(2*Math.PI)/i))+e}return f*Math.pow(2,-10*(g-=1))*Math.sin((g*j-h)*(2*Math.PI)/i)*0.5+k+e},easeOutInElastic:function(g,e,j,i,f,h){if(g<i/2){return JSTweener.easingFunctions.easeOutElastic(g*2,e,j/2,i,f,h)}return JSTweener.easingFunctions.easeInElastic((g*2)-i,e+j/2,j/2,i,f,h)},easeInBack:function(e,a,h,g,f){if(f==undefined){f=1.70158}return h*(e/=g)*e*((f+1)*e-f)+a},easeOutBack:function(e,a,h,g,f){if(f==undefined){f=1.70158}return h*((e=e/g-1)*e*((f+1)*e+f)+1)+a},easeInOutBack:function(e,a,h,g,f){if(f==undefined){f=1.70158}if((e/=g/2)<1){return h/2*(e*e*(((f*=(1.525))+1)*e-f))+a}return h/2*((e-=2)*e*(((f*=(1.525))+1)*e+f)+2)+a},easeOutInBack:function(e,a,h,g,f){if(e<g/2){return JSTweener.easingFunctions.easeOutBack(e*2,a,h/2,g,f)}return JSTweener.easingFunctions.easeInBack((e*2)-g,a+h/2,h/2,g,f)},easeInBounce:function(e,a,g,f){return g-JSTweener.easingFunctions.easeOutBounce(f-e,0,g,f)+a},easeOutBounce:function(e,a,g,f){if((e/=f)<(1/2.75)){return g*(7.5625*e*e)+a}else{if(e<(2/2.75)){return g*(7.5625*(e-=(1.5/2.75))*e+0.75)+a}else{if(e<(2.5/2.75)){return g*(7.5625*(e-=(2.25/2.75))*e+0.9375)+a}else{return g*(7.5625*(e-=(2.625/2.75))*e+0.984375)+a}}}},easeInOutBounce:function(e,a,g,f){if(e<f/2){return JSTweener.easingFunctions.easeInBounce(e*2,0,g,f)*0.5+a}else{return JSTweener.easingFunctions.easeOutBounce(e*2-f,0,g,f)*0.5+g*0.5+a}},easeOutInBounce:function(e,a,g,f){if(e<f/2){return JSTweener.easingFunctions.easeOutBounce(e*2,a,g/2,f)}return JSTweener.easingFunctions.easeInBounce((e*2)-f,a+g/2,g/2,f)}};JSTweener.easingFunctions.linear=JSTweener.easingFunctions.easeNone;
