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