(function(a){
    var defaults = {
        timeout : 5000,
        step : 20,
        wait : 2000,
        update : function(value){},
        complete : function(){}
    };

    var options = {};

    var count = 0;
    var intervalId = null;

    a.fn.timerCounter = function(options) {
        
        options = a.extend(defaults, options);

        update = function(){
            options.update(parseInt((count * 100)/options.timeout));
            count += options.step;
            if (count > options.timeout){
                count = options.timeout;
                options.update(parseInt((count * 100)/options.timeout));
                clearInterval(intervalId);
                options.complete();
                setTimeout(resetT, options.wait);
            }
        }

        init = function(){
            intervalId = setInterval(update, options.step);
            update();
        };

        resetT = function(){
            count = 0;
            intervalId = setInterval(update, options.step);
            update();
        }

        return this.each(function() {
            init();
        });

    };
})(jQuery);

