;(function(window, $) {
    "use strict";

    var _requests = [];

    window.ajaxManager =
    {
        addReq: function(opt) {
            _requests.push(opt);
        },

        removeReq: function(opt) {
            if( $.inArray(opt, _requests) > -1 )
                _requests.splice($.inArray(opt, _requests), 1);
        },

        run: function() {
            var self = this,
                oriSuc;

            if (_requests.length) 
            {
                oriSuc = _requests[0].complete;

                _requests[0].complete = function() {
                    if( typeof(oriSuc) === 'function' ) oriSuc();
                    _requests.shift();
                    self.run.apply(self, []);
                };   

                $.ajax(_requests[0]);
            } 
            else 
            {
                self.tid = setTimeout(function() {
                    self.run.apply(self, []);
                }, 500);
            }
        },
        stop: function() {
            _requests = [];
            clearTimeout(this.tid);
        }
    };
})(window, jQuery);


$(function() {
    ajaxManager.run();
    
    ajaxManager.addReq({
        url: "/ajax/blah",
        type: 'GET',
        dataType: 'html',
        success: function(x){
            $('.ajax_results').append(x);
        },
        error: function(x){
            console.log(x)
        }
    });

});