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