// JavaScript Document
(function($) {

	$.fn.quotator = function(options){
		var container = this;
		var defaults = 
		{
			speed : 4000,
			json : "./quotations.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(quotesobject[index].quote + "<div id='author'>" + quotesobject[index].author + "<br /><a href='/testimonial'>Click here to read more testimonials</a></div>");
			
			function changeQuote(){
				container.fadeTo(600, 0, function(){
					container.html(quotesobject[index].quote + "<div id='author'>" + quotesobject[index].author + "<br /><a href='/testimonial'>Click here to read more testimonials</a></div>").fadeTo(200, 1);
				});
				
				if(index == quotesobject.length - 1){
					index = 0;
				} else{
					index++;
				}
			}
			
		});
		
		return container;
	}
	
})(jQuery);

