var timer; //timer variable
var timerIsSet = true;

var maxScrollLeft = 590;

/* Update these values to change speed of scroller. */
var positionInterval = 5; //scrolling interval
var timerInterval = 90; //clock timer interval

/* Delay before next text. */
var newTextDelay = 5000;

var scrollTexts = new Array();
scrollTexts[0]="<span class='disc'></span>2010 Florida Conference on Aging / Better Together: Life After 55</li>";
scrollTexts[1]="<span class='disc'></span>August 16-18, 2010 at the Caribe Royale Hotel in Orlando";
scrollTexts[2]="<span class='disc'></span>Call (850) 222-8877 for more information or go to <a href='http://http://www.fcoa.org' style='color:white' target='_blank'>www.fcoa.org</a>";
scrollTexts[3]="<span class='disc'></span>For reservations call 1-800-823-8300";
scrollTexts[4]="<span class='disc'></span>Please see ''Upcoming Events'' for August in the calendar";

currentTextIndex = 0;

var scrollContainerObject;
var scrollTextObject;

function initializeScroll (varScrollContainerObject, varScrollTextObject)
{
	/* Initialize the settings. */
    scrollContainerObject = varScrollContainerObject;
	scrollTextObject = varScrollTextObject;

	/* Let the fun begin. */
	scrollNewText ();
}

function scrollNewText ()
{
	/* Scroll back to the left so that the text is hidden. */
	scrollContainerObject.scrollLeft = 0;

	/* Load the text. */
	scrollTextObject.innerHTML = scrollTexts[currentTextIndex];
	
	/* Prepare for the next text loading. */
	currentTextIndex++;
	currentTextIndex = currentTextIndex % scrollTexts.length;
	
	/* Start the scrolling. */
	timedScrollRight();
}

function timedScrollRight()
{
    /* If we can still scroll a full interval then: */
    if ((scrollContainerObject.scrollLeft + positionInterval) <= maxScrollLeft)
    {
        /* Scroll one interval. */
        scrollContainerObject.scrollLeft += positionInterval;
        
        /* Continue scrolling (scrolling will terminate when we reach the end or timer is killed. */
        timer=setTimeout("timedScrollRight()",timerInterval);
        timerIsSet=true;
    }
    /* Otherwise: */
    else
    {
        /* At least go all the way. */
        if (scrollContainerObject.scrollLeft < maxScrollLeft)
        {
            scrollContainerObject.scrollLeft = maxScrollLeft;
        }
        /* No need to continue scrolling. */
        killTimer();
		
		/* Load and scroll in the next text after a delay. */
		timer=setTimeout("scrollNewText()", newTextDelay);
    }         
}

function killTimer()
{
    if (timerIsSet=true)
    {
        clearTimeout(timer);
        timerIsSet=false;
    }
}