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