

function CListScroller()
{
    this.itemsOuter  = "";
    this.itemsInner  = "";
    this.scrollOuter = "";
    this.scrollInner = "";

    this.itemHeight     = 18;

    this.numItems       = 0;
    this.currentItem    = 0;

    // functions
    this.init           = CListScroller_Init;
    this.scrollUp       = CListScroller_ScrollUp;
    this.scrollDown     = CListScroller_ScrollDown;

    this.objItems  = null;
    this.objScroll = null;
}

function CListScroller_Init(numItems,initialItem,
                            itemsOuter,itemsInner,
                            scrollOuter,scrollInner)
{
    this.itemsOuter  = itemsOuter;
    this.itemsInner  = itemsInner;
    this.scrollOuter = scrollOuter;
    this.scrollInner = scrollInner;

    this.numItems    = numItems;
    this.currentItem = initialItem;

    this.objItemsOuter  = document.getElementById(itemsOuter);
    this.objItemsInner  = document.getElementById(itemsInner);
    this.objScrollOuter = document.getElementById(scrollOuter);
    this.objScrollInner = document.getElementById(scrollInner);

    this.objItemsInner.style.top = 0;
    this.objItemsInner.style.top = parseInt(this.objItemsInner.style.top) - (this.currentItem*this.itemHeight) + "px";

    relativePos = this.currentItem/this.numItems;
    this.objScrollInner.style.top = Math.floor((this.objScrollOuter.offsetHeight-this.objScrollInner.offsetHeight) * relativePos);

}

function CListScroller_ScrollUp(items)
{

    itemsTop = parseInt(this.objItemsInner.style.top);
    scrollTop = parseInt(this.objScrollInner.style.top);

    if(document.getElementById)
    {
        if(this.currentItem > 0)
        {
            if (items > this.currentItem)
            {
                items = this.currentItem;
            }

            this.objItemsInner.style.top = itemsTop + (items * this.itemHeight) + "px";
            this.currentItem -= items;

        }

        relativePos = this.currentItem/this.numItems;
        this.objScrollInner.style.top = Math.floor((this.objScrollOuter.offsetHeight-this.objScrollInner.offsetHeight) * relativePos);


    }
}

function CListScroller_ScrollDown(items)
{


    scrollTop = 0;

    scrollTop = parseInt(this.objScrollInner.style.top);
    itemsTop = parseInt(this.objItemsInner.style.top);

    if(document.getElementById)
    {

        if(this.currentItem < this.numItems)
        {
            if ((this.currentItem + items) > this.numItems)
            {
                items = this.numItems - this.currentItem;
            }

            this.objItemsInner.style.top = itemsTop - (items * this.itemHeight) + "px";
            this.currentItem += items;

            // position the scroll marker

            relativePos = this.currentItem/this.numItems;
            this.objScrollInner.style.top = Math.floor((this.objScrollOuter.offsetHeight - this.objScrollInner.offsetHeight) * relativePos);
        }

    }
}


