/*! 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(o){o.fn.extend({slimScroll:function(n){var V={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"},e=o.extend(V,n);return this.each(function(){var g,b,w,D,m,v,c,E,H="<div></div>",T=30,h=!1,i=o(this);if(i.parent().hasClass(e.wrapperClass)){var C=i.scrollTop();if(a=i.siblings("."+e.barClass),d=i.siblings("."+e.railClass),x(),o.isPlainObject(n)){if("height"in n&&n.height=="auto"){i.parent().css("height","auto"),i.css("height","auto");var O=i.parent().parent().height();i.parent().css("height",O),i.css("height",O)}else if("height"in n){var R=n.height;i.parent().css("height",R),i.css("height",R)}if("scrollTo"in n)C=parseInt(e.scrollTo);else if("scrollBy"in n)C+=parseInt(e.scrollBy);else if("destroy"in n){a.remove(),d.remove(),i.unwrap();return}p(C,!1,!0)}return}else if(o.isPlainObject(n)&&"destroy"in n)return;e.height=e.height=="auto"?i.parent().height():e.height;var Y=o(H).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 d=o(H).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}),a=o(H).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}),M=e.position=="right"?{right:e.distance}:{left:e.distance};d.css(M),a.css(M),i.wrap(Y),i.parent().append(a),i.parent().append(d),e.railDraggable&&a.bind("mousedown",function(r){var s=o(document);return w=!0,t=parseFloat(a.css("top")),pageY=r.pageY,s.bind("mousemove.slimscroll",function(u){currTop=t+u.pageY-pageY,a.css("top",currTop),p(0,a.position().top,!1)}),s.bind("mouseup.slimscroll",function(u){w=!1,f(),s.unbind(".slimscroll")}),!1}).bind("selectstart.slimscroll",function(r){return r.stopPropagation(),r.preventDefault(),!1}),d.hover(function(){y()},function(){f()}),a.hover(function(){b=!0},function(){b=!1}),i.hover(function(){g=!0,y(),f()},function(){g=!1,f()}),i.bind("touchstart",function(r,s){r.originalEvent.touches.length&&(m=r.originalEvent.touches[0].pageY)}),i.bind("touchmove",function(r){if(h||r.originalEvent.preventDefault(),r.originalEvent.touches.length){var s=(m-r.originalEvent.touches[0].pageY)/e.touchScrollStep;p(s,!0),m=r.originalEvent.touches[0].pageY}}),x(),e.start==="bottom"?(a.css({top:i.outerHeight()-a.outerHeight()}),p(0,!0)):e.start!=="top"&&(p(o(e.start).position().top,null,!0),e.alwaysVisible||a.hide()),k(this);function S(s){if(g){var s=s||window.event,u=0;s.wheelDelta&&(u=-s.wheelDelta/120),s.detail&&(u=s.detail/3);var l=s.target||s.srcTarget||s.srcElement;o(l).closest("."+e.wrapperClass).is(i.parent())&&p(u,!0),s.preventDefault&&!h&&s.preventDefault(),h||(s.returnValue=!1)}}function p(r,s,u){h=!1;var l=r,I=i.outerHeight()-a.outerHeight();if(s&&(l=parseInt(a.css("top"))+r*parseInt(e.wheelStep)/100*a.outerHeight(),l=Math.min(Math.max(l,0),I),l=r>0?Math.ceil(l):Math.floor(l),a.css({top:l+"px"})),c=parseInt(a.css("top"))/(i.outerHeight()-a.outerHeight()),l=c*(i[0].scrollHeight-i.outerHeight()),u){l=r;var B=l/i[0].scrollHeight*i.outerHeight();B=Math.min(Math.max(B,0),I),a.css({top:B+"px"})}i.scrollTop(l),i.trigger("slimscrolling",~~l),y(),f()}function k(r){window.addEventListener?(r.addEventListener("DOMMouseScroll",S,!1),r.addEventListener("mousewheel",S,!1)):document.attachEvent("onmousewheel",S)}function x(){v=Math.max(i.outerHeight()/i[0].scrollHeight*i.outerHeight(),T),a.css({height:v+"px"});var r=v==i.outerHeight()?"none":"block";a.css({display:r})}function y(){if(x(),clearTimeout(D),c==~~c){if(h=e.allowPageScroll,E!=c){var r=~~c?"bottom":"top";i.trigger("slimscroll",r)}}else h=!1;if(E=c,v>=i.outerHeight()){h=!0;return}a.stop(!0,!0).fadeIn("fast"),e.railVisible&&d.stop(!0,!0).fadeIn("fast")}function f(){e.alwaysVisible||(D=setTimeout(function(){!(e.disableFadeOut&&g)&&!b&&!w&&(a.fadeOut("slow"),d.fadeOut("slow"))},1e3))}}),this}}),o.fn.extend({slimscroll:o.fn.slimScroll})})(jQuery);
