/*
 * jQuery xSlider
 * http://xslider.codapixa.com/
 * Version 1.0-beta1
 *
 * Copyright (c) 2011 Firman Wandayandi
 * Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
 */
(function (a) { a.fn.xslider = function (b) { if (typeof arguments[0] === "string") { switch (arguments[0]) { case "goto": if (typeof arguments[1] != "undefined") { a(this).data("xslider:instance").to(arguments[1]) } break; case "next": a(this).data("xslider:instance").next(); break; case "previous": a(this).data("xslider:instance").prev(); break; case "play": a(this).data("xslider:instance").play(); break; case "stop": a(this).data("xslider:instance").stop(); break; case "pause": a(this).data("xslider:instance").pause(); break; case "status": return a(this).data("xslider:instance").status(); break; case "refresh": a(this).data("xslider:instance").refresh(); break } return } return this.each(function () { var c = { settings: { children: null, width: null, height: null, effect: "slide", speed: "normal", order: "sequence", timeout: 3000, easing: null, navigation: null, prevNext: true, wrapperClass: "xslider", navigationClass: "xslider-nav", autoPlay: false, pauseOnHover: true, onLoaded: null, onBefore: null, onComplete: null }, container: null, timeout: null, current: 0, last: 0, state: null, items: function () { var d = this; if (d.settings.children) { return a(d.container).children() } else { return a(d.container).children(d.settings.children) } }, init: function (d, f) { var e = this; if (f) { a.extend(e.settings, f) } e.container = d; var g = e.items(); if (g.length == 0) { return } a(e.container).wrap(a("<div />").addClass(e.settings.wrapperClass)).wrap(a("<div />").addClass("xslider-container")); if (e.settings.order == "random") { e.last = Math.floor(Math.random() * g.length); do { e.current = Math.floor(Math.random() * g.length) } while (e.last == e.current) } else { if (e.settings.order == "random-start") { e.current = Math.floor(Math.random() * g.length); e.settings.order = "sequence" } else { if (e.settings.order != "sequence") { alert("xslider:order must either be 'sequence', 'random' or 'random-start'") } } } e.setup(false); a(e.container).css({ position: "relative", width: a(g[0]).width(), height: a(g[0]).height(), overflow: "hidden" }); if (e.settings.width != null) { a(e.container).css("width", e.settings.width) } e.navigation(); a(g[e.current]).fadeIn("normal", function () { e.onLoaded(e.current, e.last, a(g[e.current]), a(g[e.last]), g) }); a(e.container).data("xslider:playback", "standby"); if (e.settings.autoPlay) { e.play() } }, setup: function (e) { var d = this; a.each(d.items(), function (f, g) { if (e) { if (f != d.current && f != d.last) { a(g).css({ position: "absolute", top: 0, left: 0, display: "none" }) } } else { a(g).css({ position: "absolute", top: 0, left: 0, display: "none" }) } if (d.settings.effect == "fade") { a(g).css("z-index", d.items().length - f) } else { a(g).css("z-index", 0) } if (d.settings.autoPlay && d.settings.pauseOnHover) { a(g).unbind("mouseover.xslider").bind("mouseover.xslider", function () { d.stop() }).unbind("mouseout.xslider").bind("mouseout.xslider", function () { d.play() }) } }) }, navigation: function (j) { var f = this; if (f.settings.navigation == null) { return } var k = a(f.container).parents("." + f.settings.wrapperClass); if (!j && f.settings.prevNext) { var e = a('<div class="xslider-prevnext" />'); a('<a href="#xslider-prev" class="prev">Prev</a>').bind("click.xslider", function () { f.prev(); return false }).appendTo(e); a('<a href="#xslider-next" class="next">Next</a>').bind("click.xslider", function () { f.next(); return false }).appendTo(e); e.appendTo(k) } if (typeof (f.settings.navigation) == "object" && f.settings.navigation.jquery) { a("a", f.settings.navigation).each(function () { a(this).unbind("click.xslider").bind("click.xslider", function () { f.navigate(this); return false }) }); for (var h = 0; h < f.items().length; h++) { if (a("a[href=#xslider-" + h + "]", f.settings.navigation).length == 0) { var l = a("<li />"); a('<a href="#xslider-' + h + '">' + (h + 1) + "</a>").unbind("click.xslider").bind("click.xslider", function () { f.navigate(this); return false }).appendTo(l); l.appendTo(a("ul", f.settings.navigation)) } } } else { if (f.settings.navigation === true) { var d = a("<nav>").addClass(f.settings.navigationClass).appendTo(k); var g = a("<ul />"); for (var h = 0; h < f.items().length; h++) { var l = a("<li />"); a('<a href="#xslider-' + h + '">' + (h + 1) + "</a>").unbind("click.xslider").bind("click.xslider", function () { f.navigate(this); return false }).appendTo(l); l.appendTo(g) } g.appendTo(d); f.settings.navigation = d } } if (!j) { f.setNavigation() } }, navigate: function (e) { var d = a(e).attr("href").match(/#xslider-(\d+)/); if (d != null) { this.stop(); this.to(d[1]) } }, setNavigation: function (d) { if (!d) { d = this.current } if (this.settings.navigation != null) { a("a", this.settings.navigation).each(function () { var e = a(this).attr("href").match(/#xslider-(\d+)/); if (e != null && e[1] == d) { a(this).addClass("current") } else { a(this).removeClass("current") } }) } }, animate: function () { var d = this; var f = d.items(); d.onBefore(d.current, d.last, a(f[d.current]), a(f[d.last]), f); a(d.container).animate({ height: a(f[d.current]).height(), width: a(f[d.current]).width() }, d.settings.speed); if (d.settings.effect == "slide") { var e = a(d.container).width(); a(f[d.current]).css({ left: e, display: "", "z-index": f.length }); a(f[d.last]).animate({ left: -e }, d.settings.speed, d.settings.easing, function () { a(this).css({ left: 0, "z-index": 0, display: "none" }) }); a(f[d.current]).animate({ left: 0 }, d.settings.speed, d.settings.easing, function () { d.onComplete(d.current, d.last, a(f[d.current]), a(f[d.last]), f) }) } else { if (d.settings.effect == "roll") { a(f[d.current]).css({ top: -a(f[d.last]).outerHeight(), display: "", "z-index": f.length }); a(f[d.last]).animate({ top: a(f[d.current]).outerHeight() }, d.settings.speed, d.settings.easing, function () { a(this).css({ left: 0, "z-index": 0, display: "none" }) }); a(f[d.current]).animate({ top: 0 }, d.settings.speed, d.settings.easing, function () { d.onComplete(d.current, d.last, a(f[d.current]), a(f[d.last]), f) }) } else { if (d.settings.effect == "fall") { a(f[d.last]).css({ "z-index": 0 }); a(f[d.current]).css({ top: -a(f[d.current]).outerHeight(), display: "", "z-index": 1 }); a(f[d.last]).fadeOut(d.settings.speed); a(f[d.current]).animate({ top: 0 }, d.settings.speed, d.settings.easing, function () { d.onComplete(d.current, d.last, a(f[d.current]), a(f[d.last]), f) }) } else { if (d.settings.effect == "fade") { a(f[d.last]).fadeOut(d.settings.speed); a(f[d.current]).fadeIn(d.settings.speed, function () { removeFilter(a(this)[0]); d.onComplete(d.current, d.last, a(f[d.current]), a(f[d.last]), f) }) } else { alert("xslider:effect must either be 'slide', 'roll', 'fall' or 'fade'") } } } } d.setNavigation() }, to: function (e) { var d = this; if (typeof (e) == "object" && e.jquery) { if (e.length == 0) { return false } a.each(d.items(), function (f) { if (a(this)[0] == e[0]) { e = f } }) } if (d.current == e) { return } d.last = d.current; d.current = parseInt(e); d.animate() }, next: function () { var d = this; var e = d.current; if (d.settings.order == "random") { while (e == d.current) { e = Math.floor(Math.random() * d.items().length) } } else { e++; if (e > this.items().length - 1) { e = 0 } } this.to(e) }, prev: function () { var d = this; var e = d.current; if (d.settings.order == "random") { while (e == d.current) { e = Math.floor(Math.random() * d.items().length) } } else { e--; if (e < 0) { e = d.items().length - 1 } } this.to(e) }, play: function () { var d = this; a(d.container).data("xslider:playback", "play"); timeout = setInterval(function () { d.next() }, d.settings.timeout); a(d.container).data("xslider:timeout", timeout) }, stop: function () { var d = this; clearInterval(a(d.container).data("xslider:timeout")); a(d.container).data("xslider:playback", "stop") }, pause: function () { var d = this; clearInterval(a(d.container).data("xslider:timeout")); a(d.container).data("xslider:playback", "pause"); if (d.settings.autoPlay) { d.play() } }, status: function () { var d = this; return { state: a(d.container).data("xslider:playback"), current: d.current, last: d.last} }, refresh: function () { var d = this; var e = d.items(); d.setup(true); d.navigation(true) }, onLoaded: function (h, f, d, e, g) { if (typeof (this.settings.onLoaded) == "function") { this.settings.onLoaded(h, f, d, e, g) } }, onBefore: function (h, f, d, e, g) { if (typeof (this.settings.onBefore) == "function") { this.settings.onBefore(h, f, d, e, g) } }, onComplete: function (h, f, d, e, g) { if (typeof (this.settings.onComplete) == "function") { this.settings.onComplete(h, f, d, e, g) } } }; c.init(this, b); a(this).data("xslider:instance", c) }) } })(jQuery); function removeFilter(a) { if (a.style.removeAttribute) { a.style.removeAttribute("filter") } };
