// Simple JavaScript Scroller
//
//  2003.10.24. Version 0.20. Grk
//              Initial version, does not work on Netscape, tested on Internet
//              Explorer only.
//  2003.10.31. Version 0.21. Grk
//              Bugfix, tested on Opera and works fine. Does not work on
//              Netscape 7
//
// Copyright (c) EuroSportingClub, All Rights Reserved

////////////////////////////////////////////////////////////////////////////////
// Globals
var ariScrollPausePositions = new Array();
var iScrollPosition;
var iNextPausePosIndex;

var divScrollOuter = null;
var divScrollInner = null;

////////////////////////////////////////////////////////////////////////////////
// Initialize Scroller
function InitializeScroller()
{
  divScrollOuter = window.document.getElementById('ScrollOuter');
  divScrollInner = window.document.getElementById('ScrollInner');
  iScrollPosition = parseInt(divScrollOuter.style.height, 10);
  iNextPausePosIndex = 0;

  divScrollInner.style.top = iScrollPosition;
  ariScrollPausePositions[ariScrollPausePositions.length] = 0;
}

////////////////////////////////////////////////////////////////////////////////
// Adds the contenst of the specified div to the scroll area as a message.
function AddScrollMessageDiv(sDivID)
{
  divScrollInner.innerHTML += window.document.getElementById(sDivID).innerHTML;
  ariScrollPausePositions[ariScrollPausePositions.length] = divScrollOuter.scrollHeight;
}

////////////////////////////////////////////////////////////////////////////////
// Adds the specified string to the scroll area as a message.
function AddScrollMessage(sText)
{
  divScrollInner.innerHTML += sText;
  ariScrollPausePositions[ariScrollPausePositions.length] = divScrollOuter.scrollHeight;
}

////////////////////////////////////////////////////////////////////////////////
// Starts the scroller.
function StartScroller()
{
  window.setTimeout('Scroll()', 50);
}

////////////////////////////////////////////////////////////////////////////////
function Scroll()
{
  // Handle pause between messages
  if (-iScrollPosition >= ariScrollPausePositions[iNextPausePosIndex])
  {
    iScrollPosition = -ariScrollPausePositions[iNextPausePosIndex];
    iNextPausePosIndex++;
    if (iNextPausePosIndex > ariScrollPausePositions.length)
      iNextPausePosIndex = 0;
    else
      iDelay = 2000;
  }
  else
    iDelay = 50;
    
  // Reset scroll position after the last message
  if (-iScrollPosition > divScrollInner.scrollHeight)
  {
    iScrollPosition = parseInt(divScrollOuter.style.height, 10);
    iNextPausePosIndex++;
  }

  // Scroll
  divScrollInner.style.top = iScrollPosition;
  iScrollPosition--;
  
  // Reset timer
  window.setTimeout('Scroll()', iDelay);
}



