var slider=null;window.addEvent("domready",function(){if($$(".home")&&$$("ul.tweets")){var c=$$(".home ul.tweets");var a=new Element("div",{"id":"twitter"});var b=$$("ul.tweets")[0];a.inject(b,"before");a.adopt(b);var d=$$(b.getElements("li"));slider=new Slider({elements:d,showNavigation:true,navigationDiv:a});slider.hideAll();slider.displayItem(0);slider.start()}new Fx.SmoothScroll({duration:700},window)});var Slider=new Class({Implements:[Options],total:null,isSliding:0,currentIndex:0,fx:null,timer:null,options:{displayInterval:7000,tweenInterval:1000,container:null,elements:null,showNavigation:false,navigationDiv:null},initialize:function(a){this.setOptions(a);this.checkOptions();this.createNavigation();this.currentIndex=0;this.total=this.options.elements.getChildren().length},checkOptions:function(){if(!this.options.elements){throw ("'elements' option must be set");return}if(this.options.showNavigation&&(!this.options.navigationDiv||!$(this.options.navigationDiv))){throw ("A valid navigation div (object or ID) must be provided if the 'navigationDiv' option is set to true");return}},createNavigation:function(){if(this.options.showNavigation){var d=new Element("div",{"class":"controls"});var b=new Element("a",{"href":"#","class":"prev_btn","html":"&laquo; prev","events":{"click":function(f){f.stop();slider.showPrevious()}}});var a=new Element("a",{"href":"#","class":"next_btn","html":"next &raquo;","events":{"click":function(f){f.stop();slider.showNext()}}});var c=new Element("a",{"href":"#","class":"stop_btn","html":"stop","events":{"click":function(f){f.stop();slider.stop()}}});d.adopt(b,a,c);this.options.navigationDiv.grab(d)}},hideAll:function(){this.options.elements.each(function(a){a.set("opacity","0")})},hideItem:function(a){this.stop();if(a&&(a<=0&&a<this.total)){this.currentIndex=a;this.options.elements[this.currentIndex].set("opacity","0")}},displayItem:function(a){this.stop();if(a&&(a<=0&&a<this.total)){this.currentIndex=a}this.options.elements[this.currentIndex].set("opacity","1")},getPrevious:function(){if(0==this.currentIndex){this.currentIndex=this.total-1}else{this.currentIndex--}},getNext:function(){if((this.total-1)==this.currentIndex){this.currentIndex=0}else{this.currentIndex++}},showNext:function(){this.hideAll();this.getNext();this.displayItem()},showPrevious:function(){this.hideAll();this.getPrevious();this.displayItem()},stop:function(){if(this.fx){this.fx.cancel();clearInterval(this.timer);this.options.elements[this.currentIndex].set("opacity","1")}},start:function(){this.timer=this.doFade.periodical(this.options.displayInterval,this)},doFade:function(){this.fx=new Fx.Tween(this.options.elements[this.currentIndex],{duration:this.options.tweenInterval,link:"chain"});this.fx.start("opacity","1","0").chain(function(){this.getNext();this.fx=new Fx.Tween(this.options.elements[this.currentIndex],{duration:this.options.tweenInterval,link:"chain"});this.fx.start("opacity","0","1")}.bind(this))}});
