(function(s,i,o){"use strict";var c,p,n,l,e,t,r,h,a,f,d,u,g,v,S,m,T,y,w,b,$;b={paneClass:"pane",sliderClass:"slider",contentClass:"content",iOSNativeScrolling:false,preventPageScrolling:false,disableResize:false,alwaysVisible:false,flashDelay:1500,sliderMinHeight:20,sliderMaxHeight:null,documentContext:null,windowContext:null};m="scrollbar";S="scroll";h="mousedown";a="mousemove";d="mousewheel";f="mouseup";v="resize";e="drag";y="up";g="panedown";n="DOMMouseScroll";l="down";w="wheel";t="keydown";r="keyup";T="touchmove";c=i.navigator.appName==="Microsoft Internet Explorer"&&/msie 7./i.test(i.navigator.appVersion)&&i.ActiveXObject;p=null;$=function(){var t,e,i;t=o.createElement("div");e=t.style;e.position="absolute";e.width="100px";e.height="100px";e.overflow=S;e.top="-9999px";o.body.appendChild(t);i=t.offsetWidth-t.clientWidth;o.body.removeChild(t);return i};u=function(){function t(t,e){this.el=t;this.options=e;p||(p=$());this.$el=s(this.el);this.doc=s(this.options.documentContext||o);this.win=s(this.options.windowContext||i);this.$content=this.$el.children("."+e.contentClass);this.$content.attr("tabindex",this.options.tabIndex||0);this.content=this.$content[0];if(this.options.iOSNativeScrolling&&this.el.style.WebkitOverflowScrolling!=null){this.nativeScrolling()}else{this.generate()}this.createEvents();this.addEvents();this.reset()}t.prototype.preventScrolling=function(t,e){if(!this.isActive){return}if(t.type===n){if(e===l&&t.originalEvent.detail>0||e===y&&t.originalEvent.detail<0){t.preventDefault()}}else if(t.type===d){if(!t.originalEvent||!t.originalEvent.wheelDelta){return}if(e===l&&t.originalEvent.wheelDelta<0||e===y&&t.originalEvent.wheelDelta>0){t.preventDefault()}}};t.prototype.nativeScrolling=function(){this.$content.css({WebkitOverflowScrolling:"touch"});this.iOSNativeScrolling=true;this.isActive=true};t.prototype.updateScrollValues=function(){var t;t=this.content;this.maxScrollTop=t.scrollHeight-t.clientHeight;this.prevScrollTop=this.contentScrollTop||0;this.contentScrollTop=t.scrollTop;if(!this.iOSNativeScrolling){this.maxSliderTop=this.paneHeight-this.sliderHeight;this.sliderTop=this.maxScrollTop===0?0:this.contentScrollTop*this.maxSliderTop/this.maxScrollTop}};t.prototype.createEvents=function(){var i=this;this.events={down:function(t){i.isBeingDragged=true;i.offsetY=t.pageY-i.slider.offset().top;i.pane.addClass("active");i.doc.bind(a,i.events[e]).bind(f,i.events[y]);return false},drag:function(t){i.sliderY=t.pageY-i.$el.offset().top-i.offsetY;i.scroll();i.updateScrollValues();if(i.contentScrollTop>=i.maxScrollTop&&i.prevScrollTop!==i.maxScrollTop){i.$el.trigger("scrollend")}else if(i.contentScrollTop===0&&i.prevScrollTop!==0){i.$el.trigger("scrolltop")}return false},up:function(t){i.isBeingDragged=false;i.pane.removeClass("active");i.doc.unbind(a,i.events[e]).unbind(f,i.events[y]);return false},resize:function(t){i.reset()},panedown:function(t){i.sliderY=(t.offsetY||t.originalEvent.layerY)-i.sliderHeight*.5;i.scroll();i.events.down(t);return false},scroll:function(t){if(i.isBeingDragged){return}i.updateScrollValues();if(!i.iOSNativeScrolling){i.sliderY=i.sliderTop;i.slider.css({top:i.sliderTop})}if(t==null){return}if(i.contentScrollTop>=i.maxScrollTop){if(i.options.preventPageScrolling){i.preventScrolling(t,l)}if(i.prevScrollTop!==i.maxScrollTop){i.$el.trigger("scrollend")}}else if(i.contentScrollTop===0){if(i.options.preventPageScrolling){i.preventScrolling(t,y)}if(i.prevScrollTop!==0){i.$el.trigger("scrolltop")}}},wheel:function(t){var e;if(t==null){return}e=t.delta||t.wheelDelta||t.originalEvent&&t.originalEvent.wheelDelta||-t.detail||t.originalEvent&&-t.originalEvent.detail;if(e){i.sliderY+=-e/3}i.scroll();return false}}};t.prototype.addEvents=function(){var t;this.removeEvents();t=this.events;if(!this.options.disableResize){this.win.bind(v,t[v])}if(!this.iOSNativeScrolling){this.slider.bind(h,t[l]);this.pane.bind(h,t[g]).bind(""+d+" "+n,t[w])}this.$content.bind(""+S+" "+d+" "+n+" "+T,t[S])};t.prototype.removeEvents=function(){var t;t=this.events;this.win.unbind(v,t[v]);if(!this.iOSNativeScrolling){this.slider.unbind();this.pane.unbind()}this.$content.unbind(""+S+" "+d+" "+n+" "+T,t[S])};t.prototype.generate=function(){var t,e,i;t=this.options;e=t.paneClass,i=t.sliderClass;if(!this.$el.find(""+e).length&&!this.$el.find(""+i).length){this.$el.append('<div class="'+e+'"><div class="'+i+'" /></div>')}this.pane=this.$el.children("."+e);this.slider=this.pane.find("."+i);return this};t.prototype.restore=function(){this.stopped=false;this.paneShow();this.addEvents()};t.prototype.paneShow=function(){if(p){var t={right:-p};if(!this.$el.hasClass("has-scrollbar"))this.$el.addClass("has-scrollbar");this.$content.css(t)}this.pane.show()};t.prototype.paneHide=function(){this.pane.hide();this.$content.css({right:""})};t.prototype.reset=function(){var t,e,i,s,o,n,l,r,h,a;if(this.iOSNativeScrolling){this.contentHeight=this.content.scrollHeight;return}if(!this.$el.find("."+this.options.paneClass).length){this.generate().stop()}if(this.stopped){this.restore()}t=this.content;i=t.style;s=i.overflowY;if(c){this.$content.css({height:this.$content.height()})}e=t.scrollHeight+p;h=parseInt(this.$el.css("max-height"),10);if(h>0){this.$el.height("");this.$el.height(t.scrollHeight>h?h:t.scrollHeight)}n=this.pane.outerHeight(false);r=parseInt(this.pane.css("top"),10);o=parseInt(this.pane.css("bottom"),10);l=n+r+o;a=Math.round(l/e*l);if(a<this.options.sliderMinHeight){a=this.options.sliderMinHeight}else if(this.options.sliderMaxHeight!=null&&a>this.options.sliderMaxHeight){a=this.options.sliderMaxHeight}if(s===S&&i.overflowX!==S){a+=p}this.maxSliderTop=l-a;this.contentHeight=e;this.paneHeight=n;this.paneOuterHeight=l;this.sliderHeight=a;this.slider.height(a);this.events.scroll();this.paneShow();this.isActive=true;if(t.scrollHeight===t.clientHeight||this.pane.outerHeight(true)>=t.scrollHeight&&s!==S){this.paneHide();this.isActive=false}else if(this.el.clientHeight===t.scrollHeight&&s===S){this.slider.hide()}else{this.slider.show()}this.pane.css({opacity:this.options.alwaysVisible?1:"",visibility:this.options.alwaysVisible?"visible":""});return this};t.prototype.scroll=function(){if(!this.isActive){return}this.sliderY=Math.max(0,this.sliderY);this.sliderY=Math.min(this.maxSliderTop,this.sliderY);this.$content.scrollTop((this.paneHeight-this.contentHeight+p)*this.sliderY/this.maxSliderTop*-1);if(!this.iOSNativeScrolling){this.slider.css({top:this.sliderY})}return this};t.prototype.scrollBottom=function(t){if(!this.isActive){return}this.reset();this.$content.scrollTop(this.contentHeight-this.$content.height()-t).trigger(d);return this};t.prototype.scrollTop=function(t){if(!this.isActive){return}this.reset();this.$content.scrollTop(+t).trigger(d);return this};t.prototype.scrollTo=function(t){if(!this.isActive){return}this.reset();this.scrollTop(s(t).get(0).offsetTop);return this};t.prototype.stop=function(){this.stopped=true;this.removeEvents();this.paneHide();return this};t.prototype.destroy=function(){if(!this.stopped){this.stop()}if(this.pane.length){this.pane.remove()}if(c){this.$content.height("")}this.$content.removeAttr("tabindex");if(this.$el.hasClass("has-scrollbar")){this.$el.removeClass("has-scrollbar");this.$content.css({right:""})}return this};t.prototype.flash=function(){var t=this;if(!this.isActive){return}this.reset();this.pane.addClass("flashed");setTimeout(function(){t.pane.removeClass("flashed")},this.options.flashDelay);return this};return t}();s.fn.nanoScroller=function(i){return this.each(function(){var t,e;if(!(e=this.nanoscroller)){t=s.extend({},b,i);this.nanoscroller=e=new u(this,t)}if(i&&typeof i==="object"){s.extend(e.options,i);if(i.scrollBottom){return e.scrollBottom(i.scrollBottom)}if(i.scrollTop){return e.scrollTop(i.scrollTop)}if(i.scrollTo){return e.scrollTo(i.scrollTo)}if(i.scroll==="bottom"){return e.scrollBottom(0)}if(i.scroll==="top"){return e.scrollTop(0)}if(i.scroll&&i.scroll instanceof s){return e.scrollTo(i.scroll)}if(i.stop){return e.stop()}if(i.destroy){return e.destroy()}if(i.flash){return e.flash()}}return e.reset()})};s.fn.nanoScroller.Constructor=u})(jQuery,window,document);