var Ticker = new Class({
    // Options can be extended in future.
    options: { interval: 6000 },
    
    // Set Container Div and interval.
    initialize: function(containerId, options) {
    
    this.outer = $(containerId); 
    this.setOptions(options);
    this.interval = this.options.interval;
    this.delete_interval = this.interval - 2000;

    // Get the child Elements of the Container Div.
    this.messageEls = this.outer.getChildren();

    this.messages = this.messageEls.length;
    if (this.messages == 0) 
        return false;

    this.cur = 0; 
    this.prev = null;
    // Hide all.
    this.hideAll(); 
    // Show initial Message.
    this.show();
    // Periodic call to Show Method.
    this.timer = this.show.periodical(this.interval,this);
  
  },
  show: function() {
    var Appear = new Fx.Style(this.messageEls[this.cur],'opacity',{duration: 300, onStart:function(item) {
      item.setStyle('display','inline');
     }}).start(0,1);
    var d = this.remove.delay(this.delete_interval,this);
    
    if (this.cur < this.messages-1) { this.prev = this.cur++; } 
    else { this.cur = 0; this.prev = this.messages -1; }
  },
  remove: function() {
    // console.log(this.prev);
    // console.log(this.cur);

   var e_ref = this.messageEls[this.prev];
   if(e_ref == this.cur-1) {
    this.cur = 0;
    this.prev = null;
    this.hideAll();
    this.show();
   } else {
    e_ref.setStyles({ 'display':'none','opacity':0 });
   }
  },
  hideAll: function() {
    this.messageEls.each( function(message) {message.setStyles({ 'display':'none','opacity':0 }); }) 
  }
}); 
// Implement the Options.
Ticker.implement(new Options);
