// JavaScript Document
(function($){
  $.fn.quotator = function(options){
    var container = this;
    var defaults = 
    {
      speed : 5000,
      json : "/testimonials/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);
	var quote ,author;
	quote = "<div id='QuoteInfo'><p>  <i>" + quotesobject[index].quote + "</i></p> <div class='clearHack'></div> "
	author = "<div id='author'>" + quotesobject[index].author + " <br/> " 
			+ quotesobject[index].company  + "</div></div>";  //closing of solutionInfo div also here
    container.html( quote + author);
    
    
    function changeQuote(){
	     if(index == quotesobject.length - 1){
	    index = 0;
		} else{
		 index++;
		}
      container.fadeOut(function(){
	   var  qt, auth;
		qt = "<div id='QuoteInfo'><p> <i>" + quotesobject[index].quote + "</i></p> <div class='clearHack'></div> "
		auth = "<div id='author'>" + quotesobject[index].author + " <br/> " 
			 + quotesobject[index].company  + "</div></div>";
		container.html(qt + auth ).fadeIn();
      });
      
      
    }
	   
  });
  return container;
}
})(jQuery);
