var paragraphRotaterHash = new Array();

function ParagraphRotator(parentElementID, delay) {
    this.parentElementID = parentElementID;
    this.currentDisplay = -1;
    this.paragraphCount = 0;
    this.paragraphSelector = "#" + parentElementID + " > p";
    this.delay = 6000;
    if (delay)
        this.delay = eval(delay);
}

ParagraphRotator.prototype.NextRandomParagraph = function() {
    if (this.currentDisplay >= 0) {
        var callback = 'paragraphRotaterHash["' + this.parentElementID + '"].ShowNextParagraph();';
        $(this.paragraphSelector + ":eq(" + this.currentDisplay + ")").slideUp("", function() {eval(callback) });
    }
    else
        this.ShowNextParagraph();

}
ParagraphRotator.prototype.ShowNextParagraph = function() {
    this.currentDisplay = Math.floor(Math.random() * this.paragraphCount);
    $(this.paragraphSelector + ":eq(" + this.currentDisplay + ")").slideDown();
    var callback = 'paragraphRotaterHash["' + this.parentElementID + '"].NextRandomParagraph();';

    setTimeout(callback, this.delay);
}

ParagraphRotator.prototype.Start = function() {
    paragraphRotaterHash[this.parentElementID] = this;
    this.paragraphCount = $("#" + this.parentElementID + " > p").length;
    $("#" + this.parentElementID + " > p").hide();
    $("#" + this.parentElementID).show();
    this.NextRandomParagraph();
}
