/*! 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.4.0
 * 
 */(function(d){jQuery.fn.extend({slimScroll:function(l){var a=ops=d.extend({wheelStep:20,width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:0.4,alwaysVisible:!1,railVisible:!1,railColor:"#333",railOpacity:"0.2",railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv"},l);this.each(function(){var m,n,o,u,p,q=!1,l=parseInt(a.wheelStep),g=a.width,v=a.height,f=a.size,z=a.color,A=a.position,w=a.distance,r=a.start,B=a.opacity,j=
a.alwaysVisible,x=a.railVisible,C=a.railColor,D=a.railOpacity,b=d(this),E=d("<div></div>").addClass(a.wrapperClass).css({position:"relative",overflow:"hidden",width:g,height:v});b.css({overflow:"hidden",width:g,height:v});var h=d("<div></div>").addClass(a.railClass).css({width:f,height:"100%",position:"absolute",top:0,display:j&&x?"block":"none","border-radius":f,background:C,opacity:D,zIndex:90}),c=d("<div></div>").addClass(a.barClass).css({background:z,width:f,position:"absolute",top:0,opacity:B,
display:j?"block":"none","border-radius":f,BorderRadius:f,MozBorderRadius:f,WebkitBorderRadius:f,zIndex:99}),g="right"==A?{right:w}:{left:w};h.css(g);c.css(g);b.wrap(E);b.parent().append(c);b.parent().append(h);c.draggable({axis:"y",containment:"parent",start:function(){o=!0},stop:function(){o=!1;i()},drag:function(){k(0,d(this).position().top,!1)}});h.hover(function(){s()},function(){i()});c.hover(function(){n=!0},function(){n=!1});b.hover(function(){m=!0;s();i()},function(){m=!1;i()});var t=function(a){if(m){var a=
a||window.event,b=0;a.wheelDelta&&(b=-a.wheelDelta/120);a.detail&&(b=a.detail/3);k(b,!0);a.preventDefault&&!q&&a.preventDefault();if(!q)a.returnValue=!1}},k=function(a,d,f){var e=a;d&&(e=c.position().top+a*l,e=Math.max(e,0),d=b.outerHeight()-c.outerHeight(),e=Math.min(e,d),c.css({top:e+"px"}));e=parseInt(c.position().top)/(b.outerHeight()-c.outerHeight())*(b[0].scrollHeight-b.outerHeight());f&&(e=a,a=e/b[0].scrollHeight*b.outerHeight(),c.css({top:a+"px"}));b.scrollTop(e);s();i()};(function(){window.addEventListener?
(this.addEventListener("DOMMouseScroll",t,!1),this.addEventListener("mousewheel",t,!1)):document.attachEvent("onmousewheel",t)})();var y=function(){p=Math.max(b.outerHeight()/b[0].scrollHeight*b.outerHeight(),30);c.css({height:p+"px"})};y();var s=function(){y();clearTimeout(u);p>=b.outerHeight()?q=!0:(c.fadeIn("fast"),x&&h.fadeIn("fast"))},i=function(){j||(u=setTimeout(function(){!n&&!o&&(c.fadeOut("slow"),h.fadeOut("slow"))},1E3))};"bottom"==r?(c.css({top:"auto",bottom:0}),k(0,!0)):"object"==typeof r&&
(k(d(r).position().top,null,!0),j||c.hide())});return this}});jQuery.fn.extend({slimscroll:jQuery.fn.slimScroll})})(jQuery);
