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