HNSpecial.settings.registerModule("user_tooltips", function () {
  var container;
  var timeout;
  var request;
  var tooltip;
  var cache = {};

  function remove(){
    clearTimeout(timeout);

    if (request) {
      request.abort();
      request = null;
    }

    if (container) {
      container.remove();
      container = null;
      tooltip = null;
    }
  }

  window.addEventListener("scroll", remove);

  _.$('a[href^="user?id="]').forEach(function (link) {
    var href = link.href;

    function offset(key) {
      // walk up link parent tree and increment offset
      var elem = link;
      var num = 0;
      do {
        if (!isNaN(elem[key])) {
          num += elem[key];
        }
      } while(elem = elem.offsetParent);
      return num;
    }

    function display(page) {
      // create dummy element so we can query it
      var dummy = _.createElement("div");
      dummy.innerHTML = page;

      _.$("td[valign=top]", dummy).forEach(function (td) {
        var key = td.textContent.slice(0, -1); // remove trailing colon
        var val = td.parentNode.children[1].textContent.trim();
        if (!val) return;

        var row = document.createElement("div");
        row.className = "hn-special-tooltip-row";
        tooltip.appendChild(row);

        var keyElem = document.createElement("div");
        keyElem.textContent = _.naturalWords(key);
        keyElem.className = "hn-special-tooltip-key";
        row.appendChild(keyElem);

        var valElem = document.createElement("div");
        valElem.textContent = val;
        valElem.className = "hn-special-tooltip-value";
        row.appendChild(valElem);

        var clear = document.createElement("div");
        clear.className = "hn-special-tooltip-clear";
        tooltip.appendChild(clear);
      });
    }

    link.onmouseover = function () {
      remove();

      timeout = setTimeout(function () {
        // create the container here so the user has feedback that it's loading
        
        container = document.createElement("div");
        container.className = "hn-special-tooltip-container";
        document.body.appendChild(container);

        // position the tooltip container right underneath the user link
        container.style.top = offset("offsetTop") + link.offsetHeight;
        container.style.left = offset("offsetLeft");

        tooltip = document.createElement("div");
        tooltip.className = "hn-special-tooltip";
        container.appendChild(tooltip);

        var cached = cache[href];
        if (cached) {
          display(cached);
        } else {
          request = _.request(link.href, "GET", function(page){
            cache[href] = page;
            display(page);
          });
        }
      }, 500);
    };

    link.onmouseout = remove;
  });
});

@@ -527,17 +527,17 @@
      // 
-w
+W
 alk up l
@@ -797,25 +797,25 @@
  %7B%0A      // 
-c
+C
 reate dummy 
@@ -1023,17 +1023,17 @@
 -1); // 
-r
+R
 emove tr
@@ -1125,16 +1125,35 @@
 if (!val
+ %7C%7C val === %22yesno%22
 ) return
@@ -1925,17 +1925,17 @@
      // 
-c
+C
 reate th
@@ -1998,17 +1998,8 @@
 ing%0A
-        %0A
     
@@ -2165,17 +2165,17 @@
      // 
-p
+P
 osition 

exclude selects when hovering over your own profile