$(function() {
	
	var quotes = [], interval, count=0, maxHeight = 0;
	
	// returns a random integer between l and h inclusively
	function randInt(l, h) {
		return Math.floor(Math.random() * (h - l + 1)) + l;
	}

	// Consumes an array and returns an array with the same elements but in a random order
	function shuffleArray(a1) {
		var a2 = [];
		for (var i = a1.length; i > 0; i--) {
			a2.push(a1.splice(randInt(0, i-1), 1)[0])		
		}
		return a2;
	}
	
	$("#quotes .quote").each(function() {
		quotes.push($(this));
		maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
	});
	quotes = shuffleArray(quotes);
	
	function fadeToNextQuote() {
		quotes[count].fadeOut(1000);
		count = (count == quotes.length - 1) ? 0 : count + 1;
		quotes[count].fadeIn(1000);
	}
	
	$("#quotes").height(maxHeight);
	quotes[count].show().parent().height(quotes[count].height);
	interval = setInterval(fadeToNextQuote, 8000);

});
