(function(b){b.extend({_SpriteWrapper:{SpriteAnimationDirection:{ltr:"ltr",rtl:"rtl"},SpriteAnimationState:{running:1,pause:2},SpriteAnimation:function(a){this.jq=a;this._onStops=[];this._uniqueId="_SAUniqueId_"+Math.floor(Math.random()*9999);window[this._uniqueId]=this}}});b._SpriteWrapper.SpriteAnimation.prototype={frameWidth:0,jq:null,_loop:true,startFrame:0,endFrame:0,direction:b._SpriteWrapper.SpriteAnimationDirection.ltr,_currentFrame:-1,interval:50,_timerId:null,_tickDelegate:null,numberOfLoops:1,
_loopsCount:0,state:b._SpriteWrapper.SpriteAnimationState.running,start:function(){this._loopsCount=1;this._loop=this.numberOfLoops<0;this._currentFrame=this.startFrame;this.state=b._SpriteWrapper.SpriteAnimationState.running;this._tickDelegate=Function.CreateDelegate(this,this._tick);clearTimeout(this._timerId);this._timerId=setTimeout(this._tickDelegate,this.interval)},_tick:function(){if(this.state==b._SpriteWrapper.SpriteAnimationState.running){this.jq.css("background-position",-(this._currentFrame*
this.frameWidth)+"px 0px");this._timerId=setTimeout(this._tickDelegate,this.interval);if(this._currentFrame==this.endFrame)if(this._loop||this._loopsCount<this.numberOfLoops){this._loopsCount++;this._currentFrame=this.startFrame}else this.stop();else this._currentFrame=this.direction==b._SpriteWrapper.SpriteAnimationDirection.ltr?this._currentFrame+1:this._currentFrame-1}},_onStops:[],onStop:function(a,c){if(c)this._onStops[c]=a;else this._onStops.push(a)},removeOnStop:function(a){a&&this._onStops[a]&&
delete this._onStops[a]},stop:function(){for(var a in this._onStops)this._onStops[a]();clearTimeout(this._timerId)}};b._SpriteWrapper.SpriteAnimation.apply=function(a){var c=new b._SpriteWrapper.SpriteAnimation(a.jq);c.jq.attr("sprite-unique-id",c._uniqueId);c.frameWidth=a.frameWidth;c.startFrame=a.startFrame;c.endFrame=a.endFrame;c.direction=a.direction;c.numberOfLoops=a.numberOfLoops;c.interval=a.interval;c.onStop(a.onStop);c.start();return c}})(jQuery);
(function(b){b.fn.spriteAnimation=function(a){var c=b.extend({},b.fn.spriteAnimation.defaults,a);return this.each(function(){$this=b(this);if(typeof a=="undefined")if($this.attr("sprite-unique-id")!=""){window[$this.attr("sprite-unique-id")].stop();return}var d=b.meta?b.extend({},c,$this.data()):c;if(typeof d.frameWidth=="undefined")d.frameWidth=$this.width();d.jq=$this;if(typeof d.imageSrc=="undefined")b._SpriteWrapper.SpriteAnimation.apply(d);else{var e=new Image;e.src=d.imageSrc;var f=function(){d.jq.css("background-position",
-(d.startFrame*d.frameWidth)+"px 0px");d.jq.css("background-repeat","repeat-x");d.jq.css("background-image","url('"+d.imageSrc+"')");b._SpriteWrapper.SpriteAnimation.apply(d)};e.complete?f():jQuery(e).bind("error load onreadystatechange",function(){f()})}})};if(!Function.CreateDelegate)Function.CreateDelegate=function(a,c){return function(){c.apply(a,arguments)}};b.fn.spriteAnimation.defaults={numberOfLoops:-1,startFrame:0,endFrame:-1,direction:"ltr",interval:50,onStop:function(){}}})(jQuery);
