var Tooltip = Class.create();
Tooltip.prototype = {
  initialize: function(element, tool_tip) {
    var options = Object.extend({delta_x: 5, delta_y: 5}, arguments[2] || {});

    this.element      = $(element);
    this.tool_tip     = $(tool_tip);

    this.options      = options;

    this.eventMouseOver = this.showTooltip.bindAsEventListener(this);
    this.eventMouseOut   = this.hideTooltip.bindAsEventListener(this);

    Event.observe(this.element, "mousemove", this.eventMouseOver);
    Event.observe(this.element, "mouseout", this.eventMouseOut);
  },

  showTooltip: function(event){
  	Event.stop(event);

    var mouse_x = Event.pointerX(event);
  	var mouse_y = Event.pointerY(event);
		
		var parent_offset = $(this.tool_tip.parentNode).cumulativeOffset();
		
  	mouse_x = mouse_x - parent_offset.left + this.options.delta_x;
  	mouse_y = mouse_y - parent_offset.top + this.options.delta_y;
	
	  $(this.tool_tip).setStyle({top:mouse_y + "px", left:mouse_x + "px"}).show();
  },
  
  hideTooltip: function(){ $(this.tool_tip).hide(); }
}
