/**
 * @author onelson@gmail.com
 */		
(function($) {
	$.fn.animThumb = function(o){
		o = $.extend({
			matchPattern: /.*\/[\d\w]+_(\d).+$/,
			replacePattern: /(.*\/[\d\w]+_)\d(.+)$/,
			duration: 400,
			numFrames: 6
		}, o);
		function advanceThumb()
		{
			$(node).attr('src').match(o.matchPattern);
			currentFrame = parseInt(RegExp.$1);
			nextFrame = currentFrame == o.numFrames ? 1: ++currentFrame;
			nextFrame = $(node).attr('src').replace(o.replacePattern, "$1"+nextFrame+"$2" );
			$(node).attr('src', nextFrame);
		}
		return this.each(function(){
			$(this).hover(
				function()
				{
					node = this;

					$(this).attr('start', $(this).attr('src'));	

					advanceThumb();
					anim = setInterval(	advanceThumb, o.duration);	
				},
				function()
				{
					clearInterval(anim);
					$(this).attr('src', $(this).attr('start'));
				}
			);
			
		});
	}
})(jQuery);