$.widget("ui.ajaxLoader", {

    _init: function() {
        var self = this;
        this.requests = 0;
        $(document.body).bind("mousemove.ajaxLoader", function(e) {
            self.element.css({
                top: e.pageY + self.options.mouseOffset.Y,
                left: e.pageX + self.options.mouseOffset.X
            });
        });
    },

    _hide: function() {
        this.element.hide();
        $(document.body).css("cursor", "default");
    },

    isLoading: function() {
        return (this.requests > 0);
    },

    show: function() {
        var self = this;

        if (this.requests == 0) {
            this.element.show();
            $(document.body).css("cursor", "wait");
        }
        this.requests++;
    },

    hide: function() {
        if (this.requests > 0) {
            this.requests--;
            if (this.requests == 0) {
                this._hide();
            }
        }
    }

});

$.extend($.ui.ajaxLoader, {
    version: "1.0",
    defaults: {
        mouseOffset: {X: -75, Y: 20}
    }
});

$.ui.ajaxLoader.getter = "show hide isLoading";
$.ui.ajaxLoader.setter = "";