$.queuedelay = {
    _timer: null,
    _queue: [],
    add: function(fn, context, time) {
        var setTimer = function(time) {
            $.queuedelay._timer = setTimeout(function() {
                time = $.queuedelay.add();
                if ($.queuedelay._queue.length) {
                    setTimer(time);
                }
            }, time || 2);
        }

        if (fn) {
            $.queuedelay._queue.push([fn, context, time]);
            if ($.queuedelay._queue.length == 1) {
                setTimer(time);
            }
            return;
        }

        var next = $.queuedelay._queue.shift();
        if (!next) {
            return 0;
        }
        next[0].call(next[1] || window);
        return next[2];
    },
    clear: function() {
        clearTimeout($.queuedelay._timer);
        $.queuedelay._queue = [];
    }
};