(function(a){a._spritely={animate:function(e){var g=a(e.el);var b=g.attr("id");if(!a._spritely.instances[b]){return this}e=a.extend(e,a._spritely.instances[b]||{});if(e.play_frames&&!a._spritely.instances[b]["remaining_frames"]){a._spritely.instances[b]["remaining_frames"]=e.play_frames+1}if(e.type=="sprite"&&e.fps){var h;var c=function(p){var k=e.width,o=e.height;if(!h){h=[];total=0;for(var n=0;n<e.no_of_frames;n++){h[h.length]=(0-total);total+=k}}if(a._spritely.instances[b]["current_frame"]==0){if(e.on_first_frame){e.on_first_frame(p)}}else{if(a._spritely.instances[b]["current_frame"]==h.length-1){if(e.on_last_frame){e.on_last_frame(p)}}}if(e.on_frame&&e.on_frame[a._spritely.instances[b]["current_frame"]]){e.on_frame[a._spritely.instances[b]["current_frame"]](p)}if(e.rewind==true){if(a._spritely.instances[b]["current_frame"]<=0){a._spritely.instances[b]["current_frame"]=h.length-1}else{a._spritely.instances[b]["current_frame"]=a._spritely.instances[b]["current_frame"]-1}}else{if(a._spritely.instances[b]["current_frame"]>=h.length-1){a._spritely.instances[b]["current_frame"]=0}else{a._spritely.instances[b]["current_frame"]=a._spritely.instances[b]["current_frame"]+1}}var q=a._spritely.getBgY(p);p.css("background-position",h[a._spritely.instances[b]["current_frame"]]+"px "+q);if(e.bounce&&e.bounce[0]>0&&e.bounce[1]>0){var j=e.bounce[0];var l=e.bounce[1];var m=e.bounce[2];p.animate({top:"+="+j+"px",left:"-="+l+"px"},m).animate({top:"-="+j+"px",left:"+="+l+"px"},m)}};if(a._spritely.instances[b]["remaining_frames"]&&a._spritely.instances[b]["remaining_frames"]>0){a._spritely.instances[b]["remaining_frames"]--;if(a._spritely.instances[b]["remaining_frames"]==0){a._spritely.instances[b]["remaining_frames"]=-1;delete a._spritely.instances[b]["remaining_frames"];return}else{c(g)}}else{if(a._spritely.instances[b]["remaining_frames"]!=-1){c(g)}}}else{if(e.type=="pan"){if(!a._spritely.instances[b]["_stopped"]){if(e.dir=="up"){a._spritely.instances[b]["l"]=a._spritely.getBgX(g).replace("px","");a._spritely.instances[b]["t"]=(a._spritely.instances[b]["t"]-(e.speed||1))||0}else{if(e.dir=="down"){a._spritely.instances[b]["l"]=a._spritely.getBgX(g).replace("px","");a._spritely.instances[b]["t"]=(a._spritely.instances[b]["t"]+(e.speed||1))||0}else{if(e.dir=="left"){a._spritely.instances[b]["l"]=(a._spritely.instances[b]["l"]-(e.speed||1))||0;a._spritely.instances[b]["t"]=a._spritely.getBgY(g).replace("px","")}else{a._spritely.instances[b]["l"]=(a._spritely.instances[b]["l"]+(e.speed||1))||0;a._spritely.instances[b]["t"]=a._spritely.getBgY(g).replace("px","")}}}var f=a._spritely.instances[b]["l"].toString();if(f.indexOf("%")==-1){f+="px "}else{f+=" "}var d=a._spritely.instances[b]["t"].toString();if(d.indexOf("%")==-1){d+="px "}else{d+=" "}a(g).css("background-position",f+d)}}}a._spritely.instances[b]["options"]=e;window.setTimeout(function(){a._spritely.animate(e)},parseInt(1000/e.fps))},randomIntBetween:function(c,b){return parseInt(rand_no=Math.floor((b-(c-1))*Math.random())+c)},getBgY:function(b){if(a.browser.msie){var c=a(b).css("background-position-y")||"0"}else{var c=(a(b).css("background-position")||" ").split(" ")[1]}return c},getBgX:function(c){if(a.browser.msie){var b=a(c).css("background-position-x")||"0"}else{var b=(a(c).css("background-position")||" ").split(" ")[0]}return b},get_rel_pos:function(d,b){var c=d;if(d<0){while(c<0){c+=b}}else{while(c>b){c-=b}}return c}};a.fn.extend({spritely:function(d){var d=a.extend({type:"sprite",do_once:false,width:null,height:null,fps:12,no_of_frames:2,stop_after:null},d||{});var b=a(this).attr("id");if(!a._spritely.instances){a._spritely.instances={}}if(!a._spritely.instances[b]){if(d.start_at_frame){a._spritely.instances[b]={current_frame:d.start_at_frame-1}}else{a._spritely.instances[b]={current_frame:-1}}}a._spritely.instances[b]["type"]=d.type;a._spritely.instances[b]["depth"]=d.depth;d.el=this;d.width=d.width||a(this).width()||100;d.height=d.height||a(this).height()||100;var c=function(){return parseInt(1000/d.fps)};if(!d.do_once){window.setTimeout(function(){a._spritely.animate(d)},c(d.fps))}else{a._spritely.animate(d)}return this},sprite:function(b){var b=a.extend({type:"sprite",bounce:[0,0,1000]},b||{});return a(this).spritely(b)},pan:function(b){var b=a.extend({type:"pan",dir:"left",continuous:true,speed:1},b||{});return a(this).spritely(b)},flyToTap:function(b){var b=a.extend({el_to_move:null,type:"moveToTap",ms:1000,do_once:true},b||{});if(b.el_to_move){a(b.el_to_move).active()}if(a._spritely.activeSprite){if(window.Touch){a(this)[0].ontouchstart=function(g){var f=a._spritely.activeSprite;var h=g.touches[0];var d=h.pageY-(f.height()/2);var c=h.pageX-(f.width()/2);f.animate({top:d+"px",left:c+"px"},1000)}}else{a(this).click(function(j){var g=a._spritely.activeSprite;a(g).stop(true);var d=g.width();var i=g.height();var c=j.pageX-(d/2);var f=j.pageY-(i/2);g.animate({top:f+"px",left:c+"px"},1000)})}}return this},isDraggable:function(c){if((!a(this).draggable)){return this}var c=a.extend({type:"isDraggable",start:null,stop:null,drag:null},c||{});var b=a(this).attr("id");if(!a._spritely.instances[b]){return this}a._spritely.instances[b].isDraggableOptions=c;a(this).draggable({start:function(){var d=a(this).attr("id");a._spritely.instances[d].stop_random=true;a(this).stop(true);if(a._spritely.instances[d].isDraggableOptions.start){a._spritely.instances[d].isDraggableOptions.start(this)}},drag:c.drag,stop:function(){var d=a(this).attr("id");a._spritely.instances[d].stop_random=false;if(a._spritely.instances[d].isDraggableOptions.stop){a._spritely.instances[d].isDraggableOptions.stop(this)}}});return this},active:function(){a._spritely.activeSprite=this;return this},activeOnClick:function(){var b=a(this);if(window.Touch){b[0].ontouchstart=function(c){a._spritely.activeSprite=b}}else{b.click(function(c){a._spritely.activeSprite=b})}return this},spRandom:function(d){var d=a.extend({top:50,left:50,right:290,bottom:320,speed:4000,pause:0},d||{});var b=a(this).attr("id");if(!a._spritely.instances[b]){return this}if(!a._spritely.instances[b].stop_random){var f=a._spritely.randomIntBetween;var e=f(d.top,d.bottom);var c=f(d.left,d.right);a("#"+b).animate({top:e+"px",left:c+"px"},d.speed)}window.setTimeout(function(){a("#"+b).spRandom(d)},d.speed+d.pause);return this},makeAbsolute:function(){return this.each(function(){var b=a(this);var c=b.position();b.css({position:"absolute",marginLeft:0,marginTop:0,top:c.top,left:c.left}).remove().appendTo("body")})},spSet:function(d,c){var b=a(this).attr("id");a._spritely.instances[b][d]=c;return this},spGet:function(d,c){var b=a(this).attr("id");return a._spritely.instances[b][d]},spStop:function(b){a(this).each(function(){var c=a(this).attr("id");a._spritely.instances[c]["_last_fps"]=a(this).spGet("fps");a._spritely.instances[c]["_stopped"]=true;a._spritely.instances[c]["_stopped_f1"]=b;if(a._spritely.instances[c]["type"]=="sprite"){a(this).spSet("fps",0)}if(b){var d=a._spritely.getBgY(a(this));a(this).css("background-position","0 "+d)}});return this},spStart:function(){a(this).each(function(){var b=a(this).attr("id");var c=a._spritely.instances[b]["_last_fps"]||12;a._spritely.instances[b]["_stopped"]=false;if(a._spritely.instances[b]["type"]=="sprite"){a(this).spSet("fps",c)}});return this},spToggle:function(){var b=a(this).attr("id");var d=a._spritely.instances[b]["_stopped"]||false;var c=a._spritely.instances[b]["_stopped_f1"]||false;if(d){a(this).spStart()}else{a(this).spStop(c)}return this},fps:function(b){a(this).each(function(){a(this).spSet("fps",b)});return this},spSpeed:function(b){a(this).each(function(){a(this).spSet("speed",b)});return this},spRelSpeed:function(b){a(this).each(function(){var c=a(this).spGet("depth")/100;a(this).spSet("speed",b*c)});return this},spChangeDir:function(b){a(this).each(function(){a(this).spSet("dir",b)});return this},spState:function(b){a(this).each(function(){var d=((b-1)*a(this).height())+"px";var e=a._spritely.getBgX(a(this));var c=e+" -"+d;a(this).css("background-position",c)});return this},lockTo:function(c,b){a(this).each(function(){var d=a(this).attr("id");if(!a._spritely.instances[d]){return this}a._spritely.instances[d]["locked_el"]=a(this);a._spritely.instances[d]["lock_to"]=a(c);a._spritely.instances[d]["lock_to_options"]=b;window.setInterval(function(){if(a._spritely.instances[d]["lock_to"]){var g=a._spritely.instances[d]["locked_el"];var j=a._spritely.instances[d]["lock_to"];var f=a._spritely.instances[d]["lock_to_options"];var m=f.bg_img_width;var i=j.height();var k=a._spritely.getBgY(j);var l=a._spritely.getBgX(j);var h=(parseInt(l)+parseInt(f.left));var e=(parseInt(k)+parseInt(f.top));h=a._spritely.get_rel_pos(h,m);a(g).css({top:e+"px",left:h+"px"})}},b.interval||20)});return this},destroy:function(){var c=a(this);var b=a(this).attr("id");delete a._spritely.instances[b];return this}})})(jQuery);try{document.execCommand("BackgroundImageCache",false,true)}catch(err){};
