
function StartQuoteBox()
{	
	var URL = "/utils/general/QuoteBox.aspx?element=quote";

	doAjaxJSON(
		URL,
		null,
		InitiateQuoteScroll, 
		null);			
}

function InitiateQuoteScroll(html)
{
	SetContent(html, "quote-js-array");
	UpdateQuoteBox();
	var i=0;
	var delay = 7500;
	while(i<40)
	{	
		setTimeout ("FadeOut()",			delay*i - 200);
		setTimeout ("UpdateQuoteBox()",	    delay*i);
		setTimeout ("FadeIn()",				delay*i + 10);
		i++;
	}
}

var lastPersonIndex = 0;

function UpdateQuoteBox()
{	
	var personsArray = GetQuoteData();
	
	if(personsArray != null)
	{
	    /** Get next persons index, not same as last person */
	    var rowNo = Math.floor(Math.random() * (personsArray.length));
	    if(rowNo == lastPersonIndex)
		    rowNo = rowNo + 1 % (personsArray.length);	
	    lastPersonIndex = rowNo;
    	
    	if(personsArray[rowNo])
    	{
	        var html = GetQuoteHTML(personsArray[rowNo][0], personsArray[rowNo][1], personsArray[rowNo][2], personsArray[rowNo][3]);
        	
	        $("quote-container").set("html", html);
	    }
	}
}

function GetQuoteData()
{	
	var peopleString = $("quote-js-array").innerHTML;
	
	if(peopleString == "")
	    return null;
	
	var peopleArray = new Array();
	peopleArray = peopleString.split("|");
	var people = new Array();
	
	for(row = 0; row < peopleArray.length; ++row)
	{
		people[row] = peopleArray[row].split("^");
	}
	
	return people;
}

function GetQuoteHTML(title, linkURL, imageURL, quote)
{
	return "<div id='quote-start'>"
			+ "<img src='/images/units/quotebox/quote-start.gif' />"
		+ "</div>"
		+ "<div id='quote'>"
			+ quote
			+ "<img src='/images/units/quotebox/quote-end.gif' style='margin: 0 0 -8px 3px;' />"
			+ "<br /><a href='" + linkURL + "'>&raquo; " + title + "</a>"
		+ "</div>"
		+ "<img src='" + imageURL + "' style='margin-top:-110px;margin-left:330px' />";
}

function FadeOut()
{
	$("quote-container").fade('0');
}

function FadeIn()
{
	$("quote-container").fade('1');	
}
