// Accessible Scroller by Mike Foskett (http://www.websemantics.co.uk/). Retain this message and you may use the code freely.
// Edited by Leo Ludwig (http://www.wduk.co.uk/).

var speed=70        // speed of scroller
var step=5          // smoothness of movement

var x, scroll, divW, sText=""

function stopScroller(){clearTimeout(scroll)}

function startScroller(){
  document.getElementById('scrollnews').style.whiteSpace='nowrap'
  //create a paragraph to copy the scrolling text and find out its width
  var p=document.createElement('P')
  p.id='testP'
  x-=step
  if (document.getElementById('scrollnews').className) p.className=document.getElementById('scrollnews').className
  //add the new paragraph to the document flow and append the text create in initScroller function
  p.appendChild(document.createTextNode(sText))
  document.body.appendChild(p)
  //calculate the width of the newlycreated paragraph
  pw=p.offsetWidth
  //remove paragraph from page
  document.body.removeChild(p)
  // if the posistion of the scrolling p is less than -the total width start over the scroller
  if (x<(pw)*-1){x=divW}
  document.getElementById('scrollnews').style.left=x+'px'
  scroll=setTimeout('startScroller()',speed)
}

function initScroller(){
  if (document.getElementById && document.createElement && document.body.appendChild) {
    divW=document.getElementById('scroller').offsetWidth
    x=divW
    document.getElementById('scrollnews').style.position='relative'
    document.getElementById('scrollnews').style.left=divW+'px'
    sHTML = document.getElementById('scrollnews');
	sText = '';
	// we wanted the scroller to link to the news items so we have additional html tags for the links
	// we select the anchor text only and pass it to the startScroller function
	// the data passed is used to determine the width of the scroller and leaving the html makes it a lot wider than reality
	var anchors = sHTML.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i].innerHTML;
		sText += anchors[i].innerHTML + ' | ';
	}
	scroll=setTimeout('startScroller()',speed)
  }
}