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 = 300;

var scrollTexts = new Array(); 
scrollTexts[0]="<span class='disc'></span>2011 Florida Conference on Aging: Through a New Lens";
scrollTexts[1]="<span class='disc'></span>August 22-24, 2011";
scrollTexts[2]="<span class='disc'></span>Trade Winds Grand, St. Pete Beach, FL";
scrollTexts[3]="<span class='disc'></span>Call (850) 222-8877 for more information or visit www.fcoa.org";
scrollTexts[4]="<span class='disc'></span>For reservations call 1-800-808-9833";

//UNCOMMENT NEXT LINE TO RUN
//currentTextIndex = 0;

var scrollContainerObject;
var scrollTextObject;

function initializeScroll (varScrollContainerObject, varScrollTextObject)
{
	/* Initialize the settings. */
    scrollContainerObject = varScrollContainerObject;
	scrollTextObject = varScrollTextObject;

	/* Let the fun begin. */
	// Un-comment the line below to enable the scroller or comment to hide //
	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;
    }
}
