var Fader=Class.create({initialize:function(_1,_2,_3){
this.rotatingImageObjs=_1;
this.containerElement=$(_2);
this.preloader=new Preloader();
this.newTag=null;
this.retryDuration=1;
var _4=Fader._getImageElement(this.containerElement);
this.imageHeight=_4.getHeight();
this.imageWidth=_4.getWidth();
this.options=Object.extend({fadeInDuration:1,fadeOutDuration:1,displayDuration:2,crossfade:false,pause:false},_3||{});
if(this.options.crossfade){
this.containerElement.setStyle({height:this.imageHeight+"px",width:this.imageWidth+"px"});
this.containerElement.makePositioned();
this.containerElement.firstDescendant().setStyle({position:"absolute",top:0,left:0});
}
var _5=[];
for(var i=0;i<_1.length;i++){
_5.push(_1[i].imgPath);
}
this.preloader.addToQueue(_5);
this.preloader.startLoading();
if(!this.options.pause){
this.pe=new PeriodicalExecuter(this.next.bind(this),this.options.displayDuration);
}
},next:function(pe){
if(this.pe!=null){
this.pe.stop();
}
var _8=this.rotatingImageObjs.shift();
this.rotatingImageObjs.push(_8);
if(!this.preloader.hasPathLoaded(_8.imgPath)){
this.rotatingImageObjs.unshift(this.rotatingImageObjs.pop());
this.pe=new PeriodicalExecuter(this.next.bind(this),this.retryDuration);
return false;
}
this.fadeToImage(_8);
},prev:function(pe){
if(this.pe!=null){
this.pe.stop();
}
this.rotatingImageObjs.unshift(this.rotatingImageObjs.pop());
var _a=this.rotatingImageObjs.pop();
this.rotatingImageObjs.push(_a);
if(!this.preloader.hasPathLoaded(_a.imgPath)){
this.rotatingImageObjs.push(this.rotatingImageObjs.shift());
this.pe=new PeriodicalExecuter(this.prev.bind(this),this.retryDuration);
return false;
}
this.fadeToImage(_a);
},fadeToImage:function(_b){
var _c=Fader._getImageElement(this.containerElement);
this.newTag=Element.extend(document.createElement("img"));
this.newTag.writeAttribute("src",_b.imgPath);
this.newTag.writeAttribute("alt",_b.imgAlt);
this.newTag.writeAttribute("width",this.imageWidth);
this.newTag.writeAttribute("height",this.imageHeight);
Element.setOpacity(this.newTag,0);
var _d;
if(_b.linkUrl!=null){
_d=Element.extend(document.createElement("a"));
_d.writeAttribute("href",_b.linkUrl);
this.newTag=_d.update(this.newTag);
}
if(this.options.crossfade){
this.newTag.setStyle({position:"absolute",top:0,left:0});
var _e=(this.newTag.tagName!="IMG")?Fader._getImageElement(this.newTag):this.newTag;
this.containerElement.insert(this.newTag);
new Effect.Opacity(_e,{duration:this.options.fadeInDuration,from:0,to:1,afterFinish:this.onCrossfadeFinish.bind(this)});
}else{
new Effect.Opacity(_c,{duration:this.options.fadeOutDuration,from:1,to:0,afterFinish:this.onFadeOutFinish.bind(this)});
}
},onFadeOutFinish:function(_f){
this.containerElement.childElements().first().replace(this.newTag);
var img=Fader._getImageElement(this.containerElement);
new Effect.Opacity(img,{duration:this.options.fadeInDuration,from:0,to:1,afterFinish:this.onFadeInFinish.bind(this)});
},onFadeInFinish:function(obj){
if(!this.options.pause){
this.pe=new PeriodicalExecuter(this.next.bind(this),this.options.displayDuration);
}
},onCrossfadeFinish:function(obj){
this.containerElement.childElements().first().remove();
if(!this.options.pause){
this.pe=new PeriodicalExecuter(this.next.bind(this),this.options.displayDuration);
}
}});
Fader._getImageElement=function(_13){
var img=_13.select("img")[0];
return img;
};

