/*

 TODO: poprawić działanie i sprzężyć z "cycle"
 */
;
(function($) {
    $.fn.counter = function(options) {

        var changeBg = function($this, options) {
            var currentI = $this.counterVals.shift();
            //$this.css('background', 'url("' + options.img + '' + (currentI) + '")');
            $this.html('' + (currentI));
        }
        options = $.extend({
            img: '',
            limit: 5,
            timeout: 1000
        }, options);
        return this.each(function() {
            var $this = $(this);
            $this.css('background', 'url("' + options.img + '")');
            $this.counterVals = new Array();
            for (var i = 0; i < options.limit; i++) {
                $this.counterVals.push(i + 1);
                setTimeout(function() {
                    changeBg($this, options);
                }, options.timeout * (i + 1));
            }
            return $this;
        });
    };
    function waitTime(milis) {
        var date = new Date();
        var currDate = null;
        do {
            currDate = new Date();
        }
        while ((currDate - date) < milis);
    }
})(jQuery);



