

// POPBOX - Functions for the dead simple pop-up box for elist signup.
// (C) 2005 Panic, Inc. / Cabel Sasser

function togglePopBox() {

  pophost = document.getElementById("PopHost");
  popbox = document.getElementById("PopBox");

  if (popbox.style.visibility == "hidden" || popbox.style.visibility == "") {

    // Find the location of where we should position the pop-up box
    // "PopHost" is the document element near where the pop-up box should appear

    var pophostY = 0;
    var pophostX = 0;
    var count = 0;
    var pophostFind = pophost;

    // Iterate through the target item's many potential parents to calculate position X and Y values

    do {
      pophostY += pophostFind.offsetTop;
      pophostX += pophostFind.offsetLeft;
    } while ( pophostFind = pophostFind.offsetParent )

    // Now position the pop-up box. I swear, lord, that I tried to do this dynamically, but it 
    // wasn't as easy as it seems. NOTE: If PopBox gets resized, this must change as well.

 //   popbox.style.left = pophostX - 25;
   // popbox.style.top = pophostY + 38;

      popbox.style.left = pophostX - 0;
      popbox.style.top = pophostY + 0;

//     popbox.style.left = pophostX - (popbox.offsetWidth / 2.5);
//     popbox.style.top = pophostY + (pophost.offsetHeight);

    // DON'T ASK. Workaround for Firefox Flicker Pain. First set of 100 = brief dissapearing.

    if (navigator.userAgent.indexOf("Firefox") != -1) {
      setOpacity(99.999, "PopBox");
    }
 
    // Now make the box visible (fade in?)

    popbox.style.visibility = "visible";

  } else {
    popbox = document.getElementById("PopBox");
    // Fade out the box quickly
    fadeElementSetup("PopBox", 100, 0, 10);
  }
}

// FADE (OUT) ITEM function
//
// NOTE: Slightly different than the more flexible "mininfo" code; this will hide the layer
// when finished and set the opacity back up to 100, so it's really intended
// only for fading an item out.
//
// Pass opacity values from 1 - 100.

function fadeElementSetup(theID, fdStart, fdEnd, fdSteps) {
  fadeSteps = fdSteps;
  fadeCurrent = 0;
  fadeAmount = (fdStart - fdEnd) / fadeSteps;
  fadeTimer = setInterval("fadeElement('"+theID+"')", 50);
}

function fadeElement(theID) {
  fadeCurrent++;
  // Set the opacity depending on if we're adding or subtracting (pos or neg)
  if (fadeAmount < 0) {
    setOpacity(Math.abs(fadeCurrent * fadeAmount), theID);
  } else {
    setOpacity(100 - (fadeCurrent * fadeAmount), theID);
  }
  if (fadeCurrent == fadeSteps) {
    // We're done, so clear
    clearInterval(fadeTimer);
    document.getElementById(theID).style.visibility = "hidden";
    setOpacity(100, theID);
  }
}

function setOpacity(opacity, theID) {

  // Multi-browser opacity setting
  var object = document.getElementById(theID).style;
  object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win
  object.KhtmlOpacity = (opacity / 100);            // Safari 1.1 or lower, Konqueror
  object.MozOpacity = (opacity / 100);              // Older Mozilla+Firefox
  object.opacity = (opacity / 100);                 // Safari 1.2, Firefox+Mozilla
}
