(function(b){b.jScrollPane={active:[]};b.fn.jScrollPane=function(c){c=b.extend({},b.fn.jScrollPane.defaults,c);var l=function(){return false};return this.each(function(){var d=b(this),P=this,Q=0,k,f,o,t=c.topCapHeight;if(b(this).parent().is(".jScrollPaneContainer")){Q=c.maintainPosition?d.position().top:0;var i=b(this).parent();k=i.innerWidth();f=i.outerHeight();b(">.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown, >.jScrollCap",i).remove();d.css({top:0})}else{d.data("originalStyleTag",d.attr("style"));
d.css("overflow","hidden");this.originalPadding=d.css("paddingTop")+" "+d.css("paddingRight")+" "+d.css("paddingBottom")+" "+d.css("paddingLeft");this.originalSidePaddingTotal=(parseInt(d.css("paddingLeft"))||0)+(parseInt(d.css("paddingRight"))||0);k=d.innerWidth();f=d.innerHeight();var h=b("<div></div>").attr({className:"jScrollPaneContainer"}).css({height:f+"px",width:k+"px"});c.enableKeyboardNavigation&&h.attr("tabindex",c.tabIndex);d.wrap(h);b(document).bind("emchange",function(){d.jScrollPane(c)})}o=
f;if(c.reinitialiseOnImageLoad){var u=b.data(P,"jScrollPaneImagesToLoad")||b("img",d),R=[];u.length&&u.each(function(a,e){b(this).bind("load readystatechange",function(){if(b.inArray(a,R)==-1){R.push(e);u=b.grep(u,function(ca){return ca!=e});b.data(P,"jScrollPaneImagesToLoad",u);var g=b.extend(c,{reinitialiseOnImageLoad:false});d.jScrollPane(g)}}).each(function(){if(this.complete||this.complete===undefined)this.src=this.src})})}i={height:"auto",width:k-c.scrollbarWidth-c.scrollbarMargin-this.originalSidePaddingTotal+
"px"};if(c.scrollbarOnLeft)i.paddingLeft=c.scrollbarMargin+c.scrollbarWidth+"px";else i.paddingRight=c.scrollbarMargin+"px";d.css(i);var v=d.outerHeight(),z=f/v;if(z<0.99){h=d.parent();h.append(b("<div></div>").addClass("jScrollCap jScrollCapTop").css({height:c.topCapHeight}),b("<div></div>").attr({className:"jScrollPaneTrack"}).css({width:c.scrollbarWidth+"px"}).append(b("<div></div>").attr({className:"jScrollPaneDrag"}).css({width:c.scrollbarWidth+"px"}).append(b("<div></div>").attr({className:"jScrollPaneDragTop"}).css({width:c.scrollbarWidth+
"px"}),b("<div></div>").attr({className:"jScrollPaneDragBottom"}).css({width:c.scrollbarWidth+"px"}))),b("<div></div>").addClass("jScrollCap jScrollCapBottom").css({height:c.bottomCapHeight}));k=b(">.jScrollPaneTrack",h);var A=b(">.jScrollPaneTrack .jScrollPaneDrag",h),w,p=[],q,r=function(){if(q>4||q%4==0)m(j+w*K);q++};c.enableKeyboardNavigation&&h.bind("keydown.jscrollpane",function(a){switch(a.keyCode){case 38:w=-1;q=0;r();p[p.length]=setInterval(r,100);return false;case 40:w=1;q=0;r();p[p.length]=
setInterval(r,100);return false;case 33:case 34:return false;default:}}).bind("keyup.jscrollpane",function(a){if(a.keyCode==38||a.keyCode==40){for(a=0;a<p.length;a++)clearInterval(p[a]);return false}});if(c.showArrows){var B,S,T=function(){b("html").unbind("mouseup",T);B.removeClass("jScrollActiveArrowButton");clearInterval(S)},U=function(){b("html").bind("mouseup",T);B.addClass("jScrollActiveArrowButton");q=0;r();S=setInterval(r,100)};h.append(b("<a></a>").attr({href:"javascript:;",className:"jScrollArrowUp",
tabindex:-1}).css({width:c.scrollbarWidth+"px",top:c.topCapHeight+"px"}).html("Scroll up").bind("mousedown",function(){B=b(this);w=-1;U();this.blur();return false}).bind("click",l),b("<a></a>").attr({href:"javascript:;",className:"jScrollArrowDown",tabindex:-1}).css({width:c.scrollbarWidth+"px",bottom:c.bottomCapHeight+"px"}).html("Scroll down").bind("mousedown",function(){B=b(this);w=1;U();this.blur();return false}).bind("click",l));var L=b(">.jScrollArrowUp",h),V=b(">.jScrollArrowDown",h)}if(c.arrowSize){o=
f-c.arrowSize-c.arrowSize;t+=c.arrowSize}else if(L){i=L.height();c.arrowSize=i;o=f-i-V.height();t+=i}o-=c.topCapHeight+c.bottomCapHeight;k.css({height:o+"px",top:t+"px"});var M=b(this).css({position:"absolute",overflow:"visible"}),x,n,K,j=0,C=z*f/2,D=function(a,e){var g=e=="X"?"Left":"Top";return a["page"+e]||a["client"+e]+(document.documentElement["scroll"+g]||document.body["scroll"+g])||0},E=function(){return false},G=function(){F();x=A.offset(false);x.top-=j;n=o-A[0].offsetHeight;K=2*c.wheelSpeed*
n/v},W=function(){b("html").unbind("mouseup",W).unbind("mousemove",X);C=z*f/2;b.browser.msie&&b("html").unbind("dragstart",E).unbind("selectstart",E)},m=function(a){h.scrollTop(0);j=a=a<0?0:a>n?n:a;A.css({top:a+"px"});var e=a/n;d.data("jScrollPanePosition",(f-v)*-e);M.css({top:(f-v)*e+"px"});d.trigger("scroll");if(c.showArrows){L[a==0?"addClass":"removeClass"]("disabled");V[a==n?"addClass":"removeClass"]("disabled")}},X=function(a){m(D(a,"Y")-x.top-C)};t=Math.max(Math.min(z*(f-c.arrowSize*2),c.dragMaxHeight),
c.dragMinHeight);A.css({height:t+"px"}).bind("mousedown",function(a){G();C=D(a,"Y")-j-x.top;b("html").bind("mouseup",W).bind("mousemove",X);b.browser.msie&&b("html").bind("dragstart",E).bind("selectstart",E);return false});var Y,H,Z,$=function(){if(H>8||H%4==0)m(j-(j-Z)/2);H++},aa=function(){clearInterval(Y);b("html").unbind("mouseup",aa).unbind("mousemove",N)},N=function(a){Z=D(a,"Y")-x.top-C};k.bind("mousedown",function(a){G();N(a);H=0;b("html").bind("mouseup",aa).bind("mousemove",N);Y=setInterval($,
100);$();return false});h.bind("mousewheel",function(a,e){e=e||(a.wheelDelta?a.wheelDelta/120:a.detail?-a.detail/3:0);G();F();a=j;m(j-e*K);return a==j});var I,O;function da(){var a=(I-j)/c.animateStep;if(a>1||a<-1)m(j+a);else{m(I);F()}}var F=function(){if(O){clearInterval(O);delete I}},s=function(a,e){if(typeof a=="string"){$e=b(a,d);if(!$e.length)return;a=$e.offset().top-d.offset().top}F();var g=v-f;a=a>g?g:a;d.data("jScrollPaneMaxScroll",g);a=a/g*n;if(e||!c.animateTo)m(a);else{h.scrollTop(0);I=
a;O=setInterval(da,c.animateInterval)}};d[0].scrollTo=s;d[0].scrollBy=function(a){var e=-parseInt(M.css("top"))||0;s(e+a)};G();s(-Q,true);b("*",this).bind("focus",function(){for(var a=b(this),e=0;a[0]!=d[0];){e+=a.position().top;a=a.offsetParent()}a=-parseInt(M.css("top"))||0;var g=a+f;if(!(e>a&&e<g)){g=e-c.scrollbarMargin;if(e>a)g+=b(this).height()+15+c.scrollbarMargin-f;s(g)}});if(location.hash&&location.hash.length>1)setTimeout(function(){s(location.hash)},b.browser.safari?100:0);b(document).bind("click",
function(a){$target=b(a.target);if($target.is("a")){var e=$target.attr("href");if(e&&e.substr(0,1)=="#"&&e.length>1)setTimeout(function(){s(e,!c.animateToInternalLinks)},b.browser.safari?100:0)}});function ea(){b(document).bind("mousemove.jScrollPaneDragging",fa);b(document).bind("mouseup.jScrollPaneDragging",ga)}var J,y;function ha(){direction=J<0?-1:1;d[0].scrollBy(J/2)}function ba(){if(y){clearInterval(y);y=undefined}}function fa(a){var e=d.parent().offset().top,g=e+f;a=D(a,"Y");J=a<e?a-e:a>g?
a-g:0;if(J==0)ba();else y||(y=setInterval(ha,100))}function ga(){b(document).unbind("mousemove.jScrollPaneDragging").unbind("mouseup.jScrollPaneDragging");ba()}h.bind("mousedown.jScrollPane",ea);b.jScrollPane.active.push(d[0])}else{d.css({height:f+"px",width:k-this.originalSidePaddingTotal+"px",padding:this.originalPadding});d[0].scrollTo=d[0].scrollBy=function(){};d.parent().unbind("mousewheel").unbind("mousedown.jScrollPane").unbind("keydown.jscrollpane").unbind("keyup.jscrollpane")}})};b.fn.jScrollPaneRemove=
function(){b(this).each(function(){$this=b(this);var c=$this.parent();if(c.is(".jScrollPaneContainer")){$this.css({top:"",height:"",width:"",padding:"",overflow:"",position:""});$this.attr("style",$this.data("originalStyleTag"));c.after($this).remove()}})};b.fn.jScrollPane.defaults={scrollbarWidth:10,scrollbarMargin:5,wheelSpeed:18,showArrows:false,arrowSize:0,animateTo:false,dragMinHeight:1,dragMaxHeight:99999,animateInterval:100,animateStep:3,maintainPosition:true,scrollbarOnLeft:false,reinitialiseOnImageLoad:false,
tabIndex:0,enableKeyboardNavigation:true,animateToInternalLinks:false,topCapHeight:0,bottomCapHeight:0};b(window).bind("unload",function(){for(var c=b.jScrollPane.active,l=0;l<c.length;l++)c[l].scrollTo=c[l].scrollBy=null})})(jQuery);