SW.domWidget.add({
  id:"imageRotator",
  container:null,
  items:[],                                                 
  currentIdx:0,
  load:function() {
    var self = this;
    this.container = yuiDom.get("careerIntroImages");
    if (this.container) {
      this.items = yuiDom.getElementsByClassName("careerIntroImage", "li", this.container);
      this.items.forEach(function(item, i) {
        item.style.display = "block";
        yuiDom.setStyle(item, "opacity", 0);
        var frameLength = item.getAttribute("framelength") * 1000;
        item.Idx = i;
        item.animIn = new yuiAnim(item, {opacity:{from:0,to:1}}, 1);
        item.animIn.onStart.subscribe(function() {
          yuiDom.setStyle(item, "opacity", 0);
          //          yuiDom.addClass(item,"show");
          self.currentIdx = item.Idx;
        });
        item.animIn.onComplete.subscribe(function() {
          setTimeout(function() {
            self.hideThis();
          }, frameLength);
        });
        item.animOut = new yuiAnim(item, {opacity:{from:1,to:0}}, 1);
        item.animOut.onStart.subscribe(function() {
          self.showNext();
        });
        item.animOut.onComplete.subscribe(function() {
          //          yuiDom.removeClass(item,"show");
        });
      });
      this.items[0].animIn.animate();
    }
  },
  hideThis:function() {
    this.items[this.currentIdx].animOut.animate();
  },
  showNext:function() {
    this.currentIdx++;
    if (this.currentIdx >= this.items.length) {
      this.currentIdx = 0;
    }
    this.items[this.currentIdx].animIn.animate();
  }
});

SW.domWidget.imageRotator.setEnabled(true);

