function AnimatedPromos(containerId, tabsId, controlsId, isAutoStart) {
  this.id= "animatedPromos" + Math.floor(9999999*Math.random());
  window[this.id]= this;
  this.containerId= containerId;
  this.container= $(containerId);
  this.tabsId= tabsId;
  this.tabs= $(tabsId);
  this.controls= $(controlsId);
  this.isAutoStart= isAutoStart;
  this.previousIndex=0;
  this.index=0;
  this.newIndex=0;
  this.count= this.container.find("img").length;
  
  this.start= function () {
    this.container.find("img").removeClass("off");
    this.container.find("img").css( { "display":"none", "z-index":"-1" } );
    if( this.isAutoStart ) this.interval= setInterval("window."+this.id+".next()", "6500");
    this.tabs.find("ol li div").css("display", "none");
    this.animate();
  }
  
  this.goto= function(gotoIndex) {
    this.newIndex= gotoIndex;
    this.animate();
    clearInterval( this.interval );
  }
  
  this.next= function () {
    this.newIndex= this.index >= this.count-1 ? 0 : this.index + 1;
    this.animate();
  };
  
  this.prev= function () {
    this.newIndex= ( this.index > 1 ? this.index : this.count ) - 1;
    this.animate();
  };
  
  this.animate= function () {
    // controls
    this.controls.find("ol li").removeClass("on");
    this.controls.find("ol li:eq("+this.newIndex+")").addClass("on");
    // hide previous
    this.container.find("img:eq("+this.previousIndex+")").css( { "display":"none", "z-index":"-1" } );
    this.tabs.find("ol li:eq("+this.index+")").find("div").css("display","none");
    // show current, bring to front
    this.container.find("img:eq("+this.index+")").css( { "display":"block", "z-index":"1" } );
    this.tabs.find("ol li:eq("+this.newIndex+") div").css("display","block");
    // hide new, bring to front
    this.container.find("img:eq("+this.newIndex+")").css( { "display":"none", "z-index":"2" } );
    // show new
    this.container.find("img:eq("+this.newIndex+")").fadeIn(2000);
    this.updateLink( $(this.containerId + " img:eq("+this.newIndex+")") );
    // update indices
    this.previousIndex= this.index;
    this.index= this.newIndex;
  };
  
  this.updateLink= function (img) {
    $(this.containerId).parent().unbind("click");
    if( $(img).attr("href") ) {
      $(this.containerId).parent().bind( "click", function () {
        window.location.href= $(img).attr("href");
      } );
      $(this.containerId).parent().css("cursor", "pointer");
    } else {
      $(this.containerId).parent().css("cursor", "default");
    }
  }

  this.start();
}
