  var mActiveDivId = "";
  var mActiveElement = 0;
  var mWidth = 100;
  var mHeight = 100;
  var mYPos = 0;

  function setCycleDimensions (aWidth, aHeight) {
    mWidth = aWidth;
    mHeight = aHeight;
  }

  function cycleElements (aDivId, aType)
  {
    mActiveDivId = aDivId;

    var vDiv = document.getElementById (aDivId);
    var vElements = vDiv.getElementsByTagName ("*");

    for (var vCounter = 0; vCounter < vElements.length; vCounter++)
    {
      var vElement = vElements[vCounter];
      if (aType == 'slide')
      {
        vElement.style.position = "relative";
        vElement.style.visibility = vCounter == mActiveElement ? "visible" : "hidden";
      } else {
        vElement.style.display = vCounter == mActiveElement ? "block" : "none";
      }
    }

    var vActiveElement = vElements[mActiveElement];
    if (aType == "fade") {
      fade ("in", vActiveElement.id, 0);
    } else if (aType == "scale") {
      scale ("in", vActiveElement.id, 0);
    } else if (aType == "slide") {
      slide ("in", vActiveElement.id, -1 * mWidth);
    }

    if (mActiveElement == vElements.length - 1)
    {
      mActiveElement = 0;
    }
    else
    {
      mActiveElement += 1;
    }
  }


  function slide (aInOrOut, aElementId, aXPos)
  {
    var vElement = document.getElementById (aElementId);

    vXPos = aInOrOut == "in" ? aXPos + 4 : aXPos - 4;
    setPosition (aElementId, vXPos, mYPos);

    if (aInOrOut == "in" && vXPos < 0 ||
        aInOrOut == "out" && vXPos > -1 * mWidth)
    {
      window.setTimeout ("slide ('" + aInOrOut + "', '" + aElementId + "', " + vXPos + ")", 50);
    }
    else
    if (aInOrOut == "in" && vXPos >= -1 * mWidth)
    {
      window.setTimeout ("slide ('out', '" + aElementId + "', " + vXPos + ")", 3000);
    }
    else
    if (aInOrOut == "out" && vXPos  <= -1 * mWidth)
    {
      window.setTimeout ("cycleElements ('" + mActiveDivId + "', 'slide')", 50);
    }
  }

  function scale (aInOrOut, aElementId, aWidth)
  {
    var vElement = document.getElementById (aElementId);

    vWidth = aInOrOut == "in" ? aWidth + 4 : aWidth - 4;
    setDimensions (aElementId, vWidth, mHeight);

    if (aInOrOut == "in" && vWidth < mWidth ||
        aInOrOut == "out" && vWidth > 0)
    {
      window.setTimeout ("scale ('" + aInOrOut + "', '" + aElementId + "', " + vWidth + ")", 50);
    }
    else
    if (aInOrOut == "in" && vWidth == mWidth)
    {
      window.setTimeout ("scale ('out', '" + aElementId + "', " + vWidth + ")", 3000);
    }
    else
    if (aInOrOut == "out" && vWidth == 0)
    {
      window.setTimeout ("cycleElements ('" + mActiveDivId + "', 'scale')", 50);
    }
  }

  function fade (aInOrOut, aElementId, aOpacity)
  {
    var vElement = document.getElementById (aElementId);

    vOpacity = aInOrOut == "in" ? aOpacity + 4 : aOpacity - 4;
    setOpacity (aElementId, vOpacity);

    if (aInOrOut == "in" && vOpacity < 100 ||
        aInOrOut == "out" && vOpacity > 0)
    {
      window.setTimeout ("fade ('" + aInOrOut + "', '" + aElementId + "', " + vOpacity + ")", 50);
    }
    else
    if (aInOrOut == "in" && vOpacity == 100)
    {
      window.setTimeout ("fade ('out', '" + aElementId + "', " + vOpacity + ")", 3000);
    }
    else
    if (aInOrOut == "out" && vOpacity == 0)
    {
      window.setTimeout ("cycleElements ('" + mActiveDivId + "', 'fade')", 50);
    }
  }



  function setOpacity (aElementId, aOpacity)
  {
    var vElement = document.getElementById (aElementId);

    if (aOpacity == 100)
    {
      aOpacity = 99.999;
    }

    vElement.style.opacity = aOpacity / 100;
    vElement.style.MozOpacity = aOpacity / 100;
    vElement.style.KHTMLOpacity = aOpacity / 100;
    vElement.style.filter = "alpha (opacity: " + aOpacity + ")";
  }

  function setDimensions (aElementId, aWidth, aHeight)
  {
    var vElement = document.getElementById (aElementId);

    if (aWidth <= 1)
    {
      aWidth = 1;
    }

    if (aHeight <= 1)
    {
      aHeight = 1;
    }
   
    vElement.style.width = aWidth + "px";
    vElement.style.height = aHeight + "px";
  }

  function setPosition (aElementId, aXPos, aYPos)
  {
    var vElement = document.getElementById (aElementId);
    vElement.style.pixelLeft = aXPos;
    vElement.style.pixelTop = aYPos;
  }
