//<script type="text/javascript">
jQuery.fn.extend({
 play:function(a,fps,loop){
  jQuery(this).data('animation_array',a);
  var undefined; var fps = (fps==undefined||isNaN(fps)?60:fps);
  jQuery(this).data('loop_anim',loop);
  jQuery(this).data('frames_per_sec',fps);
  jQuery(this).data('current_frame',1);
  jQuery(this).nextframe();
  }
,nextframe:function(){
  var l = jQuery(this).data('loop_anim');
  var f = jQuery(this).data('frames_per_sec');
  var a = jQuery(this).data('animation_array');
  var c = jQuery(this).data('current_frame');
  c = (c+1>=a.length&&l?1:c+1); jQuery(this).data('current_frame',c);
  if(c<a.length)jQuery(this).css({backgroundPosition:(-a[c][0])+'px '+(-a[c][1])+'px'})
  //.delay(1000/f)
  .animate({backgroundPosition:(-a[c][0])+'px '+(-a[c][1])+'px'},1000/f,'linear',function(e){
   jQuery(this).nextframe();
   });  
  }
 });
//</script>
