var scrollSpeed = 1;

function getStyle(el,styleProp)
{
  var x = document.getElementById(el);
  if (x.currentStyle)
    var y = x.currentStyle[styleProp];
  else if (window.getComputedStyle)
    var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
  return y;
}

function getText(autoScrollTextValueId)
{
  return document.getElementById(autoScrollTextValueId);
}

function getContainer(autoScrollTextContainerId)
{
  return document.getElementById(autoScrollTextContainerId);
}

function getTextWidth(autoScrollTextValueId)
{
  //return getStyle(autoScrollTextValueId, 'width');//getText().offsetWidth;
  return getText(autoScrollTextValueId).offsetWidth;
}

function getContainerWidth(autoScrollTextContainerId)
{
  return getContainer(autoScrollTextContainerId).clientWidth;
}

function getTextItem(autoScrollTextValueId, i)
{
  return document.getElementById(autoScrollTextValueId + '_' + i);
}

function scrollText(autoScrollTextValueId, autoScrollTextContainerId)
{
  var maxItems = 50;

  var posLeft = 0;
  var textWidth = getTextWidth(autoScrollTextValueId);
  var containerWidth = getContainerWidth(autoScrollTextContainerId);
  if (textWidth > 0 && containerWidth > 0)
  {
    var textHtml = getText(autoScrollTextValueId + '_0').innerHTML;
    for (var i = 0; i < maxItems; i++)
    {
      if (2 * containerWidth <= textWidth || textWidth <= 0)
        break;
      
      getText(autoScrollTextValueId).innerHTML = getText(autoScrollTextValueId).innerHTML + '&nbsp;<span style="position: relative;" id="' + autoScrollTextValueId  +  '_' + (i + 1) +  '">' + textHtml + '</span>';
      
      textWidth = getTextWidth(autoScrollTextValueId);
    }
    setInterval(function()
    {
      var textValueStyle = getText(autoScrollTextValueId).style;
      textValueStyle.left = posLeft + 'px';

      posLeft -= scrollSpeed;
      if ((-1) * posLeft == getTextItem(autoScrollTextValueId, 0).offsetWidth)
        posLeft = 0;
    }, 30);
  }
}

window.onload = function()
{
  if (document.getElementById('auto_scroll_ttext_value_0').innerHTML.length > 0) {
    document.getElementById('auto_scroll_ttext_container').style.display = '';
    document.getElementById('pod').style.marginTop = '7px';
  }

  scrollText('auto_scroll_text_value', 'auto_scroll_text_container');
  scrollText('auto_scroll_ttext_value', 'auto_scroll_ttext_container');
}

