var ImageCarousel=new Class({Implements:[Options],options:{source:'Images/Carousel/',fileLister:'ImageCarousel.php',showDuration:3500,fadeDuration:900,autoPlay:true,files:[]},slide:[],initialize:function(options){this.setOptions(options);this.options.element=$(this.options.element).grab(this.panel=new Element('div',{'class':'panel'}));this.dim=this.options.element.getSize();if($defined(this.options.fileLister)){new Request.JSON({url:this.options.source+this.options.fileLister,secure:false,onSuccess:function(file){this.setFiles(file);this.loadImage(0);}.bind(this)}).get();}else{this.setFiles(this.options.files);this.loadImage(0);}
if(this.options.autoPlay)this.play();},play:function(){this.player=this.nextSlide.periodical(this.options.showDuration,this);return this;},stop:function(){$clear(this.player);return this;},setFiles:function(files){this.options.files=files;this.options.files.each(function(f){if($defined(f)){var slide={file:f,element:new Element('div',{'class':'slide',styles:{width:this.dim.x,height:this.dim.y,backgroundImage:'url('+this.options.source+f+')',opacity:0}})};this.options.element.grab(slide.element);slide.element.set('tween',{duration:this.options.fadeDuration})
this.slide.push(slide);}}.bind(this));return this;},loadImage:function(i){this.currentImage=i;this.slide.each(function(s,j){if(i==j){s.element.fade(1);}else{s.element.fade(0);}}.bind(this));},nextSlide:function(){var t=this.currentImage+1;if(t>this.slide.length-1)t=0;this.loadImage(t);return this;}});ImageCarousel.extend({speed:{fast:{showDuration:2000,fadeDuration:400},normal:{showDuration:3500,fadeDuration:900},slow:{showDuration:5000,fadeDuration:1300}}});window.addEvent('domready',function(){$$('.ImageCarousel.auto').each(function(e){var speed=ImageCarousel.speed.normal;if(e.hasClass('fast'))speed=ImageCarousel.speed.fast;if(e.hasClass('slow'))speed=ImageCarousel.speed.slow;new ImageCarousel($merge({element:e,source:$defined(e.get('rel'))?e.get('rel'):null},speed));});});
