quoterotator.col = [];

function quoterotator(quoteid, quoteauthorid, speed) {
    this.quoteid = quoteid;
    this.quoteauthorid = quoteauthorid;
    this.speed = speed || 4500;
    this.ctr = 0;
    this.timer = 0;
    this.quotes = [];
    this.quoteAuthors = [];
    this.index = quoterotator.col.length;
    quoterotator.col[this.index] = this;
    this.animString = "quoterotator.col[" + this.index + "]";
};

quoterotator.prototype.addQuotes = function() {
    var lbl;
    for (var i = 0; arguments[i]; i++) {
        lbl = new String(arguments[i]);
        this.quotes[this.quotes.length] = lbl;
    }
};

quoterotator.prototype.addQuoteAuthors = function() {
    var lbl;
    for (var i = 0; arguments[i]; i++) {
        lbl = new String(arguments[i]);
        this.quoteAuthors[this.quoteAuthors.length] = lbl;
    }
};

quoterotator.prototype.rotate = function() {
    clearTimeout(this.timer);
    this.timer = null;
    if (this.ctr < this.quotes.length - 1)
        this.ctr++;
    else this.ctr = 0;
    var quoteObj = document.getElementById(this.quoteid);
    if (quoteObj) {
        quoteObj.innerHTML = this.quotes[this.ctr];
        this.timer = setTimeout(this.animString + ".rotate()", this.speed);
    }
    var quoteauthorObj = document.getElementById(this.quoteauthorid);
    if (quoteauthorObj)
        quoteauthorObj.innerHTML = this.quoteAuthors[this.ctr];
};

quoterotator.start = function() {
var len = quoterotator.col.length, obj;
    for (var i = 0; i < len; i++) {
        obj = quoterotator.col[i];
        if (obj && obj.quoteid)
            obj.timer = setTimeout(obj.animString + ".rotate()", obj.speed);
    }
};

