// This must be transcluded directly after wz_tooltip.js

with(config)
{
  Above = true;
  CenterMouse = true;
  Delay = 1000;
  // Duration = -250;  // still not working right in wz_tooltip 5.3
  FadeIn = 250;
  FadeOut = 250;
  FontSize = '11px';
  OffsetY = 20;
  Opacity = 90;
  Padding = 4;
  Width = 300;
}

function TitlesToTooltips(bgcolor, bordercolor, hilitebgcolor, wikeicon, siteicon, sitetitle) {
 var tags = getElementsBySelector('a');
 var imgs = getElementsBySelector('img');
 var inputs = getElementsBySelector('input');
 var thesitetitle = sitetitle.toLowerCase();
 
 for (var i = 0; i < imgs.length; i++)
 {
   if ((imgs[i].alt != "") && (imgs[i].className != "banner") && (imgs[i].name.substr(0, 4) != "link"))
   {
     imgString = new String(imgs[i].alt);
     imgString = imgString.replace(/^\xA0/, "");
     imgString = imgString.replace(/\xA0$/, "");
     imgString = "<div style='width: " + config.Width + "px;'>" + siteicon + imgString;
     imgString = imgString + "<br /><br style='line-height: 4px; '/><div align='right'><span style='font-variant: small-caps; font-size: 10px; '>" + thesitetitle + "</span></div></div>";
   
     imgs[i].onmouseover = new Function("Tip(\"" + imgString + "\", BORDERWIDTH, 4, BGCOLOR, \"" + bgcolor + "\", BORDERCOLOR, \"" + bordercolor + "\");");
     imgs[i].onmouseout = new Function("UnTip();");
     imgs[i].title = "";
   }
   imgs[i].alt = "";
 }
 
 for (var i = 0; i < tags.length; i++)
 {
  if ((tags[i].title) && (tags[i].name))
  {
    if (tags[i].name.substr(0, 4) == "wike")
    {
      boldedString = new String(tags[i].name.substr(5));
      prereplaceString = new String("");
      do
      {
   	    prereplaceString = boldedString;
        boldedString = boldedString.replace(/_/, " ");
      }
      while(prereplaceString != boldedString);
   
      defString = new String(tags[i].title);
      defString = defString.replace(/^\xA0/, "");
      defString = defString.replace(/\xA0$/, "");
      defString = defString.replace(/^Wikipedia:\s/, "");
   
      var posboldString = defString.indexOf(boldedString);
      defString = defString.substr(0, posboldString) + "<b>" + boldedString + "</b>" + defString.substr(posboldString + boldedString.length); 
   
      defString = defString.replace(/ \(New Window\)/, "<br style='clear: both; '/><br style='line-height: 2px; '/><center><span style='font-variant: small-caps; font-size: 10px; '>(full article appears in new window upon click)</span></center>");
      defString = "<div style='width: " + config.Width + "px;'>" + wikeicon + defString + "</div>";
   
      if (tt_op) {
        captionString = new String("<center><span style='font-variant: small-caps; '>Wikipedia Lookup</span></center>");
      }
      else {
        captionString = new String("<center><span style='font-variant: small-caps; letter-spacing: 2px; '>Wikipedia Lookup</span></center>");
      }

      tags[i].onmouseover = new Function("Tip(\"" + defString + "\", TITLEBGCOLOR, \"" + bordercolor + "\", TITLEFONTCOLOR, \"" + bgcolor + "\", TITLEFONTSIZE, \"13px\", TITLE, \"" + captionString + "\", SHADOW, true, OFFSETY, 30, BORDERWIDTH, 2, BGCOLOR, \"" + bgcolor + "\", BORDERCOLOR, \"" + bordercolor + "\");");
      tags[i].onmouseout = new Function("UnTip();");
      tags[i].title = "";
    }
    else if (tags[i].name.substr(0, 4) == "link")
    {
      var borderwidth = 2;
         
      linkString = new String(tags[i].title);
      linkString = linkString.replace(/^\xA0/, "");
      linkString = linkString.replace(/\xA0$/, "");
   
      linkString = linkString.replace(/ \(New Window\)/, "<br style='clear: both; '/><br style='line-height: 2px; '/><center><span style='font-variant: small-caps; font-size: 10px; '>(appears in new window upon click)</span></center>");
      if (tags[i].name.substr(0, 6) == "linkin")
      {
        if (tags[i].name.substr(0, 11) == "linkinthick")
        {
          borderwidth = 4;
        }
        linkString = "<div style='width: " + config.Width + "px;'>" + siteicon + linkString;
        linkString = linkString + "<br /><br style='line-height: 4px; '/><div align='right'><span style='font-variant: small-caps; font-size: 10px; '>" + thesitetitle + "</span></div></div>";
      }
      else {
        linkString = "<div style='width: " + config.Width + "px;'>" + linkString + "</div>";
      }
   
      tags[i].onmouseover = new Function("Tip(\"" + linkString + "\", BORDERWIDTH, " + borderwidth + ", BGCOLOR, \"" + bgcolor + "\", BORDERCOLOR, \"" + bordercolor + "\");");
      tags[i].onmouseout = new Function("UnTip();");
      tags[i].title = "";
    }
  }
 }
 
 for (var i = 0; i < inputs.length; i++)
 {
  if ((inputs[i].title) && (inputs[i].name))
  {
    if (inputs[i].name.substr(0, 6) == "submit")
    {   
      inputString = new String(inputs[i].title);
      inputString = inputString.replace(/^\xA0/, "");
      inputString = inputString.replace(/\xA0$/, "");
   
      inputString = "<div style='width: " + config.Width + "px;'>" + siteicon + inputString;
      inputString = inputString + "<br /><br style='line-height: 4px; '/><div align='right'><span style='font-variant: small-caps; font-size: 10px; '>" + thesitetitle + "</span></div></div>";
   
      inputs[i].onmouseover = new Function("Tip(\"" + inputString + "\", BORDERWIDTH, 2, BGCOLOR, \"" + bgcolor + "\", BORDERCOLOR, \"" + bordercolor + "\");");
      inputs[i].onmouseout = new Function("UnTip();");
      inputs[i].title = "";
    }
  }
 }
}