
/*
Script made by Martial Boissonneault © 2001-2002 http://getElementById.com/
This script may be used and changed freely as long as this msg is intact
Visit http://getElementById.com/ for more free scripts and tutorials.
*/
timerID = null;
var active = 0;

var scrollCount = 0;
var scrollGranularity = 10;
var lastScroll = "";
var lastOuter = "";

function ScrollUp(speed,scrollSpeed,outer,inner,posOuter,posInner)
{

    if (lastScroll != "up" || lastOuter != outer)
    {
        lastScroll = "up";
        lastOuter = outer;
        scrollCount = 0;
    }

    obj = document.getElementById(outer).getElementsByTagName("div");

    scrollObj = null;
    if (document.getElementById(posOuter))
    {
        scrollObj = document.getElementById(posOuter).getElementsByTagName("div");
    }

    innerTop = parseInt(obj[inner].style.top);

    posInnerTop = 0;
    if (scrollObj != null)
    {
        posInnerTop = parseInt(scrollObj[posInner].style.top);
    }

    if(document.getElementById)
    {
        if( innerTop < 0)
        {
            obj[inner].style.top = innerTop + speed + "px";
        }

        if ( (scrollObj != null) && posInnerTop > 0)
        {
            ++scrollCount;
            scrollCount = (scrollCount % scrollGranularity);
            scrollDif = ((speed * scrollSpeed * scrollGranularity) %scrollGranularity);

            scrollOffset = Math.floor(speed * scrollSpeed);
            if (scrollCount < scrollDif)
            {
                scrollOffset = Math.ceil(speed * scrollSpeed);
            }

            scrollObj[posInner].style.top = posInnerTop - scrollOffset + "px";


        }


        //timerID = setTimeout("ScrollUp("+speed+"," + scrollSpeed + ",'" + outer + "','" + inner + "','" + posOuter + "','" + posInner + "')",30);


    }
}

function ScrollDown(speed,scrollSpeed,outer,inner,posOuter,posInner)
{
    if (lastScroll != "down" || lastOuter != outer)
    {
        lastScroll = "down";
        lastOuter = outer;
        scrollCount = 100 - scrollCount;
    }


    posOuterObj = document.getElementById(posOuter);
    scrollObj = null;

    if (posOuterObj != null)
    {
        scrollObj = posOuterObj.getElementsByTagName("div");
    }

    posInnerTop = 0;
    if (scrollObj != null)
    {
        posInnerTop = parseInt(scrollObj[posInner].style.top);
    }

    outerObj = document.getElementById(outer);
    obj = outerObj.getElementsByTagName("div");
    objInnerTop = parseInt(obj[inner].style.top);


    if(document.getElementById)
    {

        if( objInnerTop > outerObj.offsetHeight - obj[inner].offsetHeight)
        {
            obj[inner].style.top = objInnerTop - speed + "px";
        }

        if ((scrollObj != null) &&  (posInnerTop < posOuterObj.offsetHeight - scrollObj[posInner].offsetHeight))
        {
            ++scrollCount;
            scrollCount = (scrollCount % scrollGranularity);
            scrollDif = ((speed * scrollSpeed * scrollGranularity) % scrollGranularity);

            scrollOffset = Math.floor(speed * scrollSpeed);
            if (scrollCount < scrollDif)
            {
                scrollOffset = Math.ceil(speed * scrollSpeed);
            }

            scrollObj[posInner].style.top = posInnerTop + scrollOffset + "px";
        }


        //timerID = setTimeout("ScrollDown("+speed+"," + scrollSpeed + ",'" + outer + "','" + inner + "','" + posOuter + "','" + posInner + "')",30);

    }
}

function ScrollStop()
{
    if(document.getElementById)
    {
            clearTimeout(timerID);
    }
}

function ScrollInit(outer,inner,offset)
{
    if(document.getElementById)
    {
        //if ("outer" == "scrollOuter")
            //alert(offset*18);
        obj = document.getElementById(outer).getElementsByTagName("div");
        scrollCount = 0;
            obj[inner].style.top = 0;
            obj[inner].style.top = parseInt(obj[inner].style.top) - (offset*18) + "px";
    }
}

function displayDate(theTime,bShowDate)
{
  var theDate = new Date (theTime * 1000);


  var hours = theDate.getHours();
  var minutes = theDate.getMinutes();

  if (hours < 10){hours= '0' + hours;}
  if (minutes < 10){ minutes = '0' + minutes; }

  if (bShowDate)
  {
      document.write(theDate.toLocaleString());
  }
  else
  {
      document.write(hours + ':' + minutes);
  }
}


function changeVisibility()
{
    theDiv = "feeds";

    d = document.getElementById(theDiv);

    if (d != null)
    {
        if (d.style.visibility == "hidden")
        {
            //alert('making vis');

            d.style.visibility = "visible";
        }
        else
        {
            //alert('making hidden');

            d.style.visibility = "hidden";
        }
    }
}
// Pass an event and return whether or not it was the popup DIV that was clicked
function isClicked(e)
{
    divName = "feeds";

    if (divName != null)
    {
        /*if (this.use_layers)
        {
            var clickX = e.pageX;
            var clickY = e.pageY;
            var t = document.layers[this.divName];
            if ((clickX > t.left) &&
                (clickX < t.left+t.clip.width) &&
                (clickY > t.top) &&
                (clickY < t.top+t.clip.height))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else*/
        if (document.all)
        {
            // Need to hard-code this to trap IE for error-handling
            var t = window.event.srcElement;
            while (t.parentElement != null)
            {
                if (t.id==this.divName)
                {
                    return true;
                }
                t = t.parentElement;
            }
            return false;
        }
        else if(this.use_gebi)
        {

            var t = e.originalTarget;
            while (t.parentNode != null)
            {
                //alert(t.id);
                if (t.id==divName)
                {
                    return true;
                }
                t = t.parentNode;
            }
            return false;
        }


        return false;
    }

    return false;
}

function hidePopup(e)
{
    if (!isClicked(e))
    {
        changeVisibility();
        untrapMouse();
    }
}

function showPopup()
{
    changeVisibility();
    trapMouse();
}

function trapMouse()
{
    if (document.layers)
    {
        document.captureEvents(Event.MOUSEUP);
    }

    window.oldEventListener = document.onmouseup;

    if (window.oldEventListener != null)
    {
        document.onmouseup = new Function("window.oldEventListener(); hidePopup();");
    }
    else
    {
        document.onmouseup = hidePopup;
    }

}

function untrapMouse()
{
    document.onmouseup = window.oldEventListener;
}
