(function(n){jQuery.fn.extend({slimScroll:function(t){var i=n.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},t);return this.each(function(){function y(t){if(a){t=t||window.event;var u=0;t.wheelDelta&&(u=-t.wheelDelta/120);t.detail&&(u=t.detail/3);n(t.target||t.srcTarget||t.srcElement).closest("."+i.wrapperClass).is(r.parent())&&o(u,!0);t.preventDefault&&!c&&t.preventDefault();c||(t.returnValue=!1)}}function o(n,t,e){var o=n,s=r.outerHeight()-u.outerHeight();t&&(o=parseInt(u.css("top"))+n*parseInt(i.wheelStep)/100*u.outerHeight(),o=Math.min(Math.max(o,0),s),o=0<n?Math.ceil(o):Math.floor(o),u.css({top:o+"px"}));f=parseInt(u.css("top"))/(r.outerHeight()-u.outerHeight());o=f*(r[0].scrollHeight-r.outerHeight());e&&(o=n,n=o/r[0].scrollHeight*r.outerHeight(),n=Math.min(Math.max(n,0),s),u.css({top:n+"px"}));r.scrollTop(o);r.trigger("slimscrolling",~~o);w();h()}function tt(){window.addEventListener?(this.addEventListener("DOMMouseScroll",y,!1),this.addEventListener("mousewheel",y,!1)):document.attachEvent("onmousewheel",y)}function p(){v=Math.max(r.outerHeight()/r[0].scrollHeight*r.outerHeight(),it);u.css({height:v+"px"});var n=v==r.outerHeight()?"none":"block";u.css({display:n})}function w(){p();clearTimeout(d);f==~~f?(c=i.allowPageScroll,nt!=f&&r.trigger("slimscroll",0==~~f?"top":"bottom")):c=!1;nt=f;v>=r.outerHeight()?c=!0:(u.stop(!0,!0).fadeIn("fast"),i.railVisible&&e.stop(!0,!0).fadeIn("fast"))}function h(){i.alwaysVisible||(d=setTimeout(function(){i.disableFadeOut&&a||b||k||(u.fadeOut("slow"),e.fadeOut("slow"))},1e3))}var a,b,k,d,g,v,f,nt,it=30,c=!1,r=n(this),s;if(r.parent().hasClass(i.wrapperClass)){var l=r.scrollTop(),u=r.parent().find("."+i.barClass),e=r.parent().find("."+i.railClass);if(p(),n.isPlainObject(t)){if("height"in t&&"auto"==t.height&&(r.parent().css("height","auto"),r.css("height","auto"),s=r.parent().parent().height(),r.parent().css("height",s),r.css("height",s)),"scrollTo"in t)l=parseInt(i.scrollTo);else if("scrollBy"in t)l+=parseInt(i.scrollBy);else if("destroy"in t){u.remove();e.remove();r.unwrap();return}o(l,!1,!0)}}else{i.height="auto"==i.height?r.parent().height():i.height;l=n("<div><\/div>").addClass(i.wrapperClass).css({position:"relative",overflow:"hidden",width:i.width,height:i.height});r.css({overflow:"hidden",width:i.width,height:i.height});var e=n("<div><\/div>").addClass(i.railClass).css({width:i.size,height:"100%",position:"absolute",top:0,display:i.alwaysVisible&&i.railVisible?"block":"none","border-radius":i.size,background:i.railColor,opacity:i.railOpacity,zIndex:90}),u=n("<div><\/div>").addClass(i.barClass).css({background:i.color,width:i.size,position:"absolute",top:0,opacity:i.opacity,display:i.alwaysVisible?"block":"none","border-radius":i.size,BorderRadius:i.size,MozBorderRadius:i.size,WebkitBorderRadius:i.size,zIndex:99}),s="right"==i.position?{right:i.distance}:{left:i.distance};e.css(s);u.css(s);r.wrap(l);r.parent().append(u);r.parent().append(e);i.railDraggable&&n.ui&&"function"==typeof n.ui.draggable&&u.draggable({axis:"y",containment:"parent",start:function(){k=!0},stop:function(){k=!1;h()},drag:function(){o(0,n(this).position().top,!1)}});e.hover(function(){w()},function(){h()});u.hover(function(){b=!0},function(){b=!1});r.hover(function(){a=!0;w();h()},function(){a=!1;h()});r.bind("touchstart",function(n){n.originalEvent.touches.length&&(g=n.originalEvent.touches[0].pageY)});r.bind("touchmove",function(n){n.originalEvent.preventDefault();n.originalEvent.touches.length&&o((g-n.originalEvent.touches[0].pageY)/i.touchScrollStep,!0)});"bottom"===i.start?(u.css({top:r.outerHeight()-u.outerHeight()}),o(0,!0)):"top"!==i.start&&(o(n(i.start).position().top,null,!0),i.alwaysVisible||u.hide());tt();p()}}),this}});jQuery.fn.extend({slimscroll:jQuery.fn.slimScroll})})(jQuery)