/* 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)
** 1.1.0   Added write_and_slide and typewriter behaviors to
**         script.  One can also specify what object will be
**         updated using the setTarget method -- the default
**         is window.status.
*/

// Scroll message from right to left
function scroll_left() {
    if (this.messageBuffer == '') {
        this.messageBuffer = this.message;
    }
    this.messageBuffer = this.messageBuffer.substring(1,this.messageBuffer.length) +
        this.messageBuffer.substring(0,1);
}

// Scroll message from left to right
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);
}

// Write message to screen (a la typewriter) and then slide to left
function write_and_slide() {
    if (this.status == 0) { // First time through the script
        this.status = 1;
    }
    if (this.status == 1) { // Writing message to the buffer
        if (this.messageBuffer.length == this.message.length) {
            this.status = -1;
        } else {
            this.messageBuffer = this.message.substring(0, (this.messageBuffer.length + 1));
        }
    } else { // Sliding message off buffer
        if (this.messageBuffer.length == 1) {
            this.messageBuffer = '';
            this.status = 1;
        } else {
            this.messageBuffer = this.messageBuffer.substring(1, this.messageBuffer.length);
        }
    }
}

// Write message one letter at a time
function typewriter() {
    if (this.messageBuffer == '') {
        this.currentPos = 0;
    }
    if (this.currentPos >= this.message.length) {
        this.messageBuffer = '';
    } else {
        this.currentPos++;
        this.messageBuffer = this.message.substring(0, this.currentPos);
    }
}

// Toggle letters from lower to upper case one letter at a time.
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++;
    }
}

// Called automatically by scroller to update the animation.
function Scroller_update() {
    if (this.doScroll) {
        this.scroll();
        eval(this.target + ' = "' + this.messageBuffer + '"');
    }
    eval('window.setTimeout("' + this.name + '.update()", ' + this.delay + ')');
}

/* Set delay to specific value (in milliseconds).  Delays of less than 0 are
** stored as 0.
*/
function Scroller_setDelay(theDelay) {
    this.delay = theDelay >= 0 ? theDelay : 0;
}

function Scroller_setTarget(theTarget) {
    this.target = theTarget;
}

// Choose scrolling behavior
function Scroller_setScroll(scrollFunction) {
    this.scroll = scrollFunction;
}

// Increase speed of scrolling by 100 milliseconds
function Scroller_faster() {
    this.delay = (this.delay - 100) > 0 ? (this.delay - 100) : 0;
}

// Decrease speed of scrolling by 100 milliseconds
function Scroller_slower() {
    this.delay += 100;
}

// Start scrolling the message
function Scroller_start() {
    this.doScroll = true;
}

// Stop scrolling the message
function Scroller_stop() {
    this.doScroll = false;
}

// Constructor function for Scroller object
function Scroller(uniqueName, theMessage) {
    this.name          = uniqueName;
    this.message       = theMessage;
    this.messageBuffer = '';
    this.target        = 'window.status';
    this.status        = 0;
    
    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;
    this.setTarget = Scroller_setTarget;
}