var SlideShow=(function(){return{containerId:"slides",frameSelector:"div.frame",delay:5000,random:true,navigation:true,hide:Effect.Fade,show:Effect.Appear,current:0,frames:[],last:-1,timeout:null,first:true,init:function(b){var e=["containerId","frameSelector","delay","random","navigation","hide","show"];b=b||{};while(e.length){var a=e.shift();if(a in b){this[a]=b[a]}}this.frames=$A($(this.containerId).select(this.frameSelector));this.last+=this.frames.length;if(this.random){var d=[];while(this.frames.length){var c=Math.floor(Math.random()*this.frames.length);d.push(this.frames.splice(c,1)[0])}this.frames=d}for(var c=0;c<=this.last;c++){this.frames[c].hide()}this.go(0);if(this.navigation){this.buildNavigation().updateNavigation()}$(this.containerId).fire("slideshow:init",{element:$(this.containerId),frames:this.frames.length,frameElements:this.frames,currentFrame:(this.current+1),frameElement:this.frames[this.current]});return this},buildNavigation:function(){var e=new Element("ul",{"class":"navigation"});for(var d=0;d<this.frames.length;d++){var b=new Element("li",{"class":"f"+d}),c=new Element("a",{href:"#slide"+(d+1),"class":"f"+d});c.observe("click",function(a){a.preventDefault();SlideShow.go(this.className.replace(/[^\d]+/g,""))});c.insert("<span>"+(d+1)+"</span>");b.insert(c);e.insert(b)}$(this.containerId).insert(e);$(this.containerId).fire("slideshow:navbuilt",{element:$(this.containerId),frames:this.frames.length,frameElements:this.frames,navElement:$(this.containerId).select("ul")[0]});return this},updateNavigation:function(){var a=$(this.containerId).select("ul.navigation li");for(var b=a.length-1;b>=0;b--){if(a[b].hasClassName("f"+this.current)){a[b].addClassName("active")}else{if(a[b].hasClassName("active")){a[b].removeClassName("active")}}}$(this.containerId).fire("slideshow:navupdated",{element:$(this.containerId),frames:this.frames.length,frameElements:this.frames,currentFrame:(this.current+1),navElement:$(this.containerId).select("ul")[0]});return this},stop:function(){if(this.timeout){clearTimeout(this.timeout);this.timeout=null}$(this.containerId).fire("slideshow:stopped",{element:$(this.containerId),frames:this.frames.length,frameElements:this.frames,currentFrame:(this.current+1),navElement:$(this.containerId).select("ul")[0]});return this},start:function(){this.timeout=setTimeout(function(){this.next()}.bind(this),this.delay);$(this.containerId).fire("slideshow:started",{element:$(this.containerId),frames:this.frames.length,frameElements:this.frames,currentFrame:(this.current+1),navElement:$(this.containerId).select("ul")[0]});return this},next:function(a){this.go(this.current+1);this.timeout=setTimeout(function(){this.next()}.bind(this),this.delay);return this},previous:function(a){this.go(this.current-1);this.timeout=setTimeout(function(){this.previous()}.bind(this),this.delay);return this},go:function(a){this.stop();if(!this.first){this.hide(this.frames[this.current]);$(this.containerId).fire("slideshow:hide",{element:$(this.containerId),frames:this.frames.length,frameElements:this.frames,currentFrame:(this.current+1),navElement:$(this.containerId).select("ul")[0],frameElement:this.frames[this.current]})}else{this.first=false}if(a>this.last){a=0}else{if(a<0){a=this.last}}this.current=a;this.show(this.frames[this.current]);$(this.containerId).fire("slideshow:show",{element:$(this.containerId),frames:this.frames.length,frameElements:this.frames,currentFrame:(this.current+1),navElement:$(this.containerId).select("ul")[0],frameElement:this.frames[this.current]});if(this.navigation){this.updateNavigation()}return this}}})();
