﻿/* Animate v1.0 Copyright (c) 2008 Analogue Web Design, LLC; Based on and inspired by Tween, Copyright (C) 2006 by Philippe Maegerman; Easing Equations v1.5, Copyright (c) 2003 Robert Penner, all rights reserved. Open Source BSD License. */
function Animate(obj,property,transition,begin,finish,duration,suffix){this.initialize(obj,property,transition,begin,finish,duration,suffix)}Animate.extend=analogue.extend;Animate.extend({backIn:function(t,b,c,d){var s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b},backInOut:function(t,b,c,d){var 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},backOut:function(t,b,c,d){var s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},bounceIn:function(t,b,c,d){return c-Animate.bounceOut(d-t,0,c,d)+b},bounceInOut:function(t,b,c,d){if(t<d/2){return Animate.bounceIn(t*2,0,c,d)*0.5+b}return Animate.bounceOut(t*2-d,0,c,d)*0.5+c*0.5+b},bounceOut:function(t,b,c,d){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+0.75)+b}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+0.9375)+b}else{return c*(7.5625*(t-=(2.625/2.75))*t+0.984375)+b}},delegate:function(o,f){var a=[],i,ii;for(i=2,ii=arguments.length;i<ii;i+=1){a[i-2]=arguments[i]}return function(){f.apply(o,[].concat(arguments,a))}},easeIn:function(t,b,c,d){return c*(t/=d)*t+b},easeInOut:function(t,b,c,d){if((t/=d/2)<1){return c/2*t*t+b}return-c/2*((t-=1)*(t-2)-1)+b},easeOut:function(t,b,c,d){return-c*(t/=d)*(t-2)+b},snapIn:function(t,b,c,d){return c*(t/=d)*t*t*t*t+b},snapInOut:function(t,b,c,d){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},snapOut:function(t,b,c,d){return c*((t=t/d-1)*t*t*t*t+1)+b}});Animate.prototype={obj:{},property:'',transition:function(t,b,c,d){return c*t/d+b},begin:0,change:0,prevTime:0,prevPosition:0,looping:false,duration:0,time:0,position:0,startTime:0,name:'',suffix:'',listeners:[],setTime:function(t){this.prevTime=this.time;if(t>this.getDuration()){if(this.looping){this.rewind(t-this.duration);this.update();this.callEvent('onloop',{target:this,type:'onloop'})}else{this.time=this.duration;this.update();this.stop();this.callEvent('onfinish',{target:this,type:'onfinish'})}}else if(t<0){this.rewind();this.update()}else{this.time=t;this.update()}},setDuration:function(d){this.duration=(d===null||d<=0)?100000:d},getDuration:function(){return this.duration},setPosition:function(p){this.prevPosition=this.position;var a=this.suffix!==''?this.suffix:'';if(this.property=='opacity'){this.obj.style.opacity=(Math.round(p))/100;this.obj.style.MozOpacity=(Math.round(p))/100;this.obj.style.KhtmlOpacity=(Math.round(p))/100;this.obj.style.filter='alpha(opacity='+Math.round(p)+')'}else{this.obj[this.property]=Math.round(p)+a}this.position=p;this.callEvent('onchange',{target:this,type:'onchange'})},getPosition:function(t){if(t===undefined){t=this.time}return this.transition(t,this.begin,this.change,this.duration)},setFinish:function(f){this.change=f-this.begin},initialize:function(obj,property,transition,begin,finish,duration,suffix){if(!arguments.length){return}this.listeners=[];this.addEvent(this);if(suffix){this.suffix=suffix}this.obj=obj;this.property=property;if(property=='opacity'){if(begin<0){begin=0}if(finish>100){finish=100}}this.begin=begin;this.position=begin;this.setDuration(duration);if(transition!==null&&transition!==''){this.transition=transition}this.setFinish(finish)},start:function(){this.rewind();this.startEnterFrame();this.callEvent('onstart',{target:this,type:'onstart'})},rewind:function(t){this.stop();this.time=(t===undefined)?0:t;this.fixTime();this.update()},fforward:function(){this.time=this.duration;this.fixTime();this.update()},update:function(){this.setPosition(this.getPosition(this.time))},startEnterFrame:function(){this.stopEnterFrame();this.isPlaying=true;this.onEnterFrame()},onEnterFrame:function(){if(this.isPlaying){this.nextFrame();setTimeout(Animate.delegate(this,this.onEnterFrame),0)}},nextFrame:function(){this.setTime((this.getTimer()-this.startTime)/1000)},stop:function(){this.stopEnterFrame();this.callEvent('onstop',{target:this,type:'onstop'})},stopEnterFrame:function(){this.isPlaying=false},continueTo:function(finish,duration){this.begin=this.position;this.setFinish(finish);if(this.duration!==undefined){this.setDuration(duration)}this.start()},resume:function(){this.fixTime();this.startEnterFrame();this.callEvent('onresume',{target:this,type:'onresume'})},yoyo:function(){this.continueTo(this.begin,this.time)},addEvent:function(listener){this.removeEvent(listener);return this.listeners.push(listener)},removeEvent:function(listener){var i,ii,listeners=this.listeners;for(i=0,ii=listeners.length;i<ii;i+=1){if(listeners[i]==listener){listeners.splice(i,1);return true}}return false},callEvent:function(){var i,ii,listener,listeners=this.listeners,properties=[];for(i=0,ii=arguments.length;i<ii;i+=1){properties.push(arguments[i])}listener=properties.shift();for(i=0,ii=listeners.length;i<ii;i+=1){if(listeners[i][listener]){listeners[i][listener].apply(listeners[i],properties)}}},fixTime:function(){this.startTime=this.getTimer()-this.time*1000},getTimer:function(){return new Date().getTime()-this.time}};
