var iCarousel = new Class({ options: { animation: { direction: "left",// if type = scroll, set: top || left todisplay: 3, amount: 1,// if type = scroll, set the amount to scroll transition: Fx.Transitions.Cubic.easeInOut, duration: 500, position: 1 }, item: { klass: "carousel_item", size: 300 }, idPrevious: "carousel_previous", idNext: "carousel_news" }, initialize: function(container, options) { this.setOptions(options); this.container = $(container); this.aItems = $A($$('.'+ this.options.item.klass)); this.isMouseOver = false; if(this.options.idPrevious != "undefined" && $(this.options.idPrevious)) $(this.options.idPrevious).addEvent("click", function(event) { new Event(event).stop(); this._previous(); this.fireEvent("onClickPrevious", this, 20); }.bind(this));// check if value is not "undefined" before start search the dom with $() if(this.options.idNext != "undefined" && $(this.options.idNext)) $(this.options.idNext).addEvent("click", function(event) { new Event(event).stop(); this._next(); this.fireEvent("onClickNext", this, 20); }.bind(this)); var oAn = this.options.animation; // short hand this.aItems.each(function(item) { item.clone().injectInside(this.container); }.bind(this)); this.fx = this.container.effects({duration: oAn.duration, transition: oAn.transition, wait: false}); this.atScreen = this.aItems.length; this.container.setStyle(oAn.direction, - this.atScreen * this.options.item.size); document.getElementById(this.options.idPrevious).src = "/images/iCarousel/previous_disabled.jpg"; if ((this.options.animation.position + this.options.animation.todisplay) > this.aItems.length ) { document.getElementById(this.options.idNext).src = "/images/iCarousel/next_disabled.jpg"; } for (i=1;i<4;i++){ this._next(); //pour avancer la position du carrousel ! } }, _previous: function() { if (this.options.animation.position > this.options.animation.amount) { this.options.animation.position = this.options.animation.position - this.options.animation.amount; this.atScreen -= this.options.animation.amount; this._animate(this.atScreen); document.getElementById(this.options.idNext).src = "/images/iCarousel/next.jpg"; if (!(this.options.animation.position > this.options.animation.amount)) { document.getElementById(this.options.idPrevious).src = "/images/iCarousel/previous_disabled.jpg"; } } this.fireEvent("onPrevious", this, 20); }, _next: function() { if ((this.options.animation.position + this.options.animation.todisplay) <= this.aItems.length ) { this.options.animation.position = this.options.animation.position + this.options.animation.amount; this.atScreen += this.options.animation.amount; this._animate(this.atScreen); document.getElementById(this.options.idPrevious).src = "/images/iCarousel/previous.jpg"; if ((this.options.animation.position + this.options.animation.todisplay) > this.aItems.length ) { document.getElementById(this.options.idNext).src = "/images/iCarousel/next_disabled.jpg"; } } this.fireEvent("onNext", this, 20); }, _animate: function(a, b) { var that = this; if(that.options.animation.direction == "top") { that.fx.start({"top" : - a * that.options.item.size}); } else { that.fx.start({"left" : - a * that.options.item.size}); } } }); iCarousel.implement(new Events); // Implements addEvent(type, fn), fireEvent(type, [args], delay) and removeEvent(type, fn) iCarousel.implement(new Options);// Implements setOptions(defaults, options)