var quotes;
var index;

// Display a quote and queue the next one.
function showQuote() {
	// Get next quote.
	var quote;
	do {
		quote = $.trim(quotes[index]);
		index = (index + 1) % quotes.length;
	} while(!quote.length);
	
	// Prepare quote.
	quote = quote.split("|");
	quote = '&quot;' + quote[0] + '&quot;<div class="meta">' + quote[1] + "</div>";
	
	// Show the new quote.
	$(".quote").fadeOut("slow",function() {
		$(this).html(quote)
			.css({
				top:Math.floor(Math.random() * 180) + 120,
				left:Math.floor(Math.random() * ($(window).width() - 300))
			}).delay(3000)
			.fadeIn("slow");
	});
	visible = true;
	
	// Queue the next quote.
	setTimeout(showQuote,10000);
}

// Entry point.
$(window).load(function() {
	// Load quotes.
	$.get("quotes.txt",function(data) {
		quotes = data.split("\n");
		index = Math.floor(Math.random() * quotes.length);
		setTimeout(showQuote,4000);
	});
});


