function ticker(id, countShowedItems, itemWidth){
    
    this.id = id;
    this.obj = d_obj(id);
    this.content_id = id+'_content';
    this.content_obj = d_obj(id+'_content');
    this.items = null;
    this.current_item = null;
    
    this.lb_obj = d_obj(id+'_lb');    
    this.rb_obj = d_obj(id+'_rb'); 
    
    this.countShowedItems = countShowedItems;
    this.itemWidth = itemWidth;   
    
    this.init = function(){
      var items = this.content_obj.getElementsByTagName('div');
      this.items = new Array();
      var j = 0
      for (var i=0; i<items.length; i++){
          if (items[i].className == "content_block") {
            this.items[j] = items[i];
            j++;
          }  
      }
      this.current_item = 0;
      addEvent(this.lb_obj, 'click',  function(e){
        var anchor_id = this.id;
        var ticker_id = anchor_id.substring(0, anchor_id.indexOf('_lb'));
        var tickerNumber = getTickerNumberById(ticker_id);
        if (tickerNumber != null) tickers[tickerNumber].getPrevItem(); 
        
      });

      addEvent(this.rb_obj, 'click',  function(e){
        var anchor_id = this.id;
        var ticker_id = anchor_id.substring(0, anchor_id.indexOf('_rb'));
        
        var tickerNumber = getTickerNumberById(ticker_id);
        if (tickerNumber != null) tickers[tickerNumber].getNextItem(); 
        
      });
      
    }; //init
    
    
    this.getPrevItem = function(){
        if ((this.current_item != null) && (!ticker_moved)){
            if ((this.current_item) > 0) {
              refreshTicker(this.content_id, this.current_item, this.itemWidth);
              ticker_moved = true;
              new Effect.Move(this.content_id, { x: this.itemWidth, y: 0, duration: 0.7 }); 
              this.current_item = this.current_item-1;
              window.setTimeout("refreshTicker('"+this.content_id+"', '"+this.current_item+"', "+ this.itemWidth +")", 900); 
            }
        }
    };
    this.getNextItem = function(){
        if ((this.current_item != null) && (!ticker_moved)){
            if ((this.current_item+this.countShowedItems) < this.items.length) {
              refreshTicker(this.content_id, this.current_item, this.itemWidth);
              var deltaMinus = (-1)* this.itemWidth;
              ticker_moved = true;
              new Effect.Move(this.content_obj, { x: deltaMinus, y: 0, duration: 0.7 }); 
              this.current_item = this.current_item+1;
              window.setTimeout("refreshTicker('"+this.content_id+"', '"+this.current_item+"', "+ this.itemWidth +")", 900); 
            }
        }
    };
    
}
function addEvent (obj, type, fn ){  // the add event function
  if (obj.addEventListener) obj.addEventListener( type, fn, false );
  else if (obj.attachEvent) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() {
      obj["e"+type+fn]( window.event );
    };
    obj.attachEvent( "on"+type, obj[type+fn] );
  }
}
var tickers = new Array();
var main_items = null;
var ticker_moved = false;
function initTicker(id, countShowedItems, itemWidth){
    var len = tickers.length;
    tickers[len] = new ticker(id, countShowedItems, itemWidth);
    tickers[len].init();
}
function getTickerNumberById(id){
    for(var i=0; i<tickers.length; i++){
        if(tickers[i].id == id) return i;
    }
    return null;
}   
function refreshTicker(cover_id, num, itemWidth){
    d_style(cover_id).left = (0 - num * itemWidth)+"px";
    ticker_moved = false;
}