global_offset = 1;
var startElement;
var startPosition;
var skipElement;
var skipPosition;
var isPaused = false;

function startTicker() {
  var toMove= document.getElementById("ticker");

  if ( ! isPaused ) {

    startElement = document.getElementById( 'startPoint' );
    startPosition = getPosition( startElement ).x;
    skipElement = document.getElementById( 'skipPoint' );
    skipPosition = getPosition( skipElement ).x;

    currentScrollValue = toMove.scrollLeft;

    toMove.scrollLeft += global_offset;
    if ( currentScrollValue >= skipPosition ) {
      toMove.scrollLeft = startPosition;
    }
  }


    /*
      document.getElementById( 'counter' ).innerHTML = currentScrollValue;
      if ( global_offset > 0 && currentScrollValue > 800 ) {
      global_offset *= -1;
      }
      if ( global_offset < 0 && currentScrollValue == 0 ) {
      global_offset *= -1;
      }
    */
}

function setPause( trueOrFalse ) {
  isPaused = trueOrFalse;
}


function jaja() {
  alert( "start position: " + startPosition + ", skip position: " + skipPosition );
  /*
      var x=document.anchors.length;
      for (var i = 0; i < document.anchors.length; i++) {
          y=document.anchors[i];
          alert( 'length is ' + x + ', x-position is ' + getPosition(y).x );
      }
  */
}

// Borrowed from
//   http://kkaefer.com/blog/javascript-position-bestimmen
function getPosition(obj) {
  var pos = { x:0, y:0 };

  do {
    pos.x += obj.offsetLeft;
    pos.y += obj.offsetTop;
  } while (obj = obj.offsetParent);

  return pos;
}

