var YOOcarousel = new Class({ initialize: function (container, options) { this.setOptions({ onRotate: Class.empty, onStop: Class.empty, onAutoPlay: Class.empty, onShowSlide: Class.empty, panelSelector: '.panel', slidesSelector: '.slide', buttonsSelector: '.button', buttonNextSelector: '.button-next', buttonPrevSelector: '.button-prev', slideInterval: 4000, transitionDuration: 700, transitionEffect: 'scroll', startIndex: 0, buttonOnClass: 'selected', buttonOffClass: 'off', rotateAction: 'none', rotateActionDuration: 100, rotateActionEffect: 'scroll', autoplay: 'on' }, options); this.container = $(container); this.pausepanel = this.container.getElement('.pausebutton'); this.playpanel = this.container.getElement('.playbuttonon'); this.forwardpanel = this.container.getElement('.forwardbutton'); this.backpanel = this.container.getElement('.backbutton'); this.panel = this.container.getElement(this.options.panelSelector); this.slides = this.container.getElements(this.options.slidesSelector); this.buttons = this.container.getElements(this.options.buttonsSelector); this.buttonNext = this.container.getElement(this.options.buttonNextSelector); this.buttonPrev = this.container.getElement(this.options.buttonPrevSelector); this.currentSlide = null; this.pausepanel.addEvent('click', function () { this.pause(); }.bind(this)); this.playpanel.addEvent('click', function () { this.play(); }.bind(this)); this.forwardpanel.addEvent('click', function () { this.forward(); }.bind(this)); this.backpanel.addEvent('click', function () { this.back(); }.bind(this)); this.backpanel.addEvent('mousedown', function () { this.backDown(); }.bind(this)); this.backpanel.addEvent('mouseup', function () { this.backUp(); }.bind(this)); this.forwardpanel.addEvent('mousedown', function () { this.forwardDown(); }.bind(this)); this.forwardpanel.addEvent('mouseup', function () { this.forwardUp(); }.bind(this)); if (this.options.transitionEffect == 'crossfade' || this.options.rotateActionEffect == 'crossfade') { this.fxCrossfade = new Array(); this.slides.each(function (el, i) { this.fxCrossfade[i] = new Fx.Style(el, 'opacity'); if (i != this.options.startIndex) el.setStyle('opacity', 0) }, this); this.options.transitionEffect = 'crossfade'; this.options.rotateActionEffect = 'crossfade' } else { this.fxScroll = new Fx.Scroll(this.panel, { 'wait': false }); this.fxFade = new Fx.Style(this.panel, 'opacity', { 'wait': false }) } this.setupButtons(); this.showSlide(this.options.startIndex, 1); if (this.options.autoplay == 'on' || this.options.autoplay == 'once') this.autoplay() }, setupButtons: function () { if (this.options.rotateAction != 'none') { var timer = null; this.buttons.each(function (el, i) { $(el).addEvent(this.options.rotateAction, function () { if (this.options.rotateActionEffect == 'scroll') { this.showSlide(i, this.options.rotateActionDuration, this.options.rotateActionEffect) } else { $clear(timer); timer = this.showSlide.delay(this.options.rotateActionDuration, this, [i, this.options.rotateActionDuration, this.options.rotateActionEffect]) } this.stop() }.bind(this)) }, this) } if (this.buttonNext && this.buttonPrev) { this.buttonNext.addEvent('click', function () { if (this.currentSlide + 1 >= this.slides.length) { next = 0 } else { next = this.currentSlide + 1 }; this.showSlide(next, this.options.rotateActionDuration, this.options.rotateActionEffect); this.stop() }.bind(this)); this.buttonPrev.addEvent('click', function () { if (this.currentSlide - 1 < 0) { next = this.slides.length - 1 } else { next = this.currentSlide - 1 }; this.showSlide(next, this.options.rotateActionDuration, this.options.rotateActionEffect); this.stop() }.bind(this)) } }, showSlide: function (index, duration, transition) { if (index == this.currentSlide) return; this.slides.each(function (slide, i) { var button = $(this.buttons[i]); if (i == index && i != this.currentSlide) { if (button) button.removeClass(this.options.buttonOffClass).addClass(this.options.buttonOnClass) } else { if (button) button.removeClass(this.options.buttonOnClass).addClass(this.options.buttonOffClass) } }, this); switch (transition) { case 'fade': this.fxFade.setOptions({ 'duration': duration }); this.fxFade.start(1, 0.01).chain(function () { this.fxScroll.setOptions({ 'duration': 1 }); this.fxScroll.toElement(this.slides[index]); this.fxFade.start(0.01, 1) }.bind(this)); break; case 'crossfade': this.slides.each(function (el, i) { this.fxCrossfade[i].setOptions({ 'duration': duration }); if (i == index) { this.fxCrossfade[i].start(1) } else if (el.getStyle('opacity') > 0) { this.fxCrossfade[i].start(0) } }, this); break; case 'scroll': this.fxScroll.setOptions({ 'duration': duration }); this.fxScroll.toElement(this.slides[index]) } this.currentSlide = index; this.fireEvent('onShowSlide', index) }, rotate: function () { if (this.currentSlide + 1 >= this.slides.length) { next = 0 } else { next = this.currentSlide + 1 }; if (this.options.autoplay == 'once' && next == 0) { this.stop(); return }; this.showSlide(next, this.options.transitionDuration, this.options.transitionEffect); this.fireEvent('onRotate') }, autoplay: function () { this.slideshowInt = this.rotate.periodical(this.options.slideInterval, this); this.fireEvent('onAutoPlay') }, stop: function () { clearInterval(this.slideshowInt); this.fireEvent('onStop') }, pauseplay: function () { if (this.options.autoplay == 'on') { this.options.autoplay = 'off'; this.stop(); } else { this.options.autoplay = 'on'; this.autoplay(); this.fireEvent('onAutoPlay'); } return; }, pause: function () { this.pausepanel.removeClass('pausebutton').addClass('pausebuttonon') this.playpanel.removeClass('playbuttonon').addClass('playbutton') this.options.autoplay = 'off'; this.stop(); return; }, play: function () { if (this.options.autoplay == 'off') { this.pausepanel.removeClass('pausebuttonon').addClass('pausebutton') this.playpanel.removeClass('playbutton').addClass('playbuttonon') this.options.autoplay = 'on'; this.autoplay(); this.fireEvent('onAutoPlay'); } return; }, forward: function () { this.pausepanel.removeClass('pausebutton').addClass('pausebuttonon') this.playpanel.removeClass('playbuttonon').addClass('playbutton') this.options.autoplay = 'off'; this.stop(); if (this.currentSlide + 1 >= this.slides.length) { next = 0 } else { next = this.currentSlide + 1 }; this.showSlide(next, this.options.transitionDuration, this.options.transitionEffect); this.fireEvent('onRotate'); return; }, back: function () { this.pausepanel.removeClass('pausebutton').addClass('pausebuttonon') this.playpanel.removeClass('playbuttonon').addClass('playbutton') this.options.autoplay = 'off'; this.stop(); if (this.currentSlide - 1 < 0) { next = this.slides.length - 1; } else { next = this.currentSlide - 1; }; this.showSlide(next, this.options.transitionDuration, this.options.transitionEffect); this.fireEvent('onRotate'); return; }, backDown: function () { this.backpanel.removeClass('backbutton').addClass('backonbutton') return; }, backUp: function () { this.backpanel.removeClass('backonbutton').addClass('backbutton') return; }, forwardDown: function () { this.forwardpanel.removeClass('forwardbutton').addClass('forwardonbutton') return; }, forwardUp: function () { this.forwardpanel.removeClass('forwardonbutton').addClass('forwardbutton') return; } }); YOOcarousel.implement(new Options); YOOcarousel.implement(new Events);