(function($,e){$.fn.scrollbar=function(c){var d=$.extend({},$.fn.scrollbar.defaults,c);return this.each(function(){var a=$(this),props={arrows:d.arrows};if(d.containerHeight!='auto'){a.height(d.containerHeight)}props.containerHeight=a.height();props.contentHeight=$.fn.scrollbar.contentHeight(a);if(props.contentHeight<=props.containerHeight){return true}var b=new $.fn.scrollbar.Scrollbar(a,props,d);b.buildHtml().initHandle().appendEvents()})};$.fn.scrollbar.defaults={containerHeight:'auto',arrows:true,handleHeight:'auto',handleMinHeight:30,scrollSpeed:50,scrollStep:20,scrollSpeedArrows:40,scrollStepArrows:3};$.fn.scrollbar.Scrollbar=function(a,b,c){this.container=a;this.props=b;this.opts=c;this.mouse={};this.props.arrows=this.container.hasClass('no-arrows')?false:this.props.arrows};$.fn.scrollbar.Scrollbar.prototype={buildHtml:function(){this.container.wrapInner('<div class="scrollbar-pane"/>');this.container.append('<div class="scrollbar-handle-container"><div class="scrollbar-handle"/></div>');if(this.props.arrows){this.container.append('<div class="scrollbar-handle-up"/>').append('<div class="scrollbar-handle-down"/>')}var a=this.container.height();this.pane=this.container.find('.scrollbar-pane');this.handle=this.container.find('.scrollbar-handle');this.handleContainer=this.container.find('.scrollbar-handle-container');this.handleArrows=this.container.find('.scrollbar-handle-up, .scrollbar-handle-down');this.handleArrowUp=this.container.find('.scrollbar-handle-up');this.handleArrowDown=this.container.find('.scrollbar-handle-down');this.pane.defaultCss({'top':0,'left':0});this.handleContainer.defaultCss({'right':0});this.handle.defaultCss({'top':0,'right':0});this.handleArrows.defaultCss({'right':0});this.handleArrowUp.defaultCss({'top':0});this.handleArrowDown.defaultCss({'bottom':0});this.container.css({'position':this.container.css('position')==='absolute'?'absolute':'relative','overflow':'hidden','height':a});this.pane.css({'position':'absolute','overflow':'visible','height':'auto'});this.handleContainer.css({'position':'absolute','top':this.handleArrowUp.outerHeight(true),'height':(this.props.containerHeight-(this.container.outerHeight(true)-this.container.height())-this.handleArrowUp.outerHeight(true)-this.handleArrowDown.outerHeight(true))+'px'});this.handle.css({'position':'absolute','cursor':'pointer'});this.handleArrows.css({'position':'absolute','cursor':'pointer'});return this},initHandle:function(){this.props.handleContainerHeight=this.handleContainer.height();this.props.contentHeight=this.pane.height();this.props.handleHeight=this.opts.handleHeight=='auto'?Math.max(Math.ceil(this.props.containerHeight*this.props.handleContainerHeight/this.props.contentHeight),this.opts.handleMinHeight):this.opts.handleHeight;this.handle.height(this.props.handleHeight);this.handle.height(2*this.handle.height()-this.handle.outerHeight(true));this.props.handleTop={min:0,max:this.props.handleContainerHeight-this.props.handleHeight};this.props.handleContentRatio=(this.props.contentHeight-this.props.containerHeight)/(this.props.handleContainerHeight-this.props.handleHeight);this.handle.top=0;return this},appendEvents:function(){this.handle.bind('mousedown.handle',$.proxy(this,'startOfHandleMove'));this.handleContainer.bind('mousedown.handle',$.proxy(this,'onHandleContainerMousedown'));this.handleContainer.bind('mouseenter.container mouseleave.container',$.proxy(this,'onHandleContainerHover'));this.handleArrows.bind('mousedown.arrows',$.proxy(this,'onArrowsMousedown'));this.container.bind('mousewheel.container',$.proxy(this,'onMouseWheel'));this.container.bind('mouseenter.container mouseleave.container',$.proxy(this,'onContentHover'));this.handle.bind('click.scrollbar',this.preventClickBubbling);this.handleContainer.bind('click.scrollbar',this.preventClickBubbling);this.handleArrows.bind('click.scrollbar',this.preventClickBubbling);return this},mousePosition:function(a){return a.pageY||(a.clientY+(e.documentElement.scrollTop||e.body.scrollTop))||0},startOfHandleMove:function(a){a.preventDefault();a.stopPropagation();this.mouse.start=this.mousePosition(a);this.handle.start=this.handle.top;$(e).bind('mousemove.handle',$.proxy(this,'onHandleMove')).bind('mouseup.handle',$.proxy(this,'endOfHandleMove'));this.handle.addClass('move');this.handleContainer.addClass('move')},onHandleMove:function(a){a.preventDefault();var b=this.mousePosition(a)-this.mouse.start;this.handle.top=this.handle.start+b;this.setHandlePosition();this.setContentPosition()},endOfHandleMove:function(a){$(e).unbind('.handle');this.handle.removeClass('move');this.handleContainer.removeClass('move')},setHandlePosition:function(){this.handle.top=(this.handle.top>this.props.handleTop.max)?this.props.handleTop.max:this.handle.top;this.handle.top=(this.handle.top<this.props.handleTop.min)?this.props.handleTop.min:this.handle.top;this.handle[0].style.top=this.handle.top+'px'},setContentPosition:function(){this.pane.top=-1*this.props.handleContentRatio*this.handle.top;this.pane[0].style.top=this.pane.top+'px'},onMouseWheel:function(a,b){this.handle.top-=b;this.setHandlePosition();this.setContentPosition();if(this.handle.top>this.props.handleTop.min&&this.handle.top<this.props.handleTop.max){a.preventDefault()}},onHandleContainerMousedown:function(a){a.preventDefault();if(!$(a.target).hasClass('scrollbar-handle-container')){return false}this.handle.direction=(this.handle.offset().top<this.mousePosition(a))?1:-1;this.handle.step=this.opts.scrollStep;var b=this;$(e).bind('mouseup.handlecontainer',function(){clearInterval(c);b.handle.unbind('mouseenter.handlecontainer');$(e).unbind('mouseup.handlecontainer')});this.handle.bind('mouseenter.handlecontainer',function(){clearInterval(c)});var c=setInterval($.proxy(this.moveHandle,this),this.opts.scrollSpeed)},onArrowsMousedown:function(a){a.preventDefault();this.handle.direction=$(a.target).hasClass('scrollbar-handle-up')?-1:1;this.handle.step=this.opts.scrollStepArrows;$(a.target).addClass('move');var b=setInterval($.proxy(this.moveHandle,this),this.opts.scrollSpeedArrows);$(e).one('mouseup.arrows',function(){clearInterval(b);$(a.target).removeClass('move')})},moveHandle:function(){this.handle.top=(this.handle.direction===1)?Math.min(this.handle.top+this.handle.step,this.props.handleTop.max):Math.max(this.handle.top-this.handle.step,this.props.handleTop.min);this.handle[0].style.top=this.handle.top+'px';this.setContentPosition()},onContentHover:function(a){if(a.type==='mouseenter'){this.container.addClass('hover');this.handleContainer.addClass('hover')}else{this.container.removeClass('hover');this.handleContainer.removeClass('hover')}},onHandleContainerHover:function(a){if(a.type==='mouseenter'){this.handleArrows.addClass('hover')}else{this.handleArrows.removeClass('hover')}},preventClickBubbling:function(a){a.stopPropagation()}};$.fn.scrollbar.contentHeight=function(a){var b=a.wrapInner('<div/>').find(':first');var c=b.css({overflow:'hidden'}).height();b.replaceWith(b.contents());return c};$.fn.defaultCss=function(c){var d={'right':'auto','left':'auto','top':'auto','bottom':'auto','position':'static'};return this.each(function(){var a=$(this);for(var b in c){if(a.css(b)===d[b]){a.css(b,c[b])}}})};$.event.special.mousewheel={setup:function(){if(this.addEventListener){this.addEventListener('mousewheel',$.fn.scrollbar.mouseWheelHandler,false);this.addEventListener('DOMMouseScroll',$.fn.scrollbar.mouseWheelHandler,false)}else{this.onmousewheel=$.fn.scrollbar.mouseWheelHandler}},teardown:function(){if(this.removeEventListener){this.removeEventListener('mousewheel',$.fn.scrollbar.mouseWheelHandler,false);this.removeEventListener('DOMMouseScroll',$.fn.scrollbar.mouseWheelHandler,false)}else{this.onmousewheel=null}}};$.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}});$.fn.scrollbar.mouseWheelHandler=function(a){var b=a||window.event,args=[].slice.call(arguments,1),delta=0,returnValue=true,deltaX=0,deltaY=0;a=$.event.fix(b);a.type="mousewheel";if(a.wheelDelta){delta=a.wheelDelta/120}if(a.detail){delta=-a.detail/3}if(b.axis!==undefined&&b.axis===b.HORIZONTAL_AXIS){deltaY=0;deltaX=-1*delta}if(b.wheelDeltaY!==undefined){deltaY=b.wheelDeltaY/120}if(b.wheelDeltaX!==undefined){deltaX=-1*b.wheelDeltaX/120}args.unshift(a,delta,deltaX,deltaY);return $.event.handle.apply(this,args)}})(jQuery,document);
