﻿/** Anything Fadder **/
(function (a) { a.anythingFader = function (b, c) { var d = this; d.$el = a(b); d.el = b; d.currentPage = 1; d.timer = null; d.playing = false; d.$el.data("AnythingFader", d); d.init = function () { d.options = a.extend({}, a.anythingFader.defaults, c); d.$wrapper = d.$el.find("> div").css("overflow", "hidden"); d.$slider = d.$wrapper.find("> ul"); d.$items = d.$slider.find("> li"); d.$single = d.$items.filter(":first"); if (d.options.buildNavigation) d.buildNavigation(); d.singleWidth = d.$single.outerWidth(); d.pages = d.$items.length; d.$items.filter(":first").before(d.$items.filter(":last").clone().addClass("cloned")); d.$items.filter(":last").after(d.$items.filter(":first").clone().addClass("cloned")); d.$items = d.$slider.find("> li"); d.buildNextBackButtons(); if (d.options.autoPlay) { d.playing = !d.options.startStopped; d.buildAutoPlay() } if (d.options.pauseOnHover) { d.$el.hover(function () { d.clearTimer() }, function () { d.startStop(d.playing) }) } if (d.options.hashTags == true && !d.gotoHash() || d.options.hashTags == false) { d.setCurrentPage(1) } }; d.gotoPage = function (a, b) { if (b !== true) b = false; if (!b) d.startStop(false); if (typeof a == "undefined" || a == null) { a = 1; d.setCurrentPage(1) } if (a > d.pages + 1) a = d.pages; if (a < 0) a = 1; var c = a < d.currentPage ? -1 : 1, e = Math.abs(d.currentPage - a), f = d.singleWidth * c * e; d.$wrapper.filter(":not(:animated)").animate({ opacity: "0" }, d.options.animationTime, d.options.easing, function () { if (a == 0) { d.$wrapper.scrollLeft(d.singleWidth * d.pages); a = d.pages } else if (a > d.pages) { d.$wrapper.scrollLeft(d.singleWidth); a = 1 } d.setCurrentPage(a) }); d.$wrapper.animate({ opacity: "1" }, d.options.animationTime, d.options.easing) }; d.setCurrentPage = function (b, c) { if (d.options.buildNavigation) { d.$nav.find(".cur").removeClass("cur"); a(d.$navLinks[b - 1]).addClass("cur") } if (c !== false) d.$wrapper.scrollLeft(d.singleWidth * b); d.currentPage = b }; d.goForward = function (a) { if (a !== true) a = false; d.gotoPage(d.currentPage + 1, a) }; d.goBack = function () { d.gotoPage(d.currentPage - 1) }; d.gotoHash = function () { if (/^#?panel-\d+$/.test(window.location.hash)) { var a = parseInt(window.location.hash.substr(7)); var b = d.$items.filter(":eq(" + a + ")"); if (b.length != 0) { d.setCurrentPage(a); return true } } return false }; d.buildNavigation = function () { d.$nav = a("<div id='thumbNav'></div>").appendTo(d.$el); d.$items.each(function (b, c) { var e = b + 1; var f = a("<a href='#'></a>"); if (typeof d.options.navigationFormatter == "function") { f.html(d.options.navigationFormatter(e, a(this))) } else { f.text(e) } f.click(function (a) { d.gotoPage(e); if (d.options.hashTags) d.setHash("panel-" + e); a.preventDefault() }); d.$nav.append(f) }); d.$navLinks = d.$nav.find("> a") }; d.buildNextBackButtons = function () { var b = a('<a class="arrow forward">></a>'), c = a('<a class="arrow back"><</a>'); c.click(function (a) { d.goBack(); a.preventDefault() }); b.click(function (a) { d.goForward(); a.preventDefault() }); d.$wrapper.after(c).after(b) }; d.buildAutoPlay = function () { d.$startStop = a("<a href='#' id='start-stop'></a>").html(d.playing ? d.options.stopText : d.options.startText); d.$el.append(d.$startStop); d.$startStop.click(function (a) { d.startStop(!d.playing); a.preventDefault() }); d.startStop(d.playing) }; d.startStop = function (a) { if (a !== true) a = false; d.playing = a; if (d.options.autoPlay) d.$startStop.toggleClass("playing", a).html(a ? d.options.stopText : d.options.startText); if (a) { d.clearTimer(); d.timer = window.setInterval(function () { d.goForward(true) }, d.options.delay) } else { d.clearTimer() } }; d.clearTimer = function () { if (d.timer) window.clearInterval(d.timer) }; d.setHash = function (a) { if (typeof window.location.hash !== "undefined") { if (window.location.hash !== a) { window.location.hash = a } } else if (location.hash !== a) { location.hash = a } return a }; d.init() }; a.anythingFader.defaults = { easing: "swing", autoPlay: true, startStopped: false, delay: 3e3, animationTime: 600, hashTags: true, buildNavigation: true, pauseOnHover: true, startText: "", stopText: "", navigationFormatter: null }; a.fn.anythingFader = function (b) { if (typeof b == "object") { return this.each(function (c) { new a.anythingFader(this, b); b.hashTags = false }) } else if (typeof b == "number") { return this.each(function (c) { var d = a(this).data("AnythingFader"); if (d) { d.gotoPage(b) } }) } } })(jQuery);
