﻿var ancestor, quotes;
var i = 0;

function initQuotes(a, q) {
    ancestor = $(a);
    quotes = $(q);
    Start();
}

function loadQuote() {
    if (quotes.length < 2) {
        $(quotes).show();
    } else if (i < quotes.length) {
        $(quotes).fadeOut("normal");

        $(quotes[i]).fadeIn("normal");
        $(ancestor).height(($(quotes[i]).height()) + 40);

        i++;
        if (i == quotes.length)
            i = 0;
    }
}

function Start() {
    loadQuote();

    // if there is more than one quote
    // run this function every 5 seconds
    if (quotes.length > 1) {
        setTimeout(Start, 5000);
    }
}
