/*

  quoteCycle
  ----------
  Cycles quotes in the following format:

  <div id="myQuote">
    <div class="quote">The quote goes here</div>
    <div class="quote-from">The author of the quote</div>
  </div>

  EXAMPLE
  -------

  $("#myQuote").quoteCycle();

*/

jQuery.fn.quoteCycle = function() {

    var doFade = function(elem) {

        var quote = elem.find(".quote");
        var quoteFrom = elem.find(".quote-from");

        // the next quote to show
        // it's either the next in line, or the first in the queue
        // figure out what this is now, to pass through to the next call
        var quoteNext = (elem.next().length > 0 ? elem.next() :
            elem.parent().find(".testimonial:first"));

        quote.fadeIn(function() {
            quoteFrom.fadeIn(function() {

                // wait 5 seconds and fade everthing out
                setTimeout(function() {

                    quote.fadeOut();
                    quoteFrom.fadeOut(function() {

                        // call ourself with the next quote to show
                        doFade(quoteNext);

                    });

                }, 5000);

            });

        });


    };

    doFade(this);
    
    return this;
    
};
