// JavaScript Document
(function($){
  $.fn.quotator = function(options){
    var container = this;
    var defaults = 
    {
      speed : 5000,
      json : "quotator_quotes.js",
		fadeinspeed: 1000,
		fadeoutspeed: 1000
    }
    
    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(quotesobject[index].quote + "<div id='author'>" + quotesobject[index].author + "</div>");


// changeQuote doesn't get called until the first "speed" interval is up
// but then it is called again "speed" interval later, but during that time the fade in and out happen
// so there is an initial lag before the changeQuote kicks in
// to counteract that I put in a literal call to changeQuote first
// and took out the initial load of the quote box
//have backed out of that
// I added the if ($.browser.msie) this.style.removeAttribute('filter) line as ie7 has probs with losing cleartype

//	changeQuote();
    

    function changeQuote(){
      container.fadeOut(options.fadeoutspeed, function(){
        container.html(quotesobject[index].quote + "<div id='author'>" + quotesobject[index].author + "</div>").fadeIn(options.fadeinspeed, 
			function(){if ($.browser.msie) this.style.removeAttribute('filter');
			});
      });
      

      if(index == quotesobject.length - 1){
        index = 0;
      } else{
        index++;
      }
    }
      
  });
  return container;
}
})(jQuery);