var Indicator = Class.create();
Indicator.prototype = {
  initialize: function(offsetX, offsetY) {
    this.offsetX = offsetX || 8;
    this.offsetY = offsetY || 5;    

    var body = document.getElementsByTagName('body')[0];

    new Insertion.Bottom(
      body, '<div id="indicator" style="z-index: 1000; position:absolute; width:20px; height:20px; padding:6px; display: none; "><img src="/images/spinner.gif" border="0"></div>' 
    );

    this.indicator = $('indicator');

    Ajax.Responders.register({
      onLoading:  this.indicate.bind(this, true),
      onComplete: this.indicate.bind(this, false) 
    });  

    Event.observe(body, "mousemove", this.onMouseMove.bind(this));
  },

  onMouseMove: function(event) {
    try {
    this.indicator.style.top    = Event.pointerY(event) + this.offsetY + "px";         
    this.indicator.style.left   = Event.pointerX(event) + this.offsetX + "px"; 
    } catch(e) {}
  },

  indicate: function(visible) {
    if(visible) { this.indicator.show(); }
    else        { this.indicator.hide(); }
  }
};

Event.observe(window, "load", function(){ new Indicator(); });