var Tooltip = Class.create();
Tooltip.prototype = {
  initialize: function(element, tool_tip) {
    var options = Object.extend({delta_x:5,delta_y:5,zindex: 1000},arguments[1] || {});
    this.element = $(element);
    this.tool_tip = $(tool_tip);
    this.options = options;
    this.tool_tip.hide();
    this.eventMouseOver = this.showTooltip.bindAsEventListener(this);
    this.eventMouseOut = this.hideTooltip.bindAsEventListener(this);
    this.registerEvents();
  },

  destroy: function() {
    Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
    Event.stopObserving(this.element, "mouseout", this.eventMouseOut);
  },

  registerEvents: function() {
    Event.observe(this.element, "mouseover", this.eventMouseOver);
    Event.observe(this.element, "mouseout", this.eventMouseOut);
  },

  showTooltip: function(event){
	Event.stop(event);
	pos = this.element.cumulativeOffset();
	mouse_x=pos[0]+20;
	mouse_y=pos[1]+5;
	this.setStyles(mouse_x, mouse_y);
	new Element.show(this.tool_tip);
  },
  
  setStyles: function(x, y){
	Element.setStyle(this.tool_tip, { position:'absolute',top:y + "px",left:x + "px",zindex:this.options.zindex});
  },

  hideTooltip: function(event){
	new Element.hide(this.tool_tip);
  }
}