// JavaScript Document
(function($){
  $.fn.quotator = function(options){
    var container = this;
    var defaults = 
    {
      speed : 15000,
      json : "/testimonials/index"
    }
    
    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);
    
//    if(quotesobject[index].image != ""){
//    	container.html("<img id='image' src='"+quotesobject[index].image+"' /><div id='besideimage'><div id='author'>" + quotesobject[index].author + "</div>" + quotesobject[index].quote + "</div>");
//    }else{
    	container.html("<div id='author'>" + quotesobject[index].author + "</div>" + quotesobject[index].quote);
//    }
    
    
    function changeQuote(){
      container.fadeOut(function(){
//    	if(quotesobject[index].image != ""){
//    		container.html("<img id='image' src='"+quotesobject[index].image+"' /><div sid='besideimage'><div id='author'>" + quotesobject[index].author + "</div>" + quotesobject[index].quote + "</div>").fadeIn();
//    	}else{
    		container.html("<div id='author'>" + quotesobject[index].author + "</div>" + quotesobject[index].quote).fadeIn();
//    	}
      });
      
      if(index == quotesobject.length - 1){
        index = 0;
      } else{
        index++;
      }
    }
      
  });
  return container;
}
})(jQuery);