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