
$(function() {
  getQuotes();
});

var quotes;
var index = 0;
  
function getQuotes() 
{
  $.getJSON('quotes.txt', null, 
    function(res) { 
      window.quotes = res.quotes;
      index = Math.round(Math.random() * quotes.length);
      setNextQuote();          
      setInterval(setNextQuote, res.settings.cycleTime*1000);
    }
  ); 
}

function setNextQuote() {
  if (index >= quotes.length) index = 0;

  var quote = quotes[index++]; 
  $('#quote_text').text(quote.text);
  $('#quote_author').text("- " + quote.author);
}

