// Accessible Scroller by Mike Foskett (http://www.websemantics.co.uk/). Retain this message and you may use the code freely.

var speed=60;        // speed of scroller
var step=1;          // smoothness of movement
var y, scroll, divH, sText="";
var startY=155;

function onclickIE(idAttr,handler,call){
  if ((document.all)&&(document.getElementById)){
    idAttr[handler]=new Function(call);
  }
}

function addLink(id,call,txt,title){
  var e=document.createElement('A');
  e.setAttribute('href',top);
  e.setAttribute('title',title);
  e.setAttribute('onclick',call);
  var linkIMG=document.createElement('IMG');
  linkIMG.setAttribute('alt',title);
  linkIMG.setAttribute('src',txt);
  e.appendChild(linkIMG);
  document.getElementById(id).appendChild(e);
}

function startScroller(){
  //document.getElementById('flash24scroller').style.whiteSpace='nowrap';
  var p=document.createElement('P');
  p.id='flash24scroller';
  p.style.fontSize='25%'; //fix for mozilla. multiply by 4 before using
  y-=step;
  if (document.getElementById('flash24scroller').className) {
      p.className=document.getElementById('flash24scroller').className;
  }
  if (y<-divH){
     y=startY;
  }
  //document.getElementById('scrollerLabel').innerHTML = 'y :'+divH;
  document.getElementById('flash24scroller').style.top=y+'px';
  scroll=setTimeout('startScroller()',speed);
}

function initScroller(){
  showFlash24("flash24scroller");
  if (document.getElementById && document.createElement && document.body.appendChild) {
    divH=document.getElementById('flash24scroller').offsetHeight;
    y=startY;
    document.getElementById('flash24scroller').style.position='relative';
    document.getElementById('flash24scroller').style.top=y+'px';
    var ss=document.getElementById('flash24scroller').childNodes;
    for (i=0;i<ss.length;i++) {
       sText+=ss[i].nodeValue+" ";
    }

    scroll=setTimeout('startScroller()',speed);
  }
}

function addLoadEvent(func) {
  if (!document.getElementById | !document.getElementsByTagName) return
  var oldonload = window.onload
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload()
      func()
    }
  }
}

function showFlash24(htmlElementId) {
  var links="<ul id='scrollerUl'>";

  // newsArray deve essere un vettore di news già esistente.

  for (var currNewsArray in newsArray) {
        links+='<li><span class="data">'+newsArray[currNewsArray][0]+'</span><br /><a href="'+newsArray[currNewsArray][2]+'" title="leggi la notizia" onclick="javascript:clearTimeout(scroll);">'+newsArray[currNewsArray][1]+'</a><br /><br /></li>';
        arrayElem =newsArray[currNewsArray][0];
  }
  links+='</ul>';
  document.getElementById(htmlElementId).innerHTML = links;
}
addLoadEvent(initScroller)
