Ticker  = Class.create();

Ticker.prototype = {
  initialize: function(node) {
    this.element = node;
    this.prefix=node.id;
    var params=Utils.getParams(node);
    this.current = 0;
    this.nCount = 1*params["newsCount"];
    this.elemH=23;//Element.getHeight(node);
    this.speed = 5;
    this.entries=new Array();
    for (var i=0; i<this.nCount; i++) {
        var el = $(this.prefix + "_scroll" + i);
        if (el) {
          this.entries.push(this.prefix + "_scroll" + i);
          if (i>1) new Effect.Move(el,{y:(1-i)*this.elemH,mode:'relative',duration:0});
        }
    }
    this.registerEvents();
    this.paused=false;
    if (this.entries.length > 1)
        setTimeout(this.next.bind(this),this.speed*1000 + Utils.getTInterval());
  }, 
  pause: function(event) { this.paused=true; },
  release: function(event) { this.paused=false; },
  next: function() {
    setTimeout(this.next.bind(this),this.speed*1000);
    if (this.paused) return false;
    var entries=this.entries;
    new Effect.Move(entries[this.current],{
		y: -1*this.elemH,
		mode:'relative',
		fps:15,duration:0.66, 
		afterFinish: new Function("new Effect.Move('"+entries[this.current]+"',{y: 2*"+this.elemH+",mode:'relative',duration:0, fps:1});")});
    this.current++;
    if (this.current>=entries.length) this.current=0;
    new Effect.Move(entries[this.current],{y:-1*this.elemH,mode:'relative',duration:0.66, fps:15});
  },
  registerEvents: function()  {
        Event.observe(this.element, 'mouseover', this.pause.bindAsEventListener(this) );
        Event.observe(this.element, 'mouseout', this.release.bindAsEventListener(this) );
  }
}


Event.observe(window,'load',function () {
        $$('.ticker').each(function (node){
            new Ticker (node);
        });
  });
