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