var quotes;
function fadeQuote(inQuotes, index) 
{
	quotes = inQuotes;
	nextQuote(index);
}

function nextQuote(index) 
{
	var values = getNextQuote(index);
	var quote = values[1];
	var indexOfPunct = getFirstPunctuationIndex(quote);
	var phrase1 = quote.substr(0, indexOfPunct + 1);
	var phrase2 = quote.substr(indexOfPunct + 1, quote.length - (indexOfPunct + 1));

	jQuery("#quoteText").html(phrase1);
	jQuery("#quoteText").fadeTo(2500, 1, function() 
	{
		var div = jQuery("<div />");
		div.hide();
		div.html(phrase2);
		jQuery("#quoteText").append(div);
		div.slideDown(500, function() 
		{
			fadeQuoteHelper(values[0]);
		});
	});
}

function getNextQuote(index) 
{
	if (index == null)
		index = 0;

	var length = quotes.length;

	if (index < length - 1)
		index++;
	else
		index = 0;

	var quote = quotes[index];

	return [index, quote];
}

function getFirstPunctuationIndex(str) 
{
	if (str == null)
		return;
	var indexOfPeriod = str.indexOf('.');
	var indexOfExclamationPoint = str.indexOf('!');
	var indexOfAmpersand = str.indexOf('&');

	if (indexOfPeriod > -1) 
	{
		if (indexOfExclamationPoint == -1) 
		{
			return indexOfPeriod;
		}
		else if (indexOfPeriod <= indexOfExclamationPoint) 
		{
			return indexOfPeriod;
		}
		else 
		{
			return indexOfExclamationPoint;
		}
	}
	else if (indexOfExclamationPoint > -1) 
	{
		return indexOfExclamationPoint;
	}
	return str.length - 1;
}

function fadeQuoteHelper(index) 
{
	jQuery("#quoteText").fadeTo(1000, 0.99, function() 
	{
		jQuery("#quoteText").fadeTo(1500, 0.1, function() 
		{
			nextQuote(index);
		});
	});

}




