﻿var locationIndex = -1;
var currentLocation;

var quoteIndexes = new Array(quoteLocations.length);
var lastQuote = Math.floor(Math.random() * quotes.length);

function setQuote(location, quote, author)
{
	location.innerHTML = "<p class=\"Quote\">&quot;" + quote + "&quot;</p><p class=\"Author\">" + author + "</p>";
}

function getNextQuote()
{
	lastQuote++;
	
	if (lastQuote >= quotes.length)
		lastQuote = 0;
	
	for (var i = 0; i < quoteIndexes.length; i++)
	{
		if (lastQuote== quoteIndexes[i])
		{
			return getNextQuote();
		}
	}
	return lastQuote;
}

function changeRandomLocation()
{
	var newlocationIndex;
	do { newlocationIndex = Math.floor(Math.random() * quoteLocations.length) }
	while (newlocationIndex == locationIndex);
	locationIndex = newlocationIndex;
	currentLocation = quoteLocations[locationIndex];
	quoteIndexes[locationIndex] = getNextQuote();
	setTimeout("currentLocation.style.color=\"#38342E\";", 50);
	setTimeout("currentLocation.style.color=\"#4D4233\";", 100);
	setTimeout("currentLocation.style.color=\"#635136\";", 150);
	setTimeout("currentLocation.style.color=\"#7D6036\";", 200);
	setTimeout("currentLocation.style.color=\"#997033\";", 250);
	setTimeout("currentLocation.style.color=\"#CC8F33\";", 300);
	setTimeout("currentLocation.style.color=\"#DD9D3C\";", 350);
	setTimeout("currentLocation.style.color=\"#EBAA47\";", 400);
	setTimeout("currentLocation.style.color=\"#F6B655\";", 450);
	setTimeout("currentLocation.style.visibility=\"hidden\";", 500);
	setTimeout("setQuote(currentLocation, \"" + quotes[quoteIndexes[locationIndex]][0] + "\", \"" + quotes[quoteIndexes[locationIndex]][1] + "\");", 600);
	setTimeout("currentLocation.style.visibility=\"visible\";", 800);
	setTimeout("currentLocation.style.color=\"#EBAA47\";", 850);
	setTimeout("currentLocation.style.color=\"#DD9D3C\";", 900);
	setTimeout("currentLocation.style.color=\"#CC8F33\";", 950);
	setTimeout("currentLocation.style.color=\"#997033\";", 1000);
	setTimeout("currentLocation.style.color=\"#7D6036\";", 1050);
	setTimeout("currentLocation.style.color=\"#635136\";", 1100);
	setTimeout("currentLocation.style.color=\"#4D4233\";", 1150);
	setTimeout("currentLocation.style.color=\"#38342E\";", 1200);
	setTimeout("currentLocation.style.color=\"#262626\";", 1250);
}

if (quotes.length > quoteLocations.length)
{
	for (var i = 0; i < quoteLocations.length; i++)
	{
		quoteIndexes[i] = getNextQuote();
		setQuote(quoteLocations[i], quotes[quoteIndexes[i]][0], quotes[quoteIndexes[i]][1]);
	}
	setInterval("changeRandomLocation()", interval);
}

