!function(e){e.fn.extend({slimScroll:function(i){var s={width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:.4,alwaysVisible:!1,disableFadeOut:!1,railVisible:!1,railColor:"#333",railOpacity:.2,railDraggable:!0,railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv",allowPageScroll:!1,wheelStep:20,touchScrollStep:200,borderRadius:"7px",railBorderRadius:"7px"},o=e.extend(s,i);return this.each(function(){function s(t){if(c){var i=0;(t=t||window.event).wheelDelta&&(i=-t.wheelDelta/120),t.detail&&(i=t.detail/3);var s=t.target||t.srcTarget||t.srcElement;e(s).closest("."+o.wrapperClass).is(y.parent())&&a(i,!0),t.preventDefault&&!m&&t.preventDefault(),m||(t.returnValue=!1)}}function a(e,t,i){m=!1;var s=e,a=y.outerHeight()-R.outerHeight();if(t&&(s=parseInt(R.css("top"))+e*parseInt(o.wheelStep)/100*R.outerHeight(),s=Math.min(Math.max(s,0),a),s=e>0?Math.ceil(s):Math.floor(s),R.css({top:s+"px"})),f=parseInt(R.css("top"))/(y.outerHeight()-R.outerHeight()),s=f*(y[0].scrollHeight-y.outerHeight()),i){var r=(s=e)/y[0].scrollHeight*y.outerHeight();r=Math.min(Math.max(r,0),a),R.css({top:r+"px"})}y.scrollTop(s),y.trigger("slimscrolling",~~s),l(),n()}function r(){g=Math.max(y.outerHeight()/y[0].scrollHeight*y.outerHeight(),w),R.css({height:g+"px"});var e=g==y.outerHeight()?"none":"block";R.css({display:e})}function l(){if(r(),clearTimeout(p),f==~~f){if(m=o.allowPageScroll,b!=f){var e=0==~~f?"top":"bottom";y.trigger("slimscroll",e)}}else m=!1;b=f,g>=y.outerHeight()?m=!0:(R.stop(!0,!0).fadeIn("fast"),o.railVisible&&E.stop(!0,!0).fadeIn("fast"))}function n(){o.alwaysVisible||(p=setTimeout(function(){o.disableFadeOut&&c||h||u||(R.fadeOut("slow"),E.fadeOut("slow"))},1e3))}var c,h,u,p,d,g,f,b,v="<div></div>",w=30,m=!1,y=e(this);if(y.parent().hasClass(o.wrapperClass)){var x=y.scrollTop();if(R=y.siblings("."+o.barClass),E=y.siblings("."+o.railClass),r(),e.isPlainObject(i)){if("height"in i&&"auto"==i.height){y.parent().css("height","auto"),y.css("height","auto");var C=y.parent().parent().height();y.parent().css("height",C),y.css("height",C)}else if("height"in i){var H=i.height;y.parent().css("height",H),y.css("height",H)}if("scrollTo"in i)x=parseInt(o.scrollTo);else if("scrollBy"in i)x+=parseInt(o.scrollBy);else if("destroy"in i)return R.remove(),E.remove(),void y.unwrap();a(x,!1,!0)}}else if(!(e.isPlainObject(i)&&"destroy"in i)){o.height="auto"==o.height?y.parent().height():o.height;var S=e(v).addClass(o.wrapperClass).css({position:"relative",overflow:"hidden",width:o.width,height:o.height});y.css({overflow:"hidden",width:o.width,height:o.height});var E=e(v).addClass(o.railClass).css({width:o.size,height:"100%",position:"absolute",top:0,display:o.alwaysVisible&&o.railVisible?"block":"none","border-radius":o.railBorderRadius,background:o.railColor,opacity:o.railOpacity,zIndex:90}),R=e(v).addClass(o.barClass).css({background:o.color,width:o.size,position:"absolute",top:0,opacity:o.opacity,display:o.alwaysVisible?"block":"none","border-radius":o.borderRadius,BorderRadius:o.borderRadius,MozBorderRadius:o.borderRadius,WebkitBorderRadius:o.borderRadius,zIndex:99}),D="right"==o.position?{right:o.distance}:{left:o.distance};E.css(D),R.css(D),y.wrap(S),y.parent().append(R),y.parent().append(E),o.railDraggable&&R.bind("mousedown",function(i){var s=e(document);return u=!0,t=parseFloat(R.css("top")),pageY=i.pageY,s.bind("mousemove.slimscroll",function(e){currTop=t+e.pageY-pageY,R.css("top",currTop),a(0,R.position().top,!1)}),s.bind("mouseup.slimscroll",function(e){u=!1,n(),s.unbind(".slimscroll")}),!1}).bind("selectstart.slimscroll",function(e){return e.stopPropagation(),e.preventDefault(),!1}),E.hover(function(){l()},function(){n()}),R.hover(function(){h=!0},function(){h=!1}),y.hover(function(){c=!0,l(),n()},function(){c=!1,n()}),y.bind("touchstart",function(e,t){e.originalEvent.touches.length&&(d=e.originalEvent.touches[0].pageY)}),y.bind("touchmove",function(e){m||e.originalEvent.preventDefault(),e.originalEvent.touches.length&&(a((d-e.originalEvent.touches[0].pageY)/o.touchScrollStep,!0),d=e.originalEvent.touches[0].pageY)}),r(),"bottom"===o.start?(R.css({top:y.outerHeight()-R.outerHeight()}),a(0,!0)):"top"!==o.start&&(a(e(o.start).position().top,null,!0),o.alwaysVisible||R.hide()),function(e){window.addEventListener?(e.addEventListener("DOMMouseScroll",s,!1),e.addEventListener("mousewheel",s,!1)):document.attachEvent("onmousewheel",s)}(this)}}),this}}),e.fn.extend({slimscroll:e.fn.slimScroll})}(jQuery);