// iCarousel is an open source (free) javascript tool for creating carousel like widgets. Copyright (c) 2007 Fabio Zendhi Nagao, http://zend.lojcomm.com.br/icarousel/, MIT Style License. var iCarousel = new Class({ options: { animation: { type: "scroll", direction: "left", amount: 1, transition: Fx.Transitions.Cubic.easeInOut, duration: 500, rotate: { type: "manual", interval: 5000, onMouseOver: "stop" } }, item: { klass: "item", size: 100 }, idPrevious: "previous", idNext: "next", idToggle: "toggle" }, initialize: function (_1, _2) { this.setOptions(_2); this.container = $(_1); this.aItems = $A($$("." + this.options.item.klass)); this.isMouseOver = false; if (this.options.idPrevious != "undefined" && $(this.options.idPrevious)) { $(this.options.idPrevious).addEvent("click", function (_3) { new Event(_3).stop(); this._previous() }.bind(this)) } if (this.options.idNext != "undefined" && $(this.options.idNext)) { $(this.options.idNext).addEvent("click", function (_4) { new Event(_4).stop(); this._next() }.bind(this)) } if (this.options.idToggle != "undefined" && $(this.options.idToggle)) { $(this.options.idToggle).addEvent("click", function (_5) { new Event(_5).stop(); this._toggle() }.bind(this)) } var _6 = this.options.animation; switch (this.options.animation.type.toLowerCase()) { case "fade": this.aItems.each(function (_7) { _7.fx = _7.effect("opacity", { duration: _6.duration, transition: _6.transition }); _7.setStyle("opacity", 0); _7.addEvents({ "mouseenter": function () { this.isMouseOver = true }.bind(this), "mouseleave": function () { this.isMouseOver = false }.bind(this) }) }.bind(this)); this.height = this.container.getStyle("height").toInt(); this.atScreen = 0; this._animate(this.atScreen); break; case "scroll": (2).times(function () { this.aItems.each(function (_8) { _8.clone().injectInside(this.container) }.bind(this)) }.bind(this)); this.aItems = $A($$("." + this.options.item.klass)); this.aItems.each(function (_9) { _9.addEvents({ "mouseenter": function () { this.isMouseOver = true }.bind(this), "mouseleave": function () { this.isMouseOver = false }.bind(this) }) }.bind(this)); this.fx = this.container.effects({ duration: _6.duration, transition: _6.transition, wait: false }); this.atScreen = this.aItems.length / 3; this.container.setStyle(_6.direction, -this.atScreen * this.options.item.size); break } if (this.options.animation.rotate.type == "auto") { this._autoRotate.periodical(this.options.animation.rotate.interval, this) } }, _previous: function () { switch (this.options.animation.type.toLowerCase()) { case "fade": var _a = this.atScreen; this.atScreen -= this.options.animation.amount; if (this.atScreen < 0) { this.atScreen = (this.aItems.length - 1) } this._animate(this.atScreen, _a); break; case "scroll": this.atScreen -= this.options.animation.amount; if (this.atScreen < this.aItems.length / 3) { this.container.setStyle(this.options.animation.direction, -this.options.item.size * this.aItems.length * 2 / 3); this.atScreen = this.aItems.length * 2 / 3 - this.options.animation.amount } this._animate(this.atScreen); break } }, _next: function () { switch (this.options.animation.type.toLowerCase()) { case "fade": var _b = this.atScreen; this.atScreen += this.options.animation.amount; if (this.atScreen >= this.aItems.length) { this.atScreen = 0 } this._animate(this.atScreen, _b); break; case "scroll": this.atScreen += this.options.animation.amount; if (this.atScreen > this.aItems.length * 2 / 3) { this.container.setStyle(this.options.animation.direction, -this.options.item.size * this.aItems.length / 3); this.atScreen = this.aItems.length / 3 + this.options.animation.amount } this._animate(this.atScreen); break } }, _toggle: function () { (this.container.getStyle("height").toInt() == 0) ? this.container.effect("height", { duration: 1000, transition: Fx.Transitions.Sine.easeInOut }).start(this.height) : this.container.effect("height", { duration: 1000, transition: Fx.Transitions.Sine.easeInOut }).start(0) }, _autoRotate: function () { if (this.options.animation.rotate.onMouseOver == "stop" && !this.isMouseOver) { this._next() } }, _animate: function (a, b) { switch (this.options.animation.type) { case "fade": if ($defined(b)) { this.aItems[b].fx.start(0).chain(function () { this.aItems[a].fx.start(1) }.bind(this)) } else { this.aItems[a].fx.start(1) } break; case "scroll": var _e = this; if (_e.options.animation.direction == "top") { _e.fx.start({ "opacity": 0.75 }).chain(function () { _e.fx.start({ "top": -a * _e.options.item.size }).chain(function () { _e.fx.start({ "opacity": 1 }) }) }) } else { _e.fx.start({ "opacity": 0.75 }).chain(function () { _e.fx.start({ "left": -a * _e.options.item.size }).chain(function () { _e.fx.start({ "opacity": 1 }) }) }) } break } } }); iCarousel.implement(new Options);