/**
 * Simple number counter for jQuery.
 *
 * Author:  Michael HÃ¼neburg
 * Website: http://michaelhue.com
 */
(function($) {

	var defaults = {
		startDate: new Date(),
		startValue: 0,
		interval: 1000,
		step: 1,
		digits: 0,
		precision: 2,
		format: function(value) { return value; }
	};

	$.extend($.fn, {
		counter: function(options) {
			options = $.extend({}, defaults, options);

			return this.each(function() {
				setInterval($.proxy(function() {
					var diff = Math.abs((new Date()) - options.startDate);
					var value = (options.startValue + (diff / options.interval * options.step)).toFixed(options.precision);
					$(this).html(options.format(value));
				}, this), options.interval);
			});
		}
	});

}(jQuery));
