﻿var SL_Slider = new Class({ Implements: [Options], numNav: new Array(), timer: null, isSliding: 0, direction: 1, options: { slideTimer: 8000, orientation: "horizontal", fade: false, isPaused: false, transitionTime: 1100, transitionType: "cubic:out", container: null, items: null, itemNum: 0, numNavActive: false, numNavHolder: null, playBtn: null, prevBtn: null, nextBtn: null }, initialize: function(b) { var a = this; this.setOptions(b); a.options.container.setStyle("overflow", "hidden"); if (a.options.playBtn != null) { a.options.playBtn.set("text", "pause"); a.options.playBtn.addEvents({ click: function() { a.pauseIt() }, mouseenter: function() { this.setStyle("cursor", "pointer") }, mouseleave: function() { } }) } if (a.options.prevBtn && a.options.nextBtn) { a.options.prevBtn.addEvents({ click: function() { if (a.isSliding == 0) { if (a.options.isPaused == false) { $clear(a.timer); a.timer = a.slideIt.periodical(a.options.slideTimer, a, null) } a.direction = 0; a.slideIt() } }, mouseenter: function() { this.setStyle("cursor", "pointer") }, mouseleave: function() { } }); this.options.nextBtn.addEvents({ click: function() { if (a.isSliding == 0) { if (a.options.isPaused == false) { $clear(a.timer); a.timer = a.slideIt.periodical(a.options.slideTimer, a, null) } a.direction = 1; a.slideIt() } }, mouseenter: function() { this.setStyle("cursor", "pointer") }, mouseleave: function() { } }) } a.options.items.each(function(e, d) { e.setStyle("position", "absolute"); var c = e.getSize().y; var j = e.getSize().x; if (a.options.orientation == "vertical") { e.setStyle("top", (-1 * c)); e.setStyle("left", 0) } else { if (a.options.orientation == "none") { e.setStyle("left", 0); e.setStyle("top", 0); e.set("opacity", 0) } else { e.setStyle("left", (-1 * j)) } } if (a.options.numNavActive == true) { var h = new Element("li", { id: "num" + d }); var g = new Element("a", { "class": "numbtn", html: (d + 1) }); h.adopt(g); a.options.numNavHolder.adopt(h); a.numNav.push(g); g.set("morph", { duration: 100, transition: Fx.Transitions.linear, link: "ignore" }); g.addEvents({ click: function() { a.numPress(d) }, mouseenter: function() { this.setStyle("cursor", "pointer") } }); if (d == a.options.itemNum) { var f = a.numNav[d]; f.addClass("active") } } }) }, start: function() { var a = this; a.slideIt(a.options.itemNum); if (a.options.isPaused == false) { a.timer = a.slideIt.periodical(a.options.slideTimer, a, null); if (a.options.playBtn) { a.options.playBtn.set("text", "pause") } } else { if (a.options.playBtn) { a.options.playBtn.set("text", "play") } } }, slideIt: function(i) { var j = this; var l = j.options.items[j.options.itemNum]; if (j.options.numNavActive == true) { var h = j.numNav[j.options.itemNum] } if (i != null) { if (j.options.itemNum != i) { if (j.options.itemNum > i) { j.direction = 0 } else { j.direction = 1 } j.options.itemNum = i } } else { j.changeIndex() } var e = j.options.items[j.options.itemNum]; if (j.direction == 0) { var c = j.options.container.getSize().x; var a = (-1 * e.getSize().x); var b = j.options.container.getSize().y; var k = (-1 * e.getSize().y) } else { var c = (-1 * j.options.container.getSize().x); var a = e.getSize().x; var b = (-1 * j.options.container.getSize().y); var k = e.getSize().y } if (j.options.numNavActive == true) { var g = j.numNav[j.options.itemNum]; g.addClass("active") } var f = new Fx.Morph(e, { duration: j.options.transitionTime, transition: j.options.transitionType, link: "ignore", onStart: function() { j.isSliding = 1 }, onComplete: function() { j.isSliding = 0 } }); if (j.options.orientation == "vertical") { if (j.options.fade == true) { f.start({ opacity: [0, 1], top: [k, 0] }) } else { f.start({ top: [k, 0] }) } } else { if (j.options.orientation == "none") { f.start({ opacity: [0, 1] }) } else { if (j.options.fade == true) { f.start({ opacity: [0, 1], left: [a, 0] }) } else { f.start({ left: [a, 0] }) } } } if (l != e) { var d = new Fx.Morph(l, { duration: j.options.transitionTime, transition: j.options.transitionType, link: "ignore" }); if (j.options.numNavActive == true) { h.removeClass("active") } if (j.options.orientation == "vertical") { if (j.options.fade == true) { d.start({ opacity: [0], top: [(b)] }) } else { d.start({ top: [(b)] }) } } else { if (j.options.orientation == "none") { d.start({ opacity: [1, 0] }) } else { if (j.options.fade == true) { d.start({ opacity: [0], left: [(c)] }) } else { d.start({ left: [(c)] }) } } } } }, pauseIt: function() { var a = this; if (a.isSliding == 0) { if (a.options.isPaused == false) { a.options.isPaused = true; $clear(a.timer); a.options.playBtn.set("text", "play") } else { a.options.isPaused = false; a.slideIt(); a.timer = a.slideIt.periodical(a.options.slideTimer, this, null); a.options.playBtn.set("text", "pause") } } }, changeIndex: function() { var a = this; var b = a.options.items.length; if (a.direction == 1) { if (a.options.itemNum < (b - 1)) { a.options.itemNum++ } else { a.options.itemNum = 0 } } else { if (a.direction == 0) { if (a.options.itemNum > 0) { a.options.itemNum-- } else { a.options.itemNum = (b - 1) } } } }, numPress: function(b) { var a = this; if ((a.isSliding == 0) && (a.options.itemNum != b)) { if (a.options.isPaused == false) { $clear(a.timer); a.timer = a.slideIt.periodical(a.options.slideTimer, this, null) } a.slideIt(b) } } });