/* Generic image slideshow v1.0.2 Requires MooTools 1.2 or greater Author: Andrew Ferri Date: 19 October 2010 WARNING: This script lags when you have a large amount of images (> 50). Please use new version instead. Change log ********** 7 December 2010 - Added option to specify li containers 14 December 2010 - Added option for initial image to display 13 April 2011 - Fixed initial flicker of inactive images */ Slideshow = new Class({ Implements: [Options, Events], options: { duration: 600, interval: 4000, transition: Fx.Transitions.Sine.easeOut, direction: 'forward', autoplay: true, type: 'opacity', images: 'li', initial_image: 0 }, initialize: function(ul, options) { this.setOptions(options); this.ul = ul; this.images = this.ul.getChildren(this.options.images); this.active_index = this.options.initial_image; if (this.options.type == 'slider') { this.slider = new Fx.Scroll(ul.getParent()); } this.images.each(function(el, index){ el.set('morph', { duration: this.options.duration, transition: this.options.transition, link: 'cancel' }, this); if ((index != this.options.initial_image) && (this.options.type == 'opacity')) { el.get('morph').set({'opacity': 0.001}); } else { el.get('morph').set({'opacity': 1}); el.addClass('jsactive'); } el.addClass('active'); }, this); this.transitioning = false; this.status = 'paused'; if (this.options.autoplay == true) { this.play(); } }, next: function() { if (this.status == 'playing') { var cont = true; this.pause(); } else { var cont = false; } var index = this.active_index + 1; if (!this.images[index]) { index = 0; } this.slide(index); if (cont == true) { this.play(); } }, previous: function() { if (this.status == 'playing') { var cont = true; this.pause(); } else { var cont = false; } var index = this.active_index - 1; if (!this.images[index]) { index = this.images.length - 1; } this.slide(index); if (cont == true) { this.play(); } }, slide: function(index) { if ((index != this.active_index) && (this.transitioning == false)) { var ss = this; ss.transitioning = true; ss.next_index = index; var current = ss.images[ss.active_index]; var next = ss.images[index]; ss.position = 'sliding'; ss.fireEvent('start'); switch(ss.options.type) { case 'opacity': next.setStyle('z-index', '40'); current.get('morph').start({ 'opacity': 0.001 }); next.get('morph').start({ 'opacity': 1 }).chain(function(){ current.removeClass('jsactive'); next.addClass('jsactive'); next.setStyle('z-index', ''); ss.active_index = index; ss.position = 'complete'; ss.transitioning = false; ss.fireEvent('complete'); }); break; case 'slider': ss.slider.toElement(next); ss.active_index = index; ss.fireEvent('complete'); break; } } }, play: function() { this.period = this.next.periodical(this.options.interval, this); this.status = 'playing'; }, pause: function() { $clear(this.period); this.status = 'paused'; }, force_active: function(index) { this.images[this.active_index].get('morph').set({ 'opacity': 0.001 }) this.active_index = index; this.images[this.active_index].get('morph').set({ 'opacity': 1 }) } });