﻿(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(g,e){if(e!==true){e=false}if(!e){b.startStop(false)}if(typeof(g)=="undefined"||g==null){g=1;b.setCurrentPage(1)}if(g>b.pages+1){g=b.pages}if(g<0){g=1}var f=g<b.currentPage?-1:1,i=Math.abs(b.currentPage-g),h=b.singleWidth*f*i;b.$wrapper.filter(":not(:animated)").animate({scrollLeft:"+="+h},b.options.animationTime,b.options.easing,function(){if(g==0){b.$wrapper.scrollLeft(b.singleWidth*b.pages);g=b.pages}else{if(g>b.pages){b.$wrapper.scrollLeft(b.singleWidth);g=1}}b.setCurrentPage(g)})};b.setCurrentPage=function(f,e){if(b.options.buildNavigation){b.$nav.find(".cur").removeClass("cur");a(b.$navLinks[f-1]).addClass("cur")}if(e!==false){b.$wrapper.scrollLeft(b.singleWidth*f)}b.currentPage=f};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(f,h){var g=f+1;var e=a("<a href='#'></a>");if(typeof(b.options.navigationFormatter)=="function"){e.html(b.options.navigationFormatter(g,a(this)))}else{e.text(g)}e.click(function(i){b.gotoPage(g);if(b.options.hashTags){b.setHash("panel-"+g)}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(c){var d=a(this).data("AnythingSlider");if(d){d.gotoPage(b)}})}}}})(jQuery);