﻿
function NewsScroller(container, content, pixelsPerSecond, refreshRateMs)
{
    var stepDelayMs = 1000 / refreshRateMs;
    var stepPixels = pixelsPerSecond / stepDelayMs;
    var content = content; 
    var container = container;
    var interval = 0;
    var stopped = false;
    
    var spacerHeight = container.clientHeight;
    
    container.style.overflowY= 'visible';
    var contentHeight = content.clientHeight;
    container.style.overflowY= 'hidden';
    
    var pos = spacerHeight;
        
    this.step = function() {
        if( !stopped )
        {
            if( pos < -(spacerHeight + contentHeight) )
                pos = spacerHeight;
            else
                pos -= stepPixels;
           if( content.style.top != Math.round(pos)+'px' )
                content.style.top = Math.round(pos)+'px';
        }
    }
    this.resume = function() {
        stopped = false;
    }
    this.stop = function() {
        stopped = true;
    }
    
    interval = window.setInterval( this.step, stepDelayMs );
}

var newsScroller;
function newsScroll(containerID, contentID, pixels, delayMs)
{
    var container = document.getElementById(containerID);
    var content = document.getElementById(contentID);  
    newsScroller = new NewsScroller(container, content, pixels, delayMs);
}
function pauseScroll()
{
    newsScroller.stop();
}
function resumeScroll()
{    
    newsScroller.resume();
}
