var Ticker = {
  paras: [], 
  nbStory: items.length, 
  currentStory: 0, 
  startPosition: 650,//pageWidth(),
  storyTimeout: 8000, 
  lineTimeout: 5, 
  currentTimeout: 0,

  init: function() {
    this.currentTimeout = this.storyTimeout;
    var ticker = document.createElement('div');
    ticker.setAttribute('id', 'ticker');
    document.getElementsByTagName('body')[0].appendChild(ticker);
    this.currentPosition = this.startPosition;

    var para = '';
    for (var i=0;i<this.nbStory;i++) {
      para = document.createElement('p');
      para.innerHTML = items[i];
      ticker.appendChild(para);
    }
    
    this.paras = ticker.getElementsByTagName('p');
    this.nbStory = this.paras.length;
    this.currentStory = this.nbStory-1;
    this.paras[0].style.display = 'block';
    this.paras[0].style.left = this.currentPosition + 'px';
    Ticker.run();
  },

  run: function() {
    if (this.currentPosition==this.startPosition) {
      this.paras[this.currentStory].style.display = 'none';
      this.currentStory++;
      if (this.currentStory==this.nbStory) {
	this.currentStory = 0;
      }
      this.paras[this.currentStory].style.display = 'block';
    }
    
    if (this.currentPosition>0) {
      this.currentPosition--;
      if (this.currentPosition==0) {
	this.currentTimeout = this.storyTimeout;
      } else {
	this.currentTimeout = this.lineTimeout;
      }
    } else {
      this.currentPosition = this.startPosition;
      this.currentTimeout = 0;
    }
    this.paras[this.currentStory].style.left = this.currentPosition + 'px';
    setTimeout("Ticker.run()", this.currentTimeout);
  }
};

function tickerInit() {
  if (document.getElementsByTagName('body')[0]!=null) {
    Ticker.init();
  }
}

function pageWidth(){
    return window.innerWidth != null? 
    window.innerWidth: document.documentElement && 
    document.documentElement.clientWidth ?
    document.documentElement.clientWidth:document.body != null? 
    document.body.clientWidth:null;
    }

addLoadListener(tickerInit);

