if(typeof Effect=='undefined')throw("carroussel.js requires including script.aculo.us' effects.js library!");var caroussel=Class.create({initialize:function(container,options){this.container=$(container);this.options=Object.extend({tag:'li',treeTag:'ul',init:this.defaultInit,transitionFx:defaultFx,effectSpeed:1,effectOptions:{},autostart:false,pauseOnOver:false,time:3,loop:false,random:false,previousBt:null,nextBt:null,playBt:null,pauseBt:null,stopBt:null,pagesBt:null,pagesDir:'ltr',disabledClass:'disabled'},options||{});if(null!==this.options.pagesBt)this.options.randoms=false;this.timer=null;this.slides=Element.findChildren(this.container,false,false,this.options.tag);this.slidesIndex=$R(0,this.slides.size(),true).toArray();this.slidesNav=[];this.currentNav=0;this._updateNav();this.isTheLoop=false;if(null!==this.options.init){this.options.init(this.slides,this._getSlideElement(this.currentNav))}this._initButtons();if(this._canAutoStart()){this.start()}},defaultInit:function(slides,firstSlide){slides.each(function(slide){if(firstSlide!=slide){$(slide).style.display='none'}})},start:function(){if(null===this.timer){this.timer=new PeriodicalExecuter(this.next.bind(this),this.options.time)}},stop:function(){if(null!==this.timer){this.timer.stop();this.timer=null}},pause:function(){this.stop()},next:function(event){this.stop();if(this._canAutoStart()){this.start()}this._updateNav();var nextNav=this.currentNav+1;var slidesBetween=this._getSlidesBeetwen(this.currentNav,nextNav);var currentSlideElement=this._getSlideElement(this._getIndexSlideByIndexNav(this.currentNav));var nextElement=this._getSlideElement(this._getIndexSlideByIndexNav(nextNav));this.currentNav=nextNav;this._updateButtons();var optionsFx=Object.extend({fxSpeed:this.options.effectSpeed,slides:this.slides,slidesBetween:slidesBetween,isTheLoop:this.isTheLoop,revert:false},this.options.effectOptions);this.options.transitionFx(currentSlideElement,nextElement,optionsFx);this._dontLink(event)},previous:function(event){this.stop();if(this._canAutoStart()){this.start()}this.isTheLoop=false;if(0==this._getIndexSlideByIndexNav(this.currentNav)){if(this.options.loop){var previousNav=this.slidesNav.size()-1;this.isTheLoop=true}else{return}}else{var previousNav=this.currentNav-1}var slidesBetween=this._getSlidesBeetwen(this.currentNav,previousNav);var currentSlideElement=this._getSlideElement(this._getIndexSlideByIndexNav(this.currentNav));var previousElement=this._getSlideElement(this._getIndexSlideByIndexNav(previousNav));this.currentNav=previousNav;this._updateButtons();var optionsFx={fxSpeed:this.options.effectSpeed,slides:this.slides,slidesBetween:slidesBetween,isTheLoop:this.isTheLoop,revert:true};this.options.transitionFx(currentSlideElement,previousElement,optionsFx);this._dontLink(event)},_goTo:function(slideIndex){this.stop();if(this._canAutoStart()){this.start()}var slideIndex=Math.abs(parseInt(slideIndex));if(slideIndex<0)slideIndex=0;if(slideIndex>this.slidesNav.size())slideIndex=this.slidesNav.size();var navSlideIndex=this._getIndexNavBySlideIndex(parseInt(slideIndex));var slidesBetween=this._getSlidesBeetwen(this.currentNav,navSlideIndex);var currentSlideElement=this._getSlideElement(this._getIndexSlideByIndexNav(this.currentNav));var nextElement=this._getSlideElement(this._getIndexSlideByIndexNav(navSlideIndex));var isRevert=this._getIndexSlideByIndexNav(this.currentNav)>this._getIndexSlideByIndexNav(navSlideIndex);this.currentNav=navSlideIndex;this._updateButtons();var optionsFx={fxSpeed:this.options.effectSpeed,slides:this.slides,slidesBetween:slidesBetween,isTheLoop:this.isTheLoop,revert:isRevert};this.options.transitionFx(currentSlideElement,nextElement,optionsFx)},goTo:function(slideNumber){this._goTo(parseInt(slideNumber,10)-1)},_canAutoStart:function(){if(this.slides.length>1&&this.options.autostart){return true}return false},__goToAndEvent:function(event,slideIndex){this._goTo(slideIndex);this._dontLink(event)},_initButtons:function(){if(null!==this.options.previousBt){if($(this.options.previousBt)){$(this.options.previousBt).stopObserving('click');if(0==this.currentNav){if(this.options.loop){$(this.options.previousBt).removeClassName(this.options.disabledClass);$(this.options.previousBt).observe('click',this.previous.bind(this))}else{$(this.options.previousBt).addClassName(this.options.disabledClass);$(this.options.previousBt).observe('click',this._desactivedButton.bind(this))}}else{$(this.options.previousBt).removeClassName(this.options.disabledClass);$(this.options.previousBt).observe('click',this.previous.bind(this))}}}if(null!==this.options.nextBt){if($(this.options.nextBt)){$(this.options.nextBt).stopObserving('click');if(this.currentNav==this.slidesNav.size()-1){if(this.options.loop){$(this.options.nextBt).removeClassName(this.options.disabledClass);$(this.options.nextBt).observe('click',this.next.bind(this))}else{$(this.options.nextBt).addClassName(this.options.disabledClass);$(this.options.nextBt).observe('click',this._desactivedButton.bind(this));if(this._canAutoStart()){this.stop()}}}else{$(this.options.nextBt).removeClassName(this.options.disabledClass);$(this.options.nextBt).observe('click',this.next.bind(this))}}}if(null!==this.options.pagesBt){if($(this.options.pagesBt)){var pagesContainer=$(this.options.pagesBt);var pages=Element.findChildren(pagesContainer,false,false,'li');if('rtl'===this.options.pagesDir){pages.reverse()}var currentSlide=this._getIndexSlideByIndexNav(this.currentNav);pages.each(function(p,index){$(p).stopObserving('click');if(index==currentSlide){$(p).addClassName(this.options.disabledClass);$(p).observe('click',this._desactivedButton.bind(this))}else{$(p).removeClassName(this.options.disabledClass);$(p).observe('click',this.__goToAndEvent.bindAsEventListener(this,index))}}.bind(this))}}},_updateButtons:function(){this._initButtons()},_desactivedButton:function(event){this._dontLink(event)},_mouseOver:function(event){this.stop()},_mouseOut:function(event){this.start()},_getIndexSlideByIndexNav:function(indexNav){return this.slidesNav[indexNav]},_getIndexNavBySlideIndex:function(slideIndex){for(var i=this.slidesNav.size()-1;i>=0;i--){if(this.slidesNav[i]==slideIndex){return i}}},_getSlideElement:function(index){return this.slides[index]},_getSlideIndexByElement:function(slideElement){var slideIndex=-1;this.slides.each(function(s,index){if(s==slideElement){slideIndex=index}});return slideIndex},_getSlidesBeetwen:function(currentSlideNavIndex,nextSlideNavIndex){var currentSlideIndex=this._getIndexSlideByIndexNav(currentSlideNavIndex);var nextSlideIndex=this._getIndexSlideByIndexNav(nextSlideNavIndex);return Math.abs(nextSlideIndex-currentSlideIndex)},_slideIndexIsRevert:function(slideIndex){var navIndex=this._getIndexNavBySlideIndex(slideIndex);return this._isRevert(navIndex)},_isRevert:function(navIndex){console.info('this.currentNav = '+this.currentNav+' | navIndex='+navIndex);if(this.currentNav>=navIndex){return false}else{return true}},_getEffectOptions:function(){var optionsFx=Object.extend({fxSpeed:this.options.effectSpeed,slides:this.slides,revert:this._isRevert(this.currentNav)},this.options.effectOptions||{});return optionsFx},_dontLink:function(event){if(event&&false===event instanceof PeriodicalExecuter){var link=Event.findElement(event,'a');if(link!=document){event.stop()}}},_updateNav:function(){if(0==this.slidesNav.size()||this.currentNav==this.slidesNav.size()-1){var slides=this.slidesIndex.clone();this.slidesNav.push(slides);this.slidesNav=this.slidesNav.flatten();this.isTheLoop=true}else{this.isTheLoop=false}}});function defaultFx(currentSlide,slideToShowed,options){new Effect.Fade($(currentSlide),{duration:options.fxSpeed});new Effect.Appear($(slideToShowed),{duration:options.fxSpeed})}Element.findChildren=function(element,only,recursive,tagName){if(!element.hasChildNodes())return null;tagName=tagName.toUpperCase();if(only)only=[only].flatten();var elements=[];$A(element.childNodes).each(function(e){if(e.tagName&&e.tagName.toUpperCase()==tagName&&(!only||(Element.classNames(e).detect(function(v){return only.include(v)}))))elements.push(e);if(recursive){var grandchildren=Element.findChildren(e,only,recursive,tagName);if(grandchildren)elements.push(grandchildren)}});return(elements.length>0?elements.flatten():[])};function effet_fade(element){$(element).fade()}function effet_appear(element){$(element).appear()}function effet_slideDown(element){Effect.SlideDown(element)}function effet_slideUp(element){Effect.SlideUp(element)}function effet_parrallel(element){new Effect.Parallel([new Effect.Move(element,{sync:true,x:400,y:0,mode:'relative'}),new Effect.Opacity(element,{sync:true,from:0,to:1})],{duration:1.5})}