box = null;

function findPosY(obj) {
   var curtop = 0;
   if (obj.offsetParent) {
      while (obj.offsetParent) {
         curtop += obj.offsetTop;
         obj = obj.offsetParent;
      }
   }
   else if (obj.y)
      curtop = obj.y;
   return curtop;
}

function findPosX(obj) {
   var curleft = 0;
   if (obj.offsetParent) {
      while (obj.offsetParent) {
         curleft += obj.offsetLeft;
         obj = obj.offsetParent;
      }
   }
   else if (obj.y)
      curleft = obj.y;
   return curleft;
}

function addOnmouseoverForImg(elem, id) {
  elem.onmouseover = function() {
    show(id);
  }
}

window.onload = function() {
  $("loadinfo").parentNode.removeChild($("loadinfo"));
  
  $("columns").style.marginRight = "14em";
  
  var ps = document.getElementsByTagName("dl");
  for (var i = 0; i < ps.length; i++) {
    var clazz = ps[i].getAttribute("class");
    if (clazz == null) { // internet explorer...
      clazz = ps[i].getAttribute("className");
    }
    if (clazz == "info") {
      ps[i].style.display = "none";
    }
  }
  
  var imgs = document.getElementsByTagName("img");
  var width_set = false;
  for (var i = 0; i < imgs.length; i++) {
    var clazz = imgs[i].getAttribute("class");
    if (clazz == null) { // crappy IE
      clazz = imgs[i].getAttribute("className");
    }
    if (clazz == "infoimg") {
      // closures
      addOnmouseoverForImg(imgs[i], imgs[i].nextSibling.getAttribute("id"));
      if (!width_set) {
        // have to set width for IE6
        width_set = true;
        show(imgs[i].nextSibling.getAttribute("id"));
        $("columns").style.width = (968 -
                                    imgs[i].nextSibling.clientWidth) + "px";
        imgs[i].nextSibling.style.display = "none";
        box = null;
      }
    }
  }
  
  window.onscroll = function() { reshow(); }
}

// uses global box
function reshow() {
  if (box != null) {
    var offset = document.documentElement.scrollTop - findPosY($("top"));
    if ($("creepslist") != null) {
      offset += 100;
    }
    if (offset < 0) {
      offset = 0;
    }
    
    
    var top = offset + findPosY($("top")) + 90;
    
    if (top + box.clientHeight > findPosY($("footer"))) {
      top -= ((top + box.clientHeight) - findPosY($("footer")) + 20)
    }
    
    box.style.top = top + "px";
  }
}

// uses global box
function show(sum) {
  if (box != null) {
    box.style.display = "none";
  }
  
  box = $(sum);
  box.style.position = "absolute";
  box.style.right = "0px";
  box.style.top = "-3000px"; // avoid flickering
  box.style.left = (findPosX($("columns")) + $("columns").offsetWidth) + "px";
  box.style.display = "block";
  reshow();
}


