limit function calls per second
<p>I have the following code. Its goal is to limit number of passed function calls per given amount of time. It works but after given time is elapsed the passed function is called without any limitations. What's wrong? Please help.</p>

<pre><code>    var counter = 0;

    function limitCalls(seconds, callback, scope, args) {
        window.setInterval(function () {
            counter = 0;
        }, seconds);
        if (counter &lt; 1) {
            counter++;
            callback.apply(scope, args);                
        }
    }
</code></pre>

<p>Here is the example of usage:</p>

<pre><code>if ($('.slider').length) {
    $('.bottom-text').hide().eq(0).show();
    $('.prev').click(function () {
        limitCalls(500,function(){
            var slid = parseInt($('.slid').css('margin-left'));
            if (slid == 0) return;
            slid += 650;
            sliderIndex--;
            $('.slid').animate({'margin-left': slid}, 500);
            $('.slider-wrap nav a.active').removeClass('active')
                .prev()
                .addClass('active');
            $('#main header').attr('class', slide[sliderIndex - 1]);
            $('.bottom-text').hide().eq(sliderIndex - 1).show();
        });
        },this);

    $('.next').click(function () {
        limitCalls(500,function(){
            var slid = parseInt($('.slid').css('margin-left'));
            if (slid == -1300) return;
            slid -= 650;
            sliderIndex++;
            $('.slid').animate({'margin-left': slid}, 500);
            $('.slider-wrap nav a.active').removeClass('active')
                .next()
                .addClass('active');

            $('#main header').attr('class', slide[sliderIndex - 1]);
            $('.bottom-text').hide().eq(sliderIndex - 1).show();
        },this);

    });
</code></pre>
