var totalScrollWidth = 0;
var singleWidth = 160;
var maxScrollWidth = 500;
var numberOfCreatedElements = 0;
var scrolling = false;

if(document.layers||(document.getElementById&&!document.all))
{
   scrollWidth=window.outerWidth;
}
else if(document.all)
{
   scrollWidth=document.body.clientWidth;
}

maxScrollWidth = scrollWidth;



function scroll()
{
  var counter = 0;
  while (maxScrollWidth > totalScrollWidth)
  {
    for (var item in scrollItems)
    {
      var element = document.createElement("div");
      element.style.height = singleWidth+"px";
      element.style.width = singleWidth+"px";
      element.style.position = "absolute";
      element.style.left = (counter*singleWidth)+"px";
      element.className = scrollItems[item][1];
      element.id = "scroller_"+counter;
      element.innerHTML = scrollItems[item][0];
      document.getElementById(scrollHolder).appendChild(element);
      numberOfCreatedElements++;
      counter++;
    }

    totalScrollWidth = singleWidth * (counter-1)-5;
  }
  scrolling = true;
  scrollAll();
}

function scrollAll()
{
  if(scrolling)
  {
    for (var i = 0; i < numberOfCreatedElements; i++)
    {
      scrollItem("scroller_"+i);
    }
  }
  window.setTimeout("scrollAll()",50);
}

function scrollItem(itemId)
{
  var item = document.getElementById(itemId).style;
  var currentLeft = parseInt(item.left);
  var itemWidth = parseInt(item.width);
  
  if (currentLeft <= -itemWidth)
  {
    item.left = totalScrollWidth+"px";
  }
  else
  {
    item.left = (currentLeft-1)+"px";
  }
}

function stop_scroll()
{
  scrolling = false;
}

function continue_scroll()
{
  scrolling = true;
}

function highlight(elementId, className)
{
  document.getElementById(elementId).className = className;
}
