/*! 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: 1.3.8
 *
 */(function(l){l.fn.extend({slimScroll:function(n){var e=l.extend({width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:.4,alwaysVisible:!1,disableFadeOut:!1,railVisible:!1,railColor:"#333",railOpacity:.2,railDraggable:!0,railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv",allowPageScroll:!1,wheelStep:20,touchScrollStep:200,borderRadius:"7px",railBorderRadius:"7px"},n);return this.each(function(){function m(o){if(v){o=o||window.event;var a=0;o.wheelDelta&&(a=-o.wheelDelta/120),o.detail&&(a=o.detail/3),l(o.target||o.srcTarget||o.srcElement).closest("."+e.wrapperClass).is(i.parent())&&d(a,!0),o.preventDefault&&!c&&o.preventDefault(),c||(o.returnValue=!1)}}function d(o,a,M){c=!1;var r=i.outerHeight()-s.outerHeight();a&&(a=parseInt(s.css("top"))+o*parseInt(e.wheelStep)/100*s.outerHeight(),a=Math.min(Math.max(a,0),r),a=0<o?Math.ceil(a):Math.floor(a),s.css({top:a+"px"})),u=parseInt(s.css("top"))/(i.outerHeight()-s.outerHeight()),a=u*(i[0].scrollHeight-i.outerHeight()),M&&(a=o,o=a/i[0].scrollHeight*i.outerHeight(),o=Math.min(Math.max(o,0),r),s.css({top:o+"px"})),i.scrollTop(a),i.trigger("slimscrolling",~~a),x(),g()}function y(){f=Math.max(i.outerHeight()/i[0].scrollHeight*i.outerHeight(),30),s.css({height:f+"px"});var o=f==i.outerHeight()?"none":"block";s.css({display:o})}function x(){y(),clearTimeout(E),u==~~u?(c=e.allowPageScroll,R!=u&&i.trigger("slimscroll",~~u?"bottom":"top")):c=!1,R=u,f>=i.outerHeight()?c=!0:(s.stop(!0,!0).fadeIn("fast"),e.railVisible&&p.stop(!0,!0).fadeIn("fast"))}function g(){e.alwaysVisible||(E=setTimeout(function(){e.disableFadeOut&&v||C||H||(s.fadeOut("slow"),p.fadeOut("slow"))},1e3))}var v,C,H,E,S,f,u,R,c=!1,i=l(this);if(i.parent().hasClass(e.wrapperClass)){var b=i.scrollTop(),s=i.siblings("."+e.barClass),p=i.siblings("."+e.railClass);if(y(),l.isPlainObject(n)){if("height"in n&&n.height=="auto"){i.parent().css("height","auto"),i.css("height","auto");var h=i.parent().parent().height();i.parent().css("height",h),i.css("height",h)}else"height"in n&&(h=n.height,i.parent().css("height",h),i.css("height",h));if("scrollTo"in n)b=parseInt(e.scrollTo);else if("scrollBy"in n)b+=parseInt(e.scrollBy);else if("destroy"in n){s.remove(),p.remove(),i.unwrap();return}d(b,!1,!0)}}else if(!(l.isPlainObject(n)&&"destroy"in n)){e.height=e.height=="auto"?i.parent().height():e.height,b=l("<div></div>").addClass(e.wrapperClass).css({position:"relative",overflow:"hidden",width:e.width,height:e.height}),i.css({overflow:"hidden",width:e.width,height:e.height});var p=l("<div></div>").addClass(e.railClass).css({width:e.size,height:"100%",position:"absolute",top:0,display:e.alwaysVisible&&e.railVisible?"block":"none","border-radius":e.railBorderRadius,background:e.railColor,opacity:e.railOpacity,zIndex:90}),s=l("<div></div>").addClass(e.barClass).css({background:e.color,width:e.size,position:"absolute",top:0,opacity:e.opacity,display:e.alwaysVisible?"block":"none","border-radius":e.borderRadius,BorderRadius:e.borderRadius,MozBorderRadius:e.borderRadius,WebkitBorderRadius:e.borderRadius,zIndex:99}),h=e.position=="right"?{right:e.distance}:{left:e.distance};p.css(h),s.css(h),i.wrap(b),i.parent().append(s),i.parent().append(p),e.railDraggable&&s.bind("mousedown",function(r){var w=l(document);return H=!0,t=parseFloat(s.css("top")),pageY=r.pageY,w.bind("mousemove.slimscroll",function(D){currTop=t+D.pageY-pageY,s.css("top",currTop),d(0,s.position().top,!1)}),w.bind("mouseup.slimscroll",function(D){H=!1,g(),w.unbind(".slimscroll")}),!1}).bind("selectstart.slimscroll",function(r){return r.stopPropagation(),r.preventDefault(),!1}),p.hover(function(){x()},function(){g()}),s.hover(function(){C=!0},function(){C=!1}),i.hover(function(){v=!0,x(),g()},function(){v=!1,g()}),i.bind("touchstart",function(r,w){r.originalEvent.touches.length&&(S=r.originalEvent.touches[0].pageY)}),i.bind("touchmove",function(r){c||r.originalEvent.preventDefault(),r.originalEvent.touches.length&&(d((S-r.originalEvent.touches[0].pageY)/e.touchScrollStep,!0),S=r.originalEvent.touches[0].pageY)}),y(),e.start==="bottom"?(s.css({top:i.outerHeight()-s.outerHeight()}),d(0,!0)):e.start!=="top"&&(d(l(e.start).position().top,null,!0),e.alwaysVisible||s.hide()),window.addEventListener?(this.addEventListener("DOMMouseScroll",m,!1),this.addEventListener("mousewheel",m,!1)):document.attachEvent("onmousewheel",m)}}),this}}),l.fn.extend({slimscroll:l.fn.slimScroll})})(jQuery);
