function ProgramScroller(name, id, maxShown, distance, step, time)
{
    this.name = name;
    this.index = 0;
    this.itemCount = 0;
    this.maxShown = maxShown;
    this.distance = distance;
    this.itemWidth = 0;
    this.scroller = document.getElementById(id);
    this.forward = document.getElementById(id + '_Forward');
    this.back = document.getElementById(id + '_Back');
    this.step = step;
    this.time = time;
    this.isScrolling = false;
    var timer = null;

    this.scrollBack = function()
    {
        if (!this.isScrolling)
        {
            if (this.scroller)
            {
                if (this.index - this.distance > 0)
                {
                    this.index -= this.distance;
                    this.timer = setInterval(this.name + '.doScrollBack("' + this.scroller.id + '", -' + this.index * this.itemWidth + ', ' + this.step + ')', Math.floor(this.time / ((this.index * this.itemWidth) / this.step)));

                    if (this.index <= 0)
                        if (this.back)
                            this.back.className = 'Disabled';
                }
                else
                {
                    this.timer = setInterval(this.name + '.doScrollBack("' + this.scroller.id + '", ' + 0 + ', ' + this.step + ')', Math.floor(this.time / ((this.index * this.itemWidth) / this.step)));
                    this.index = 0;
                    if (this.back)
                        this.back.className = 'Disabled';
                }

                if (this.forward)
                    this.forward.className = '';
            } 
        }
    };

    this.scrollForward = function()
    {
        if (!this.isScrolling)
        {
            if (this.scroller)
            {
                this.index += this.distance;
                if (this.index + this.maxShown < this.itemCount)
                {
                    this.timer = setInterval(this.name + '.doScrollForward("' + this.scroller.id + '", ' + -this.index * this.itemWidth + ', ' + this.step + ')', Math.floor(this.time / ((this.index * this.itemWidth) / this.step)));

                    if (this.index + this.distance == this.itemCount)
                        if (this.forward)
                            this.forward.className = 'Disabled';
                }
                else
                {
                    this.index = this.itemCount - this.maxShown;
                    this.timer = setInterval(this.name + '.doScrollForward("' + this.scroller.id + '", ' + -this.index * this.itemWidth + ', ' + this.step + ')', Math.floor(this.time / ((this.index * this.itemWidth) / this.step)));
                    //this.scroller.style.left = '-' + this.index * this.itemWidth + 'px';
                    if (this.forward)
                        this.forward.className = 'Disabled';
                }

                if (this.back)
                    this.back.className = '';
            }
        }
    };

    if (this.scroller)
    {
        if (this.scroller.children.length > 0)
        {
            this.itemWidth = this.scroller.children[0].offsetWidth;
            for (var i = 0; i < this.scroller.children.length; i++)
            {
                //if (this.scroller.children[i].className.indexOf('ScrollItem') > -1)
                    this.itemCount += 1;
            }
        }
        this.scroller.style.width = this.itemWidth * this.maxShown + 'px';
    }

    this.setStartPosition = function(intIndex)
    {
        this.index = intIndex;
        if (this.itemCount - this.index < 7)
        {
            this.back.className = '';
            this.scroller.style.left = '-' + eval(this.itemWidth * (this.itemCount - 7)) + 'px';
            this.forward.className = 'Disabled';
        }
        else
        {
            this.scroller.style.left = '-' + eval(this.itemWidth * intIndex) + 'px';
            this.back.className = '';
        }
    }

    this.doScrollForward = function(id, target, move)
    {
        var elem = document.getElementById(id);
        if (elem)
        {
            var currentLeft = eval(0 + elem.style.left.replace('px', ''));
            if (currentLeft > target)
            {
                elem.style.left = currentLeft - move + 'px';
                this.isScrolling = true;
            }
            else
            {
                clearInterval(this.timer);
                this.isScrolling = false;
            }
        }
        else
        {
            clearInterval(this.timer);
        }
    }

    this.doScrollBack = function(id, target, move)
    {
        var elem = document.getElementById(id);
        if (elem)
        {
            var currentLeft = eval(0 + elem.style.left.replace('px', ''));
            if (currentLeft < target)
            {
                elem.style.left = currentLeft + move + 'px';
                this.isScrolling = true;
            }
            else
            {
                clearInterval(this.timer);
                this.isScrolling = false;
            }
        }
        else
        {
            clearInterval(this.timer);
        }
    }
}
