var XcAdvert = function(image_container, text_container, timeout) {
  this.image_container = image_container, 
  this.text_container = text_container, 
  this.timeout = timeout * 1000, 
  this.maxitem = 0, 
  this.actualitem = 0, 
  
  this.animImageTo1 = new YAHOO.util.Anim(this.image_container, { opacity: { to: 1 }, duration: 0.6 });
  this.animImageTo0 = new YAHOO.util.Anim(this.image_container, { opacity: { to: 0 }, duration: 0.6 });
  this.animTextTo1 = new YAHOO.util.Anim(this.text_container, { opacity: { to: 1 }, duration: 0.6 });
  this.animTextTo0 = new YAHOO.util.Anim(this.text_container, { opacity: { to: 0 }, duration: 0.6 });
  
  this.images = [], 
  this.texts = []
};

XcAdvert.prototype = 
{
  addImage: function(src)
  {
    this.images.push(src);
  }, 
  
  addText: function(text)
  {
    this.texts.push(text);
  }, 
  
  startAdvert: function()
  {
    this.maxitem = this.texts.length;
    this.showNext(0);
  }, 
  
  showNext: function(i)
  {
    var activeObj = this;
    
    if ( i >= this.maxitem )
    {
      this.actualitem = 0;
      i = this.actualitem;
    }
    if ( typeof this.images[i] != "undefined" )
    {
      this.animImageTo0.animate();
      window.setTimeout(
        function(){
          Dom.get(activeObj.image_container).src = activeObj.images[i];
          activeObj.animImageTo1.animate();
        }, 
        610
      );
    }
    this.animTextTo0.animate();
    window.setTimeout(
      function(){
        Dom.get(activeObj.text_container).innerHTML = activeObj.texts[i];
        activeObj.animTextTo1.animate();
      }, 
      610
    );
    
    this.actualitem++;
    
    window.setTimeout(
      function(){
        activeObj.showNext.call(activeObj, activeObj.actualitem);
      }, 
      activeObj.timeout
    );
  }
};