/*
	Just a Day Quote Ticker
*/

/*			
var quotes = new Array();
quotes[0] = 'I wouldn\'t let Boris Johnson loose with a tin opener!';
quotes[1] = 'Finn! You\'re Alive!';
quotes[2] = 'Tugboats and arson, that\'s all I ever get from you guys!';
*/
var quotes;
// Send the AJAX call to get the quotes:
if(!Prototype.Browser.MobileSafari) {
	new Ajax.Request('/fatcontroller/quoteticker/grabQuotes', {
			method: 'get',
			onSuccess: function(transport){
				quotes = transport.responseText.evalJSON();
				
				if(typeof quotes != 'undefined'){
					if(quotes.length >= 2) {
						jadQuoteTickerStart();
					}
				}
			}
		});
}

var newQuote = '';
var lastQuote = -1;
var randValue = -1;

//
// Grabs a new quote and displays it
//

function jadQuoteTickerRefresh(pe)
{
	// This section is the decision as to which quote is displayed.
	// It should be changed when we use AJAX.
	
	while(randValue == lastQuote)
	{
		randValue = Math.floor(Math.random() * quotes.length);
	}
	
	
	// Stop the executor whilst we're busy:
	pe.stop();
	
	// Fade out the old one and add the new one:
	
	newQuote = quotes[randValue];
	
	Effect.Fade('quote_ticker_content', {
		afterFinish: jadQuoteTickerUpdate
	});
			
}


function jadQuoteTickerUpdate()
{
	if(newQuote != '')
	{
		$('quote_ticker_content').innerHTML = newQuote;
		lastQuote = randValue;
		Effect.Appear('quote_ticker_content', {
			afterFinish: jadQuoteTickerStart
		});
	}
}

function jadQuoteTickerStart()
{
	new PeriodicalExecuter(jadQuoteTickerRefresh, 5);
}

