!function(t,s,o){"use strict";var e="scrollBox",n={containerClass:"sb-container",containerNoScrollClass:"sb-container-noscroll",contentClass:"sb-content",scrollbarContainerClass:"sb-scrollbar-container",scrollBarClass:"sb-scrollbar"};function i(s,o){this.element=s,this.settings=t.extend({},n,o),this._defaults=n,this._name=e,this.init()}t.extend(i.prototype,{init:function(){this.addScrollbar(),this.addEvents(),this.onResize()},addScrollbar:function(){t(this.element).addClass(this.settings.containerClass),this.wrapper=t("
"),this.wrapper.append(t(this.element).contents()),t(this.element).append(this.wrapper),this.scollbarContainer=t("
"),this.scrollBar=t("
"),this.scollbarContainer.append(this.scrollBar),t(this.element).prepend(this.scollbarContainer)},addEvents:function(){this.wrapper.on("scroll."+e,t.proxy(this.onScroll,this)),t(s).on("resize."+e,t.proxy(this.onResize,this)),this.scrollBar.on("mousedown."+e,t.proxy(this.onMousedown,this)),this.scrollBar.on("touchstart."+e,t.proxy(this.onTouchstart,this))},onTouchstart:function(s){var n=this;s.preventDefault();var i=n.scrollBar[0].offsetTop;t(o).on("touchmove."+e,function(t){var o=t.touches[0].pageY-s.touches[0].pageY;n.scrollBar[0].style.top=Math.min(n.scollbarContainer[0].clientHeight-n.scrollBar[0].clientHeight,Math.max(0,i+o))+"px",n.wrapper[0].scrollTop=n.wrapper[0].scrollHeight*n.scrollBar[0].offsetTop/n.scollbarContainer[0].clientHeight}),t(o).on("touchend."+e,function(){t(o).off("touchmove."+e),t(o).off("touchend."+e)})},onMousedown:function(s){var n=this;s.preventDefault();var i=n.scrollBar[0].offsetTop;t(o).on("mousemove."+e,function(t){var o=t.pageY-s.pageY;n.scrollBar[0].style.top=Math.min(n.scollbarContainer[0].clientHeight-n.scrollBar[0].clientHeight,Math.max(0,i+o))+"px",n.wrapper[0].scrollTop=n.wrapper[0].scrollHeight*n.scrollBar[0].offsetTop/n.scollbarContainer[0].clientHeight}),t(o).on("mouseup."+e,function(){t(o).off("mousemove."+e),t(o).off("mouseup."+e)})},onResize:function(){this.wrapper.css("max-height",t(this.element).height());var s=this.wrapper[0].clientHeight;this.scrollBar.css("height",this.scollbarContainer[0].clientHeight*s/this.wrapper[0].scrollHeight+"px"),this.scollbarContainer[0].clientHeight<=this.scrollBar[0].clientHeight?t(this.element).addClass(this.settings.containerNoScrollClass):t(this.element).removeClass(this.settings.containerNoScrollClass),this.onScroll()},onScroll:function(){this.scrollBar.css("top",Math.min(this.scollbarContainer[0].clientHeight-this.scrollBar[0].clientHeight,this.scollbarContainer[0].clientHeight*this.wrapper[0].scrollTop/this.wrapper[0].scrollHeight)+"px")}}),t.fn[e]=function(s){return this.each(function(){t.data(this,"plugin_"+e)||t.data(this,"plugin_"+e,new i(this,s))})}}(jQuery,window,document);