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