// JavaScript Document

var Tooltips = 
{
  init: function()
  {
    var links = document.getElementsByTagName("a");//gets anchor tags
    
    for (var i = 0; i < links.length; i++)//if title exists and is over sero characters
    {
      var title = links[i].getAttribute("title");//gets the title
      
      if (title && title.length > 0)
      {
        Core.addEventListener(links[i], "mouseover", Tooltips.showTipListener);//shows tip from core.js
        Core.addEventListener(links[i], "focus", Tooltips.showTipListener);//shows tip from core.js
        Core.addEventListener(links[i], "mouseout", Tooltips.hideTipListener);//hides the tip from core.js
        Core.addEventListener(links[i], "blur", Tooltips.hideTipListener);//hides the tip from core.js
      }
    }
  },

  showTip: function(link)
  {
    Tooltips.hideTip(link);

    var tip = document.createElement("span");//creates DOM
    tip.className = "tooltip";//creates span
    var tipText = document.createTextNode(link.title);//creates a text node
    tip.appendChild(tipText);//puts text inside span
    link.appendChild(tip);//adds tooltipas a child of the link
    
    link._tooltip = tip;
    link.title = "";
    
    // Fix for Safari2/Opera9 repaint issue
    document.documentElement.style.position = "relative";
  },
  
  hideTip: function(link)//hides the tool tip
  {
    if (link._tooltip)//if the link has a tooltip
    {
      link.title = link._tooltip.childNodes[0].nodeValue;      
      link.removeChild(link._tooltip);
      link._tooltip = null;
      
      // Fix for Safari2/Opera9 repaint issue
      document.documentElement.style.position = "static";
    }
  },

  showTipListener: function(event)
  {
    Tooltips.showTip(this);
    Core.preventDefault(event);//keeps browser from following the link
  },
  
  hideTipListener: function(event)
  {
    Tooltips.hideTip(this);
  }
};

Core.start(Tooltips);
