/*
 MIT
*/
Glider=Class.create();
Object.extend(Object.extend(Glider.prototype,Abstract.prototype),{initialize:function(a,b){this.scrolling=this.handStopped=false;this.wrapper=$(a);this.scroller=this.wrapper.down("div.scroller");this.sections=this.wrapper.getElementsBySelector("div.sectionslide");this.options=Object.extend({duration:1,frequency:3},b||{});this.sections.each(function(d,c){d._index=c});this.events={click:this.click.bind(this),mouseover:this.pause.bind(this),mouseout:this.resume.bind(this)};this.addObservers();this.options.initialSection&&
this.moveTo(this.options.initialSection,this.scroller,{duration:this.options.duration});this.options.autoGlide&&this.start()},addObservers:function(){this.wrapper.observe("mouseover",this.events.mouseover);this.wrapper.observe("mouseout",this.events.mouseout);var a=this.wrapper.getElementsBySelector("div.sliderdescription");a.invoke("observe","mouseover",this.makeActive);a.invoke("observe","mouseout",this.makeInactive);a=this.wrapper.getElementsBySelector("div.slidercontrol a");a.invoke("observe",
"click",this.events.click)},click:function(a){var b=Event.findElement(a,"a");this.scrolling&&this.scrolling.cancel();this.moveTo(b.href.split("#")[1],this.scroller,{duration:this.options.duration});Event.stop(a)},moveTo:function(a,b,d){this.current=$(a);Position.prepare();var c=Position.cumulativeOffset(b),e=Position.cumulativeOffset(this.current);this.scrolling=new Effect.SmoothScroll(b,{duration:d.duration,x:e[0]-c[0],y:e[1]-c[1]});if(typeof a=="object")a=a.id;this.toggleControl($$('a[href="#'+
a+'"]')[0]);return false},next:function(){if(this.current){var a=this.current._index;a=this.sections.length-1==a?0:a+1}else a=1;this.moveTo(this.sections[a],this.scroller,{duration:this.options.duration})},previous:function(){if(this.current){var a=this.current._index;a=a==0?this.sections.length-1:a-1}else a=this.sections.length-1;this.moveTo(this.sections[a],this.scroller,{duration:this.options.duration})},makeActive:function(a){a=Event.findElement(a,"div");a.addClassName("active")},makeInactive:function(a){a=
Event.findElement(a,"div");a.removeClassName("active")},toggleControl:function(a){$$(".slidercontrol a").invoke("removeClassName","active");a.addClassName("active")},stop:function(){this.handStopped=true;clearTimeout(this.timer)},start:function(){this.handStopped=false;this.periodicallyUpdate()},pause:function(){if(!this.handStopped){clearTimeout(this.timer);this.timer=null}},resume:function(){this.handStopped||this.periodicallyUpdate()},periodicallyUpdate:function(){if(this.timer!=null){clearTimeout(this.timer);
this.next()}this.timer=setTimeout(this.periodicallyUpdate.bind(this),this.options.frequency*1000)}});Effect.SmoothScroll=Class.create();
Object.extend(Object.extend(Effect.SmoothScroll.prototype,Effect.Base.prototype),{initialize:function(a,b){this.element=$(a);a=Object.extend({x:0,y:0,mode:"absolute"},b||{});this.start(a)},setup:function(){if(this.options.continuous&&!this.element._ext){this.element.cleanWhitespace();this.element._ext=true;this.element.appendChild(this.element.firstChild)}this.originalLeft=this.element.scrollLeft;this.originalTop=this.element.scrollTop;if(this.options.mode=="absolute"){this.options.x-=this.originalLeft;
this.options.y-=this.originalTop}},update:function(a){this.element.scrollLeft=this.options.x*a+this.originalLeft;this.element.scrollTop=this.options.y*a+this.originalTop}});