/**
 * Scroller
 * 
 * Repeatedly scrolls the content of a given unordered list (right to left)
 * 
 * Each li is treated as a separate message
 * 
 * @param string listId The id of the list whose content to scroll
 * @param string objectName The name we assign to this object
 * @param int speed The speed of the scroller
 */
function scroller(listId, objectName, speed)
{
    // Find what browser and version we're using
    var browserVersion = navigator.appVersion;
    
    // Only proceed if this isn't IE6
    if (browserVersion.search("MSIE 6") == -1) {
        // Fetch parameters into local variables
        this.listId = listId;
        this.objectName = objectName;
        this.speed = speed;
        
        // Fetch the container element
        this.container = document.getElementById(this.listId);
        
        // Make sure an element was found
        if (this.container == null) {
            // No element found, return
            return;
        }
        
        // Find the container's width
        this.containerWidth = this.container.offsetWidth;
        
        // Change the container's styling
        this.container.style.whiteSpace = 'nowrap';
        this.container.style.overflow = 'hidden';
        
        // Fetch the list items
        this.items = this.container.getElementsByTagName('li');
        
        // Start with empty content
        this.content = '';
        
        // Find out how many items we have
        count = this.items.length;
        
        // Run through each list item
        for (var i = 0; i < count; i++) {
            // Fetch this item's content
            message = this.items[i].innerHTML;
            
            // Build the html for this item
            if (i == 0) { // First item
                html = '<li style="display: inline; padding-right: ' + this.containerWidth + 'px; padding-left: ' + this.containerWidth + 'px;">' + message + '</li>';
            } else { // All other items
                html = '<li style="display: inline; padding-right: ' + this.containerWidth + 'px;">' + message + '</li>';
            }
            
            // Add this html to the content
            this.content += html;
        }
        
        // Put the content into the container
        this.container.innerHTML = this.content;
        
        // Scroll the container all the way to the left
        this.container.scrollLeft = 0;
        
        // Function to scroll the content
        this.scroll = function()
        {
            // Scroll the contents
            this.container.scrollLeft += speed;
            
            // If we've reached the end
            if (this.container.scrollLeft >= this.container.scrollWidth - this.containerWidth) {
                // Move back to the start
                this.container.scrollLeft = 0;
            }
            
            // Repeat
            setTimeout(this.objectName + '.scroll()', 30);
        }
        
        // Start the scroller
        this.scroll();
    }
}
