/* --------------------------------------------------------------------------------------------*/
/* ------------------------------------->>> COOLTIPS V 1.0 <<<---------------------------------*/
/* --------------------------------------------------------------------------------------------*/

/*


*/


var CoolTip = Class.create({
  initialize: function(obj, toolTipObj) {
      this.element = $(obj);
      this.trans = {};
      //remove title attribute so that the default browser tooltip doesnt show
      this.tip = this.element.title;
      this.tool_tip = $(toolTipObj);
      this.tool_tip_content = $('toolTip-content').firstDescendant('p');
      this.element.removeAttribute('title');
      
      //Add Events
      this.eventMouseOver = this.showCoolTip.bindAsEventListener(this);
      this.eventMouseOut = this.hideCoolTip.bindAsEventListener(this);
      this.registerEvents();
  },
   registerEvents: function() {
      Event.observe(this.element, "mouseover", this.eventMouseOver);
      Event.observe(this.element, "mouseout", this.eventMouseOut);
  },
  showCoolTip: function(event){
      Event.stop(event);
      // get Mouse position
      var offSet = this.element.viewportOffset();
      var scrollOffset = document.viewport.getScrollOffsets();
      var dim = this.element.getDimensions();
      //var mouse_x = Event.pointerX(event);
      //var mouse_y = Event.pointerY(event);
      var mouse_x = offSet.left + scrollOffset.left;
      var mouse_y = offSet.top + scrollOffset.top;
      this.tool_tip_content.innerHTML = this.tip;
      var tip_top = mouse_y + dim.height;
      var tip_left = mouse_x - 10;
      this.tool_tip.style.top = tip_top + "px";
      this.tool_tip.style.left = tip_left + "px";
      // this.trans = new Effect.Appear(this.tool_tip, {duration: 0.3});// so apparently ie7 still sucks at life.
      this.trans = Element.show.delay(0.3, this.tool_tip);
  },
  hideCoolTip: function(event){
      Event.stop(event);
      //this.trans.cancel();//stop the fade in animation.
      window.clearTimeout(this.trans);
      this.tool_tip.hide();
  }
});
