function AutoScrollBox(placeholderId, contentId)
{
    var hndlTimer = null;
    var interval = 0;
    var container = document.getElementById(placeholderId);
    var content = document.getElementById(contentId);
    var self = this;
    var top = 0;
    
    init();
    
    function roll()
	{
	    var frames = content.getElementsByTagName('div');
	    
	    if (Math.abs(top) >= frames[0].offsetHeight) {
	        top += frames[0].offsetHeight;
	    } else {
	       top -= 1;
	    }
	    content.style.top = top + 'px';
	}

    function init()
	{
	    top = content.offsetTop;

	    container.onmouseover = function() { self.stop(); }
	    container.onmouseout = function() { if (interval > 0) self.start(interval); }
	    
	    var contentHeight = content.offsetHeight;
	    var nodes = content.getElementsByTagName('p');

	    var frame = document.createElement('div');
	    frame.style.paddingBottom = '20px';
	    while (nodes.length > 0) {
	        frame.appendChild(nodes[0]);
	    }
	    content.appendChild(frame);
	    
	    do {
	        content.appendChild(frame.cloneNode(true));
	    } while (content.offsetHeight - container.offsetHeight < contentHeight);
	}
	
	this.startDelayed = function(intvl, delay)
	{
	    window.setTimeout(function() { self.start(intvl); }, delay);
	}
	
	this.start = function(milliseconds)
	{
	    if (hndlTimer == null) {
	        interval = milliseconds;
	        hndlTimer = window.setInterval(roll, interval);
	    } else {
	       throw "Already started";
	    }
	}
	
	this.stop = function()
	{
	    if (hndlTimer != null) {
	        window.clearInterval(hndlTimer);
	        hndlTimer = null;
	    }
	}
}

function SlideBox(containerId, height)
{
    var container = null;
    var slider = null;
    var self = this;
    var step = 5;
    var hndlTimer = null;
    var btnUp = null;
    var btnDown = null;
    
    init();
    
    function init()
    {
        var box = document.getElementById(containerId);
        
        container = document.createElement('div');
        container.style.position = 'relative';
        container.style.overflow = 'hidden';

        slider = document.createElement('div');
        slider.style.position = 'absolute';
        slider.top = 0;
        
        while (box.childNodes.length > 0) {
            slider.appendChild(box.childNodes[0]);
        }
        container.appendChild(slider);
        box.appendChild(container);
        
        slider.style.width = container.offsetWidth + 'px';
        
        if (height < slider.offsetHeight) {
            container.style.height = height + 'px';
            
            btnUp = createButton('up', 'buttonUp disabled', 1);
            box.insertBefore(btnUp, container);
            
            btnDown = createButton('down', 'buttonDown', -1);
            box.appendChild(btnDown);
            
            container.style.height = (height - btnUp.offsetHeight - btnDown.offsetHeight) + 'px';
        } else {
            container.style.height = slider.offsetHeight + 'px';
        }
    }
    
    function roll()
    {
        var ns = nextStep();
        if (step != ns) {
            self.stop();
            if (step > 0) {
                btnUp.className = 'buttonUp disabled';
            } else {
                btnDown.className = 'buttonDown disabled';
            }
        } else {
            btnDown.className = 'buttonDown';
            btnUp.className = 'buttonUp';
        }

        slider.top += ns;
        slider.style.top = slider.top + 'px';
    }
    
    function nextStep()
    {
        if (step > 0) {
            return Math.min(step, Math.abs(slider.top));
        } else {
            return Math.max(step, -Math.abs(container.offsetHeight - slider.offsetHeight - slider.top));
        }
    }
    
    function createButton(caption, className, direction)
    {
        var btn = document.createElement('a');
        btn.href='javascript:void(0)';
        btn.onmousedown = function() { self.start(direction); }
        btn.onmouseup = function() { self.stop(); }
        btn.className = className;
        btn.appendChild(document.createTextNode(caption));
        
        return btn;
    }

    this.start = function(direction)
    {
        step = direction * Math.abs(step);
        if (hndlTimer == null) {
            hndlTimer = window.setInterval(roll, 100);
        }
    }
    
    this.stop = function()
    {
        if (hndlTimer != null) {
            window.clearInterval(hndlTimer);
            hndlTimer = null;
        }
    }
}        