var noobSlide = new Class({ initialize: function(b) { this.items = b.items; this.mode = b.mode || "horizontal"; this.fade = b.fade || false; this.modes = { horizontal: ["left", "width"], vertical: ["top", "height"] }; this.size = b.size || 240; this.box = b.box.setStyle(this.modes[this.mode][1], (this.size * this.items.length) + "px"); this.button_event = b.button_event || "click"; this.handle_event = b.handle_event || "click"; this.onWalk = b.onWalk || null; this.currentIndex = null; this.previousIndex = null; this.nextIndex = null; this.interval = b.interval || 5000; this.autoPlay = b.autoPlay || false; this._play = null; this.handles = b.handles || null; if (this.handles) { this.addHandleButtons(this.handles) } this.buttons = { previous: [], next: [], play: [], playback: [], stop: [] }; if (b.addButtons) { for (var a in b.addButtons) { this.addActionButtons(a, $type(b.addButtons[a]) == "array" ? b.addButtons[a] : [b.addButtons[a]]) } } if (this.fade) { this.orderItems(); this.fading((b.startItem || 0), true, true) } else { this.fx = new Fx.Tween(this.box, $extend((b.fxOptions || { duration: 500, wait: false }), { property: this.modes[this.mode][0] })); this.walk((b.startItem || 0), true, true) } }, orderItems: function() { for (i = 0; i < this.items.length; i++) { this.items[i].setStyle("position", "absolute"); this.items[i].setStyle("left", "0px"); this.items[i].setStyle("z-index", i + 1); if (i > 0) { this.items[i].fade("out") } } }, addHandleButtons: function(b) { for (var a = 0; a < b.length; a++) { if (this.fade) { b[a].addEvent(this.handle_event, this.fading.bind(this, [a, true])) } else { b[a].addEvent(this.handle_event, this.walk.bind(this, [a, true])) } } }, addActionButtons: function(c, b) { for (var a = 0; a < b.length; a++) { switch (c) { case "previous": b[a].addEvent(this.button_event, this.previous.bind(this, [true])); break; case "next": b[a].addEvent(this.button_event, this.next.bind(this, [true])); break; case "play": b[a].addEvent(this.button_event, this.play.bind(this, [this.interval, "next", false])); break; case "playback": b[a].addEvent(this.button_event, this.play.bind(this, [this.interval, "previous", false])); break; case "stop": b[a].addEvent(this.button_event, this.stop.bind(this)); break } this.buttons[c].push(b[a]) } }, previous: function(a) { if (this.fade) { this.fading((this.currentIndex > 0 ? this.currentIndex - 1 : this.items.length - 1), a) } else { this.walk((this.currentIndex > 0 ? this.currentIndex - 1 : this.items.length - 1), a) } }, next: function(a) { if (this.fade) { this.fading((this.currentIndex < this.items.length - 1 ? this.currentIndex + 1 : 0), a) } else { this.walk((this.currentIndex < this.items.length - 1 ? this.currentIndex + 1 : 0), a) } }, play: function(a, c, b) { this.stop(); if (!b) { this[c](false) } this._play = this[c].periodical(a, this, [false]) }, stop: function() { $clear(this._play) }, walk: function(c, b, a) { if (c != this.currentIndex) { this.currentIndex = c; this.previousIndex = this.currentIndex + (this.currentIndex > 0 ? -1 : this.items.length - 1); this.nextIndex = this.currentIndex + (this.currentIndex < this.items.length - 1 ? 1 : 1 - this.items.length); if (b) { this.stop() } if (a) { this.fx.cancel().set((this.size * -this.currentIndex) + "px") } else { this.fx.start(this.size * -this.currentIndex) } if (b && this.autoPlay) { this.play(this.interval, "next", true) } if (this.onWalk) { this.onWalk((this.items[this.currentIndex] || null), (this.handles && this.handles[this.currentIndex] ? this.handles[this.currentIndex] : null)) } } }, fading: function(c, b, a) { if (c != this.currentIndex) { this.lastIndex = this.currentIndex; this.currentIndex = c; this.previousIndex = this.currentIndex + (this.currentIndex > 0 ? -1 : this.items.length - 1); this.nextIndex = this.currentIndex + (this.currentIndex < this.items.length - 1 ? 1 : 1 - this.items.length); if (b) { this.stop() } if (!a) { this.items[this.lastIndex].fade("out"); this.items[this.currentIndex].fade("in") } if (b && this.autoPlay) { this.play(this.interval, "next", true) } if (this.onWalk) { this.onWalk((this.items[this.currentIndex] || null), (this.handles && this.handles[this.currentIndex] ? this.handles[this.currentIndex] : null)) } } } });