/*! Copyright (c) 2011 Piotr Rochala (http://rocha.la) * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * * Version: 0.6.5 * */ (function(d){jQuery.fn.extend({slimScroll:function(m){var a=d.extend({wheelStep:20,width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:0.4,alwaysVisible:!1,disableFadeOut:!1,railVisible:!1,railColor:"#333",railOpacity:"0.2",railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv",allowPageScroll:!1,scroll:0,touchScrollStep:200},m);this.each(function(){function e(i,d,e){var f=i;d&&(f=parseInt(c.css("top"))+i*parseInt(a.wheelStep)/ 100*c.outerHeight(),d=b.outerHeight()-c.outerHeight(),f=Math.min(Math.max(f,0),d),c.css({top:f+"px"}));g=parseInt(c.css("top"))/(b.outerHeight()-c.outerHeight());f=g*(b[0].scrollHeight-b.outerHeight());e&&(f=i,i=f/b[0].scrollHeight*b.outerHeight(),c.css({top:i+"px"}));b.scrollTop(f);n();j()}function t(){p=Math.max(b.outerHeight()/b[0].scrollHeight*b.outerHeight(),m);c.css({height:p+"px"})}function n(){t();clearTimeout(u);g==~~g&&(k=a.allowPageScroll,v!=g&&b.trigger("slimscroll",0==~~g?"top":"bottom")); v=g;p>=b.outerHeight()?k=!0:(c.stop(!0,!0).fadeIn("fast"),a.railVisible&&h.stop(!0,!0).fadeIn("fast"))}function j(){a.alwaysVisible||(u=setTimeout(function(){if((!a.disableFadeOut||!l)&&!q&&!r)c.fadeOut("slow"),h.fadeOut("slow")},1E3))}var l,q,r,u,w,p,g,v,m=30,k=!1,b=d(this);if(b.parent().hasClass("slimScrollDiv"))scroll&&(c=b.parent().find(".slimScrollBar"),h=b.parent().find(".slimScrollRail"),e(b.scrollTop()+parseInt(scroll),!1,!0));else{var y=d("
").addClass(a.wrapperClass).css({position:"relative", overflow:"hidden",width:a.width,height:a.height});b.css({overflow:"hidden",width:a.width,height:a.height});var h=d("
").addClass(a.railClass).css({width:a.size,height:"100%",position:"absolute",top:0,display:a.alwaysVisible&&a.railVisible?"block":"none","border-radius":a.size,background:a.railColor,opacity:a.railOpacity,zIndex:90}),c=d("
").addClass(a.barClass).css({background:a.color,width:a.size,position:"absolute",top:0,opacity:a.opacity,display:a.alwaysVisible?"block":"none", "border-radius":a.size,BorderRadius:a.size,MozBorderRadius:a.size,WebkitBorderRadius:a.size,zIndex:99}),x="right"==a.position?{right:a.distance}:{left:a.distance};h.css(x);c.css(x);b.wrap(y);b.parent().append(c);b.parent().append(h);c.draggable({axis:"y",containment:"parent",start:function(){r=!0},stop:function(){r=!1;j()},drag:function(){e(0,d(this).position().top,!1)}});h.hover(function(){n()},function(){j()});c.hover(function(){q=!0},function(){q=!1});b.hover(function(){l=!0;n();j()},function(){l= !1;j()});b.bind("touchstart",function(a){a.originalEvent.touches.length&&(w=a.originalEvent.touches[0].pageY)});b.bind("touchmove",function(b){b.originalEvent.preventDefault();b.originalEvent.touches.length&&e((w-b.originalEvent.touches[0].pageY)/a.touchScrollStep,!0)});var s=function(a){if(l){var a=a||window.event,b=0;a.wheelDelta&&(b=-a.wheelDelta/120);a.detail&&(b=a.detail/3);e(b,!0);a.preventDefault&&!k&&a.preventDefault();k||(a.returnValue=!1)}};(function(){window.addEventListener?(this.addEventListener("DOMMouseScroll", s,!1),this.addEventListener("mousewheel",s,!1)):document.attachEvent("onmousewheel",s)})();t();"bottom"==a.start?(c.css({top:b.outerHeight()-c.outerHeight()}),e(0,!0)):"object"==typeof a.start&&(e(d(a.start).position().top,null,!0),a.alwaysVisible||c.hide())}});return this}});jQuery.fn.extend({slimscroll:jQuery.fn.slimScroll})})(jQuery);