(function(c){var a=function(e,d){this.$element=c(e);this.options=c.extend({},a.DEFAULTS,this.dataOptions(),d);this.init()};a.DEFAULTS={from:0,to:0,speed:1000,refreshInterval:100,decimals:0,formatter:b,onUpdate:null,onComplete:null};a.prototype.init=function(){this.value=this.options.from;this.loops=Math.ceil(this.options.speed/this.options.refreshInterval);this.loopCount=0;this.increment=(this.options.to-this.options.from)/this.loops};a.prototype.dataOptions=function(){var d={from:this.$element.data("from"),to:this.$element.data("to"),speed:this.$element.data("speed"),refreshInterval:this.$element.data("refresh-interval"),decimals:this.$element.data("decimals")};var g=Object.keys(d);for(var f in g){var e=g[f];if(typeof(d[e])==="undefined"){delete d[e]}}return d};a.prototype.update=function(){this.value+=this.increment;this.loopCount++;this.render();if(typeof(this.options.onUpdate)=="function"){this.options.onUpdate.call(this.$element,this.value)}if(this.loopCount>=this.loops){clearInterval(this.interval);this.value=this.options.to;if(typeof(this.options.onComplete)=="function"){this.options.onComplete.call(this.$element,this.value)}}};a.prototype.render=function(){var d=this.options.formatter.call(this.$element,this.value,this.options);this.$element.text(d)};a.prototype.restart=function(){this.stop();this.init();this.start()};a.prototype.start=function(){this.stop();this.render();this.interval=setInterval(this.update.bind(this),this.options.refreshInterval)};a.prototype.stop=function(){if(this.interval){clearInterval(this.interval)}};a.prototype.toggle=function(){if(this.interval){this.stop()}else{this.start()}};function b(e,d){return e.toFixed(d.decimals)}c.fn.countTo=function(d){return this.each(function(){var g=c(this);var f=g.data("countTo");var h=!f||typeof(d)==="object";var e=typeof(d)==="object"?d:{};var i=typeof(d)==="string"?d:"start";if(h){if(f){f.stop()}g.data("countTo",f=new a(this,e))}f[i].call(f)})}}(jQuery));