(function($){$.fn.extend({slimscroll:function(options){var defaults={width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:.4,alwaysvisible:false,disablefadeout:false,railvisible:false,railcolor:"#333",railopacity:.2,raildraggable:true,railclass:"slimscrollrail",barclass:"slimscrollbar",wrapperclass:"slimscrolldiv",allowpagescroll:false,wheelstep:20,touchscrollstep:200,borderradius:"7px",railborderradius:"7px"};var o=$.extend(defaults,options);this.each(function(){var isoverpanel,isoverbar,isdragg,queuehide,touchdif,barheight,percentscroll,lastscroll,divs="
",minbarheight=30,releasescroll=false;var me=$(this);if(me.parent().hasclass(o.wrapperclass)){var offset=me.scrolltop();bar=me.parent().find("."+o.barclass);rail=me.parent().find("."+o.railclass);getbarheight();if($.isplainobject(options)){if("height"in options&&options.height=="auto"){me.parent().css("height","auto");me.css("height","auto");var height=me.parent().parent().height();me.parent().css("height",height);me.css("height",height)}if("scrollto"in options){offset=parseint(o.scrollto)}else if("scrollby"in options){offset+=parseint(o.scrollby)}else if("destroy"in options){bar.remove();rail.remove();me.unwrap();return}scrollcontent(offset,false,true)}return}else if($.isplainobject(options)){if("destroy"in options){return}}o.height=o.height=="auto"?me.parent().height():o.height;var wrapper=$(divs).addclass(o.wrapperclass).css({position:"relative",overflow:"hidden",width:o.width,height:o.height});me.css({overflow:"hidden",width:o.width,height:o.height,"-ms-touch-action":"none"});var rail=$(divs).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});var bar=$(divs).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});var poscss=o.position=="right"?{right:o.distance}:{left:o.distance};rail.css(poscss);bar.css(poscss);me.wrap(wrapper);me.parent().append(bar);me.parent().append(rail);if(o.raildraggable){bar.bind("mousedown",function(e){var $doc=$(document);isdragg=true;t=parsefloat(bar.css("top"));pagey=e.pagey;$doc.bind("mousemove.slimscroll",function(e){currtop=t+e.pagey-pagey;bar.css("top",currtop);scrollcontent(0,bar.position().top,false)});$doc.bind("mouseup.slimscroll",function(e){isdragg=false;hidebar();$doc.unbind(".slimscroll")});return false}).bind("selectstart.slimscroll",function(e){e.stoppropagation();e.preventdefault();return false})}rail.hover(function(){showbar()},function(){hidebar()});bar.hover(function(){isoverbar=true},function(){isoverbar=false});me.hover(function(){isoverpanel=true;showbar();hidebar()},function(){isoverpanel=false;hidebar()});if(window.navigator.mspointerenabled){me.bind("mspointerdown",function(e,b){if(e.originalevent.targettouches.length){touchdif=e.originalevent.targettouches[0].pagey}});me.bind("mspointermove",function(e){e.originalevent.preventdefault();if(e.originalevent.targettouches.length){var diff=(touchdif-e.originalevent.targettouches[0].pagey)/o.touchscrollstep;scrollcontent(diff,true);touchdif=e.originalevent.targettouches[0].pagey}})}else{me.bind("touchstart",function(e,b){if(e.originalevent.touches.length){touchdif=e.originalevent.touches[0].pagey}});me.bind("touchmove",function(e){if(!releasescroll){e.originalevent.preventdefault()}if(e.originalevent.touches.length){var diff=(touchdif-e.originalevent.touches[0].pagey)/o.touchscrollstep;scrollcontent(diff,true);touchdif=e.originalevent.touches[0].pagey}})}getbarheight();if(o.start==="bottom"){bar.css({top:me.outerheight()-bar.outerheight()});scrollcontent(0,true)}else if(o.start!=="top"){scrollcontent($(o.start).position().top,null,true);if(!o.alwaysvisible){bar.hide()}}attachwheel();function _onwheel(e){if(!isoverpanel){return}var e=e||window.event;var delta=0;if(e.wheeldelta){delta=-e.wheeldelta/120}if(e.detail){delta=e.detail/3}var target=e.target||e.srctarget||e.srcelement;if($(target).closest("."+o.wrapperclass).is(me.parent())){scrollcontent(delta,true)}if(e.preventdefault&&!releasescroll){e.preventdefault()}if(!releasescroll){e.returnvalue=false}}function scrollcontent(y,iswheel,isjump){releasescroll=false;var delta=y;var maxtop=me.outerheight()-bar.outerheight();if(iswheel){delta=parseint(bar.css("top"))+y*parseint(o.wheelstep)/100*bar.outerheight();delta=math.min(math.max(delta,0),maxtop);delta=y>0?math.ceil(delta):math.floor(delta);bar.css({top:delta+"px"})}percentscroll=parseint(bar.css("top"))/(me.outerheight()-bar.outerheight());delta=percentscroll*(me[0].scrollheight-me.outerheight());if(isjump){delta=y;var offsettop=delta/me[0].scrollheight*me.outerheight();offsettop=math.min(math.max(offsettop,0),maxtop);bar.css({top:offsettop+"px"})}me.scrolltop(delta);me.trigger("slimscrolling",~~delta);showbar();hidebar()}function attachwheel(){if(window.addeventlistener){this.addeventlistener("dommousescroll",_onwheel,false);this.addeventlistener("mousewheel",_onwheel,false)}else{document.attachevent("onmousewheel",_onwheel)}}function getbarheight(){barheight=math.max(me.outerheight()/me[0].scrollheight*me.outerheight(),minbarheight);bar.css({height:barheight+"px"});var display=barheight==me.outerheight()?"none":"block";bar.css({display:display})}function showbar(){getbarheight();cleartimeout(queuehide);if(percentscroll==~~percentscroll){releasescroll=o.allowpagescroll;if(lastscroll!=percentscroll){var msg=~~percentscroll==0?"top":"bottom";me.trigger("slimscroll",msg)}}else{releasescroll=false}lastscroll=percentscroll;if(barheight>=me.outerheight()){releasescroll=true;return}bar.stop(true,true).fadein("fast");if(o.railvisible){rail.stop(true,true).fadein("fast")}}function hidebar(){if(!o.alwaysvisible){queuehide=settimeout(function(){if(!(o.disablefadeout&&isoverpanel)&&!isoverbar&&!isdragg){bar.fadeout("slow");rail.fadeout("slow")}},1e3)}}});return this}});$.fn.extend({slimscroll:$.fn.slimscroll})})(jquery);