﻿(function (a) { a.anythingSlider = function (b, c) { var d = this, e; d.el = b; d.$el = a(b).addClass("anythingBase").wrap('<div class="anythingSlider"><div class="anythingWindow" /></div>'); d.$el.data("AnythingSlider", d); d.init = function () { d.options = e = a.extend({}, a.anythingSlider.defaults, c); d.initialized = false; if (a.isFunction(e.onBeforeInitialize)) { d.$el.bind("before_initialize", e.onBeforeInitialize) } d.$el.trigger("before_initialize", d); d.$wrapper = d.$el.parent().closest("div.anythingSlider").addClass("anythingSlider-" + e.theme); d.$window = d.$el.closest("div.anythingWindow"); d.win = window; d.$win = a(d.win); d.$controls = a('<div class="anythingControls"></div>').appendTo(e.appendControlsTo !== null && a(e.appendControlsTo).length ? a(e.appendControlsTo) : d.$wrapper); d.$startStop = a('<a href="#" class="start-stop"></a>'); if (e.buildStartStop) { d.$startStop.appendTo(e.appendStartStopTo !== null && a(e.appendStartStopTo).length ? a(e.appendStartStopTo) : d.$controls) } d.$nav = a('<ul class="thumbNav" />').appendTo(e.appendNavigationTo !== null && a(e.appendNavigationTo).length ? a(e.appendNavigationTo) : d.$controls); d.flag = false; d.playing = e.autoPlay; d.slideshow = false; d.hovered = false; d.panelSize = []; d.currentPage = e.startPanel = parseInt(e.startPanel, 10) || 1; e.changeBy = parseInt(e.changeBy, 10) || 1; d.adj = e.infiniteSlides ? 0 : 1; d.width = d.$el.width(); d.height = d.$el.height(); d.outerPad = [d.$wrapper.innerWidth() - d.$wrapper.width(), d.$wrapper.innerHeight() - d.$wrapper.height()]; if (e.playRtl) { d.$wrapper.addClass("rtl") } if (e.expand) { d.$outer = d.$wrapper.parent(); d.$window.css({ width: "100%", height: "100%" }); d.checkResize() } if (e.buildStartStop) { d.buildAutoPlay() } if (e.buildArrows) { d.buildNextBackButtons() } if (!e.autoPlay) { e.autoPlayLocked = false } d.updateSlider(); d.$lastPage = d.$currentPage; d.runTimes = a("div.anythingSlider").index(d.$wrapper) + 1; d.regex = new RegExp("panel" + d.runTimes + "-(\\d+)", "i"); if (d.runTimes === 1) { d.makeActive() } if (!a.isFunction(a.easing[e.easing])) { e.easing = "swing" } if (e.pauseOnHover) { d.$wrapper.hover(function () { if (d.playing) { d.$el.trigger("slideshow_paused", d); d.clearTimer(true) } }, function () { if (d.playing) { d.$el.trigger("slideshow_unpaused", d); d.startStop(d.playing, true) } }) } d.setCurrentPage(d.gotoHash() || e.startPage, false); d.slideControls(false); d.$wrapper.bind("mouseenter mouseleave", function (a) { d.hovered = a.type === "mouseenter" ? true : false; d.slideControls(d.hovered, false) }); a(document).keyup(function (a) { if (e.enableKeyboard && d.$wrapper.is(".activeSlider") && !a.target.tagName.match("TEXTAREA|INPUT|SELECT")) { if (!e.vertical && (a.which === 38 || a.which === 40)) { return } switch (a.which) { case 39: case 40: d.goForward(); break; case 37: case 38: d.goBack(); break } } }); d.$items.delegate("a", "focus.AnythingSlider", function (b) { var c = a(this).closest(".panel"), f = d.$items.index(c) + d.adj; d.$items.find(".focusedLink").removeClass("focusedLink"); a(this).addClass("focusedLink"); d.$window.scrollLeft(0); if (f >= d.currentPage + e.showMultiple || f < d.currentPage) { d.gotoPage(f); b.preventDefault() } }); var b = "slideshow_paused slideshow_unpaused slide_init slide_begin slideshow_stop slideshow_start initialized swf_completed".split(" "); a.each("onShowPause onShowUnpause onSlideInit onSlideBegin onShowStop onShowStart onInitialized onSWFComplete".split(" "), function (c, f) { if (a.isFunction(e[f])) { d.$el.bind(b[c], e[f]) } }); if (a.isFunction(e.onSlideComplete)) { d.$el.bind("slide_complete", function () { setTimeout(function () { e.onSlideComplete(d) }, 0) }) } d.initialized = true; d.$el.trigger("initialized", d); d.startStop(d.playing) }; d.updateSlider = function () { d.$el.children(".cloned").remove(); d.$nav.empty(); d.currentPage = d.currentPage || 1; d.$items = d.$el.children(); d.pages = d.$items.length; d.dir = e.vertical ? "top" : "left"; e.showMultiple = e.vertical ? 1 : parseInt(e.showMultiple, 10) || 1; if (e.showMultiple > 1) { if (e.showMultiple > d.pages) { e.showMultiple = d.pages } d.adjustMultiple = e.infiniteSlides && d.pages > 1 ? 0 : e.showMultiple - 1; d.pages = d.$items.length - d.adjustMultiple } d.$controls.add(d.$nav).add(d.$startStop).add(d.$forward).add(d.$back)[d.pages <= 1 ? "hide" : "show"](); if (d.pages > 1) { d.buildNavigation() } if (e.infiniteSlides && d.pages > 1) { d.$el.prepend(d.$items.filter(":last").clone().removeAttr("id").addClass("cloned")); if (e.showMultiple > 1) { d.$el.append(d.$items.filter(":lt(" + e.showMultiple + ")").clone().removeAttr("id").addClass("cloned").addClass("multiple")) } else { d.$el.append(d.$items.filter(":first").clone().removeAttr("id").addClass("cloned")) } d.$el.find(".cloned").each(function () { a(this).find("a,input,textarea,select,button,area").attr("disabled", "disabled"); a(this).find("[id]").removeAttr("id") }) } d.$items = d.$el.children().addClass("panel" + (e.vertical ? " vertical" : "")); d.setDimensions(); if (e.resizeContents) { d.$items.css("width", d.width); d.$wrapper.css("width", d.getDim(d.currentPage)[0]); d.$wrapper.add(d.$items).css("height", d.height) } else { d.$win.load(function () { d.setDimensions() }) } if (d.currentPage > d.pages) { d.currentPage = d.pages } d.setCurrentPage(d.currentPage, false); d.$nav.find("a").eq(d.currentPage - 1).addClass("cur") }; d.buildNavigation = function () { if (e.buildNavigation && d.pages > 1) { var b, c; d.$items.filter(":not(.cloned)").each(function (f) { var g = f + 1; b = (g === 1 ? "first" : "") + (g === d.pages ? "last" : ""); c = a('<a href="#"></a>').addClass("panel" + g).wrap('<li class="' + b + '" />'); d.$nav.append(c.parent()); if (a.isFunction(e.navigationFormatter)) { b = e.navigationFormatter(g, a(this)); c.html("<span>" + b + "</span>"); if (parseInt(c.find("span").css("text-indent"), 10) < 0) { c.addClass(e.tooltipClass).attr("title", b) } } else { c.html("<span>" + g + "</span>") } c.bind(e.clickControls, function (a) { if (!d.flag && e.enableNavigation) { d.flag = true; setTimeout(function () { d.flag = false }, 100); d.gotoPage(g); if (e.hashTags) { d.setHash(g) } } a.preventDefault() }) }); if (e.navigationSize !== false && parseInt(e.navigationSize, 10) < d.pages) { if (!d.$controls.find(".anythingNavWindow").length) { d.$nav.before('<ul><li class="prev"><a href="#"><span>' + e.backText + "</span></a></li></ul>").after('<ul><li class="next"><a href="#"><span>' + e.forwardText + "</span></a></li></ul>").wrap('<div class="anythingNavWindow"></div>') } d.navWidths = d.$nav.find("li").map(function () { return a(this).innerWidth() + Math.ceil(parseInt(a(this).find("span").css("left"), 10) / 2 || 0) }).get(); d.navLeft = 1; d.$nav.width(d.navWidth(1, d.pages + 1) + 5); d.$controls.find(".anythingNavWindow").width(d.navWidth(1, e.navigationSize + 1)).end().find(".prev,.next").bind(e.clickControls, function (b) { if (!d.flag) { d.flag = true; setTimeout(function () { d.flag = false }, 200); d.navWindow(d.navLeft + e.navigationSize * (a(this).is(".prev") ? -1 : 1)) } b.preventDefault() }) } } }; d.navWidth = function (a, b) { var c, e = Math.min(a, b), f = Math.max(a, b), g = 0; for (c = e; c < f; c++) { g += d.navWidths[c - 1] || 0 } return g }; d.navWindow = function (a) { var b = d.pages - e.navigationSize + 1; a = a <= 1 ? 1 : a > 1 && a < b ? a : b; if (a !== d.navLeft) { d.$controls.find(".anythingNavWindow").animate({ scrollLeft: d.navWidth(1, a), width: d.navWidth(a, a + e.navigationSize) }, { queue: false, duration: e.animationTime }); d.navLeft = a } }; d.buildNextBackButtons = function () { d.$forward = a('<span class="arrow forward"><a href="#"><span>' + e.forwardText + "</span></a></span>"); d.$back = a('<span class="arrow back"><a href="#"><span>' + e.backText + "</span></a></span>"); d.$back.bind(e.clickBackArrow, function (a) { if (e.enableArrows && !d.flag) { d.flag = true; setTimeout(function () { d.flag = false }, 100); d.goBack() } a.preventDefault() }); d.$forward.bind(e.clickForwardArrow, function (a) { if (e.enableArrows && !d.flag) { d.flag = true; setTimeout(function () { d.flag = false }, 100); d.goForward() } a.preventDefault() }); d.$back.add(d.$forward).find("a").bind("focusin focusout", function () { a(this).toggleClass("hover") }); d.$back.appendTo(e.appendBackTo !== null && a(e.appendBackTo).length ? a(e.appendBackTo) : d.$wrapper); d.$forward.appendTo(e.appendForwardTo !== null && a(e.appendForwardTo).length ? a(e.appendForwardTo) : d.$wrapper); d.$arrowWidth = d.$forward.width() }; d.buildAutoPlay = function () { d.$startStop.html("<span>" + (d.playing ? e.stopText : e.startText) + "</span>").bind(e.clickSlideshow, function (a) { if (e.enableStartStop) { d.startStop(!d.playing); d.makeActive(); if (d.playing && !e.autoPlayDelayed) { d.goForward(true) } } a.preventDefault() }).bind("focusin focusout", function () { a(this).toggleClass("hover") }) }; d.checkResize = function (a) { clearTimeout(d.resizeTimer); d.resizeTimer = setTimeout(function () { var b = d.$outer.width() - d.outerPad[0], c = (d.$outer[0].tagName === "BODY" ? d.$win.height() : d.$outer.height()) - d.outerPad[1]; if (d.width * e.showMultiple !== b || d.height !== c) { d.setDimensions(); d.gotoPage(d.currentPage, d.playing, null, -1) } if (typeof a === "undefined") { d.checkResize() } }, 500) }; d.setDimensions = function () { var b, c, f, g = 0, h = { width: "100%", height: "100%" }, i = e.showMultiple > 1 ? d.width || d.$window.width() / e.showMultiple : d.$window.width(), j = d.$win.width(); if (e.expand) { b = d.$outer.width() - d.outerPad[0]; d.height = c = d.$outer.height() - d.outerPad[1]; d.$wrapper.add(d.$window).add(d.$items).css({ width: b, height: c }); d.width = i = e.showMultiple > 1 ? b / e.showMultiple : b } d.$items.each(function (k) { f = a(this).children(); if (e.resizeContents) { b = d.width; c = d.height; a(this).css({ width: b, height: c }); if (f.length && f[0].tagName === "EMBED") { f.attr(h) } if (f[0].tagName === "OBJECT") { f.find("embed").attr(h) } if (f.length === 1) { f.css(h) } } else { b = a(this).width() || d.width; if (f.length === 1 && b >= j) { b = f.width() >= j ? i : f.width(); f.css("max-width", b) } a(this).css("width", b); c = f.length === 1 ? f.outerHeight(true) : a(this).height(); if (c <= d.outerPad) { c = d.height } a(this).css("height", c) } d.panelSize[k] = [b, c, g]; g += e.vertical ? c : b }); d.$el.css(e.vertical ? "height" : "width", g) }; d.getDim = function (a) { if (d.pages < 1 || isNaN(a)) { return [d.width, d.height] } a = e.infiniteSlides && d.pages > 1 ? a : a - 1; var b, c = d.panelSize[a][0], f = d.panelSize[a][1]; if (e.showMultiple > 1) { for (b = 1; b < e.showMultiple; b++) { c += d.panelSize[(a + b) % e.showMultiple][0]; f = Math.max(f, d.panelSize[a + b][1]) } } return [c, f] }; d.goForward = function (a) { d.gotoPage(d.currentPage + e.changeBy * (e.playRtl ? -1 : 1), a) }; d.goBack = function (a) { d.gotoPage(d.currentPage + e.changeBy * (e.playRtl ? 1 : -1), a) }; d.gotoPage = function (b, c, f, g) { if (c !== true) { c = false; d.startStop(false); d.makeActive() } if (/^[#|.]/.test(b) && a(b).length) { b = a(b).closest(".panel").index() + d.adj } if (e.changeBy !== 1) { if (b < 0) { b += d.pages } if (b > d.pages) { b -= d.pages } } if (d.pages <= 1) { return } d.$lastPage = d.$currentPage; if (typeof b !== "number") { b = e.startPanel; d.setCurrentPage(b) } if (c && e.isVideoPlaying(d)) { return } if (b > d.pages + 1 - d.adj) { b = !e.infiniteSlides && !e.stopAtEnd ? 1 : d.pages } if (b < d.adj) { b = !e.infiniteSlides && !e.stopAtEnd ? d.pages : 1 } d.currentPage = b > d.pages ? d.pages : b < 1 ? 1 : d.currentPage; d.$currentPage = d.$items.eq(d.currentPage - d.adj); d.exactPage = b; d.targetPage = b === 0 ? d.pages - d.adj : b > d.pages ? 1 - d.adj : b - d.adj; d.$targetPage = d.$items.eq(d.targetPage); g = g || e.animationTime; if (g >= 0) { d.$el.trigger("slide_init", d) } d.slideControls(true, false); if (c !== true) { c = false } if (!c || e.stopAtEnd && b === d.pages) { d.startStop(false) } if (g >= 0) { d.$el.trigger("slide_begin", d) } setTimeout(function (a) { if (!e.resizeContents) { a = d.getDim(b); d.$wrapper.filter(":not(:animated)").animate({ width: a[0] || d.width, height: a[1] || d.height }, { queue: false, duration: g < 0 ? 0 : g, easing: e.easing }) } a = {}; a[d.dir] = -d.panelSize[e.infiniteSlides && d.pages > 1 ? b : b - 1][2]; d.$el.filter(":not(:animated)").animate(a, { queue: false, duration: g, easing: e.easing, complete: function () { d.endAnimation(b, f, g) } }) }, parseInt(e.delayBeforeAnimate, 10) || 0) }; d.endAnimation = function (a, b, c) { if (a === 0) { d.$el.css(d.dir, -d.panelSize[d.pages][2]); a = d.pages } else if (a > d.pages) { d.$el.css(d.dir, -d.panelSize[1][2]); a = 1 } d.exactPage = a; d.setCurrentPage(a, false); d.$items.removeClass("activePage").eq(a - d.adj).addClass("activePage"); if (!d.hovered) { d.slideControls(false) } if (c >= 0) { d.$el.trigger("slide_complete", d) } if (typeof b === "function") { b(d) } if (e.autoPlayLocked && !d.playing) { setTimeout(function () { d.startStop(true) }, e.resumeDelay - (e.autoPlayDelayed ? e.delay : 0)) } }; d.setCurrentPage = function (a, b) { a = parseInt(a, 10); if (d.pages < 1 || a === 0 || isNaN(a)) { return } if (a > d.pages + 1 - d.adj) { a = d.pages - d.adj } if (a < d.adj) { a = 1 } if (e.buildNavigation) { d.$nav.find(".cur").removeClass("cur").end().find("a").eq(a - 1).addClass("cur") } if (!e.infiniteSlides && e.stopAtEnd) { d.$wrapper.find("span.forward")[a === d.pages ? "addClass" : "removeClass"]("disabled").end().find("span.back")[a === 1 ? "addClass" : "removeClass"]("disabled"); if (a === d.pages && d.playing) { d.startStop() } } if (!b) { var c = d.getDim(a); d.$wrapper.css({ width: c[0], height: c[1] }).add(d.$window).scrollLeft(0); d.$el.css(d.dir, -d.panelSize[e.infiniteSlides && d.pages > 1 ? a : a - 1][2]) } d.currentPage = a; d.$currentPage = d.$items.removeClass("activePage").eq(a - d.adj).addClass("activePage") }; d.makeActive = function () { if (!d.$wrapper.is(".activeSlider")) { a(".activeSlider").removeClass("activeSlider"); d.$wrapper.addClass("activeSlider") } }; d.gotoHash = function () { var b = d.win.location.hash, c = b.indexOf("&"), f = b.match(d.regex); if (f === null && !/^#&/.test(b)) { b = b.substring(0, c >= 0 ? c : b.length); f = a(b).closest(".anythingBase")[0] === d.el ? a(b).closest(".panel").index() : null } else if (f !== null) { f = e.hashTags ? parseInt(f[1], 10) : null } return f }; d.setHash = function (a) { var b = "panel" + d.runTimes + "-", c = d.win.location.hash; if (typeof c !== "undefined") { d.win.location.hash = c.indexOf(b) > 0 ? c.replace(d.regex, b + a) : c + "&" + b + a } }; d.slideControls = function (a) { var b = a ? "slideDown" : "slideUp", c = a ? 0 : e.animationTime, f = a ? e.animationTime : 0, g = a ? 1 : 0, h = a ? 0 : 1; if (e.toggleControls) { d.$controls.stop(true, true).delay(c)[b](e.animationTime / 2).delay(f) } if (e.buildArrows && e.toggleArrows) { if (!d.hovered && d.playing) { h = 1; g = 0 } d.$forward.stop(true, true).delay(c).animate({ right: h * d.$arrowWidth, opacity: g }, e.animationTime / 2); d.$back.stop(true, true).delay(c).animate({ left: h * d.$arrowWidth, opacity: g }, e.animationTime / 2) } }; d.clearTimer = function (a) { if (d.timer) { d.win.clearInterval(d.timer); if (!a && d.slideshow) { d.$el.trigger("slideshow_stop", d); d.slideshow = false } } }; d.startStop = function (a, b) { if (a !== true) { a = false } d.playing = a; if (a && !b) { d.$el.trigger("slideshow_start", d); d.slideshow = true } if (e.buildStartStop) { d.$startStop.toggleClass("playing", a).find("span").html(a ? e.stopText : e.startText); if (parseInt(d.$startStop.find("span").css("text-indent"), 10) < 0) { d.$startStop.addClass(e.tooltipClass).attr("title", a ? e.stopText : e.startText) } } if (a) { d.clearTimer(true); d.timer = d.win.setInterval(function () { if (!e.isVideoPlaying(d)) { d.goForward(true) } else if (!e.resumeOnVideoEnd) { d.startStop() } }, e.delay) } else { d.clearTimer() } }; d.init() }; a.anythingSlider.defaults = { theme: "default", expand: false, resizeContents: true, vertical: false, showMultiple: false, easing: "swing", buildArrows: true, buildNavigation: true, buildStartStop: true, appendForwardTo: null, appendBackTo: null, appendControlsTo: null, appendNavigationTo: null, appendStartStopTo: null, toggleArrows: false, toggleControls: false, startText: "Start", stopText: "Stop", forwardText: "»", backText: "«", tooltipClass: "tooltip", enableArrows: true, enableNavigation: true, enableStartStop: true, enableKeyboard: true, startPanel: 1, changeBy: 1, hashTags: true, infiniteSlides: true, navigationFormatter: null, navigationSize: false, autoPlay: false, autoPlayLocked: false, autoPlayDelayed: false, pauseOnHover: true, stopAtEnd: false, playRtl: false, delay: 3e3, resumeDelay: 15e3, animationTime: 600, delayBeforeAnimate: 0, clickForwardArrow: "click", clickBackArrow: "click", clickControls: "click focusin", clickSlideshow: "click", resumeOnVideoEnd: true, addWmodeToObject: "opaque", isVideoPlaying: function (a) { return false } }; a.fn.anythingSlider = function (b, c) { return this.each(function () { var d, e = a(this).data("AnythingSlider"); if ((typeof b).match("object|undefined")) { if (!e) { new a.anythingSlider(this, b) } else { e.updateSlider() } } else if (/\d/.test(b) && !isNaN(b) && e) { d = typeof b === "number" ? b : parseInt(a.trim(b), 10); if (d >= 1 && d <= e.pages) { e.gotoPage(d, false, c) } } else if (/^[#|.]/.test(b) && a(b).length) { e.gotoPage(b, false, c) } }) } })(jQuery)
