// JavaScript Document
(function($){
  $.fn.quotator = function(options){
    var container = this;
    var defaults = 
    {
      speed : 5000,
      json : "js/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 = 0;
    
    
    setInterval(changeQuote, options.speed);
    
    container.html("<blockquote><div id='quote'>" + quotesobject[index].quote + "<span style='position: relative; top: 2px;'><img src='images/quote_close.gif' alt='' height='9' width='10'></span></div><div id='top'>" + quotesobject[index].top + "</div><div id='author'>" + quotesobject[index].author + "</div><div id='date'>" + quotesobject[index].date + "</div></blockquote>");
    
    
    function changeQuote(){
      container.fadeOut(function(){
        container.html("<blockquote><div id='quote'>" + quotesobject[index].quote + "<span style='position: relative; top: 2px;'><img src='images/quote_close.gif' alt='' height='9' width='10'></span></div><div id='top'>" + quotesobject[index].top + "</div><div id='author'>" + quotesobject[index].author + "</div><div id='date'>" + quotesobject[index].date + "</div></blockquote>").fadeIn();
      });
      
      if(index == quotesobject.length - 1){
        index = 0;
      } else{
        index++;
      }
    }
      
  });
  return container;
}
})(jQuery);