/* JSScroller
** Copyright (c) 1999 Christopher D. Doemel
**
** Permission to use and modify this script is granted, so long as
** the above copyright is maintained, any modifications are
** documented, and credit is given for use of the script.
**
** Version 1.0.0, February 1999
**
** 1.0.0   Initial release (08 Feb 1999)
*/

function scroll_left() {
    if (this.messageBuffer == '') {
        this.messageBuffer = this.message;
    }
    this.messageBuffer = this.messageBuffer.substring(1,this.messageBuffer.length) +
        this.messageBuffer.substring(0,1);
}

function scroll_right() {
    if (this.messageBuffer == '') {
        this.messageBuffer = this.message;
    }
    this.messageBuffer = this.messageBuffer.substring(this.messageBuffer.length - 1,
        this.messageBuffer.length) + this.messageBuffer.substring(0,this.messageBuffer.length - 1);
}

function scroll_caps() {
    if (this.messageBuffer == '') {
        this.currentPos = 0;
    }
    if (this.currentPos == 0) {
        this.messageBuffer = this.message.charAt(0).toUpperCase() +
            this.message.substring(1,this.message.length).toLowerCase();
            this.currentPos++;
    } else if (this.currentPos == this.message.length) {
        this.messageBuffer = this.message.substring(0, this.message.length - 1).toLowerCase() +
            this.message.charAt(this.message.length).toUpperCase();
            this.currentPos = 0;
    } else {
        this.messageBuffer = this.message.substring(0, this.currentPos).toLowerCase() +
            this.message.charAt(this.currentPos).toUpperCase() +
            this.message.substring(this.currentPos + 1, this.message.length).toLowerCase();
            this.currentPos++;
    }
}

function Scroller_update() {
    if (this.doScroll) {
        this.scroll();
        window.status = this.messageBuffer;
    }
    eval('window.setTimeout("' + this.name + '.update()", ' + this.delay + ')');
}

function Scroller_setDelay(theDelay) {
    this.delay = theDelay >= 0 ? theDelay : 0;
}

function Scroller_setScroll(scrollFunction) {
    this.scroll = scrollFunction;
}

function Scroller_faster() {
    this.delay = (this.delay - 100) > 0 ? (this.delay - 100) : 0;
}

function Scroller_slower() {
    this.delay += 100;
}

function Scroller_start() {
    this.doScroll = true;
}

function Scroller_stop() {
    this.doScroll = false;
}

function Scroller(uniqueName, theMessage) {
    this.name          = uniqueName;
    this.message       = theMessage;
    this.messageBuffer = '';
    
    this.delay  = 500;
    this.scroll = scroll_left;
    this.doScroll = true;
    
    this.update    = Scroller_update;
    this.faster    = Scroller_faster;
    this.slower    = Scroller_slower;
    this.start     = Scroller_start;
    this.stop      = Scroller_stop;
    this.setDelay  = Scroller_setDelay;
    this.setScroll = Scroller_setScroll;
}
