// JavaScript Document
(function($){
	$.fn.quotator = function(options){
	var container = this;
	var defaults =
	{
		speed : 15000,
		json : "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(quotesobject[index].quote + "<div id='author'>" + quotesobject[index].author + "</div>");

	container.html(quotesobject[index].quote);
	$("#author").html(quotesobject[index].author).fadeIn();
	$("#location").html(quotesobject[index].location).fadeIn();


	function changeQuote(){


		container.fadeOut(function(){
		//container.html(quotesobject[index].quote + "<div id='author'>" + quotesobject[index].author + "</div>").fadeIn();

		if( index == 0 ){
			document.getElementById('rotation').style.display='none';
			document.getElementById('banner').style.display='block';
		}else{
			document.getElementById('rotation').style.display='block';
			document.getElementById('banner').style.display='none';
		}
		container.html(quotesobject[index].quote).fadeIn();
		$("#author").html(quotesobject[index].author).fadeIn();
		$("#location").html(quotesobject[index].location).fadeIn();

		$("#testimonial-picture").attr('src', '/files/images/testimonial' + index + '.jpg').fadeIn();


		});

		if(index == quotesobject.length - 1){
		index = 0;
		} else{
		index++;
		}
	}

	});
	return container;
}
})(jQuery);
