(function(){var c,e,d=function(b,a){return function(){return b.apply(a,arguments)}};c=this.jQuery;e=function(){function b(a){this.el=a;this.generate();this.createEvents();this.addEvents();this.reset()}b.prototype.createEvents=function(){return this.events={down:d(function(a){this.isDrag=!0;this.offsetY=a.clientY-this.slider.offset().top;this.pane.addClass("active");c(document).bind("mousemove",this.events.drag);c(document).bind("mouseup",this.events.up);return!1},this),drag:d(function(a){this.sliderY=
a.clientY-this.el.offset().top-this.offsetY;this.scroll();return!1},this),up:d(function(){this.isDrag=!1;this.pane.removeClass("active");c(document).unbind("mousemove",this.events.drag);c(document).unbind("mouseup",this.events.up);return!1},this),resize:d(function(){return this.reset()},this),panedown:d(function(a){this.sliderY=a.clientY-this.el.offset().top-0.5*this.sliderH;this.scroll();return this.events.down(a)},this),scroll:d(function(){if(!0!==this.isDrag)return this.slider.css({top:this.content[0].scrollTop/
(this.content[0].scrollHeight-this.content[0].clientHeight)*(this.paneH-this.sliderH)+"px"})},this),wheel:d(function(a){this.sliderY+=-a.wheelDeltaY||-a.delta;this.scroll();return!1},this)}};b.prototype.addEvents=function(){c(window).bind("resize",this.events.resize);this.slider.bind("mousedown",this.events.down);this.pane.bind("mousedown",this.events.panedown);this.content.bind("scroll",this.events.scroll);if(window.addEventListener)return this.pane[0].addEventListener("mousewheel",this.events.wheel),
this.pane[0].addEventListener("DOMMouseScroll",this.events.wheel)};b.prototype.removeEvents=function(){c(window).unbind("resize",this.events.resize);this.slider.unbind("mousedown",this.events.down);this.pane.unbind("mousedown",this.events.panedown);this.content.unbind("scroll",this.events.scroll);if(window.addEventListener)return this.pane[0].removeEventListener("mousewheel",this.events.wheel),this.pane[0].removeEventListener("DOMMouseScroll",this.events.wheel)};b.prototype.getScrollbarWidth=function(){var a,
b,c;b=document.createElement("div");b.style.position="absolute";b.style.width="100px";b.style.height="100px";b.style.overflow="scroll";document.body.appendChild(b);a=b.offsetWidth;c=b.scrollWidth;document.body.removeChild(b);return a-c};b.prototype.generate=function(){this.el.append('<div class="pane"><div class="slider"></div></div>');this.content=c(this.el.children()[0]);this.slider=this.el.find(".slider");this.pane=this.el.find(".pane");this.scrollW=this.getScrollbarWidth();if(0===this.scrollbarWidth)this.scrollW=
0;this.content.css({right:-this.scrollW+"px"});null!=c.browser.msie&&8>parseInt(c.browser.version)&&this.pane.hide()};b.prototype.reset=function(){if(!0===this.isDead)this.isDead=!1,this.pane.show(),this.addEvents();this.contentH=this.content[0].scrollHeight+this.scrollW;this.paneH=this.pane.outerHeight();this.sliderH=this.paneH/this.contentH*this.paneH;this.sliderH=Math.round(this.sliderH);this.scrollH=this.paneH-this.sliderH;this.slider.height(this.sliderH);this.paneH>=this.contentH?this.pane.hide():
this.pane.show()};b.prototype.scroll=function(){var a;this.sliderY=Math.max(0,this.sliderY);this.sliderY=Math.min(this.scrollH,this.sliderY);a=this.paneH-this.contentH+this.scrollW;a=a*this.sliderY/this.scrollH;this.content.scrollTop(-a);return this.slider.css({top:this.sliderY})};b.prototype.scrollBottom=function(a){this.reset();this.content.scrollTop(this.contentH-this.content.height()-a)};b.prototype.scrollTop=function(a){this.reset();this.content.scrollTop(a+0)};b.prototype.stop=function(){this.isDead=
!0;this.removeEvents();this.pane.hide()};return b}();c.fn.nanoScroller=function(b){var a;b||(b={});a=this.data("scrollbar");if(void 0===a)a=new e(this,b),this.data({scrollbar:a});else return b.scrollBottom?a.scrollBottom(b.scrollBottom):b.scrollTop?a.scrollTop(b.scrollTop):"bottom"===b.scroll?a.scrollBottom(0):"top"===b.scroll?a.scrollTop(0):!0===b.stop?a.stop():a.reset()}}).call(this);
