// JavaScript Document
(function($){
  $.fn.quotator = function(options){
    var container = this;
    var defaults = 
    {
      speed : 5000,
      json : "quotator_quotes.js"
    }
    var options = $.extend(defaults, options);
    var quotes_json = options.json;
    var quotes;
    $.getJSON(quotes_json, function(data){
    var quotesobject = eval(data.quotes);
    var index = Math.floor(Math.random()*(quotesobject.length - 1));
    setInterval(changeQuote, options.speed);
    container.html("<img src='images/left_quote.jpg'>" + quotesobject[index].quote + "<img src='images/right_quote.jpg' align='top'>" + "<div id='author'>" + quotesobject[index].author + "</div>");
    function changeQuote(){
      container.fadeOut(function(){
        container.html("<img src='images/left_quote.jpg'>" + quotesobject[index].quote +  "<img src='images/right_quote.jpg' align='top'>" + "<div id='author'>" + quotesobject[index].author + "</div>").fadeIn();
      });
      if(index == quotesobject.length - 1){
        index = 0;
      } else{
        index++;
      }
    }
      
  });
  return container;
}
})(jQuery);
