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