(function(a,b,c){a.fn.jScrollPane=function(b){function d(b,d){function T(d){var f,q,r,t,u,w,x=!1,y=!1;e=d;if(g===c)u=b.scrollTop(),w=b.scrollLeft(),b.css({overflow:"hidden",padding:0}),h=b.innerWidth()+L,i=b.innerHeight(),b.width(h),g=a('<div class="jspPane" />').css("padding",K).append(b.children()),j=a('<div class="jspContainer" />').css({width:h+"px",height:i+"px"}).append(g).appendTo(b);else{b.css("width",""),x=e.stickToBottom&&bp(),y=e.stickToRight&&bq(),t=b.innerWidth()+L!=h||b.outerHeight()!=i,t&&(h=b.innerWidth()+L,i=b.innerHeight(),j.css({width:h+"px",height:i+"px"}));if(!t&&M==k&&g.outerHeight()==l){b.width(h);return}M=k,g.css("width",""),b.width(h),j.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}g.css("overflow","auto"),d.contentWidth?k=d.contentWidth:k=g[0].scrollWidth,l=g[0].scrollHeight,g.css("overflow",""),m=k/h,n=l/i,o=n>1,p=m>1,!p&&!o?(b.removeClass("jspScrollable"),g.css({top:0,width:j.width()-L}),bs(),bv(),bx(),bc(),bz()):(b.addClass("jspScrollable"),f=e.maintainPosition&&(s||v),f&&(q=bn(),r=bo()),U(),W(),Y(),f&&(bl(y?k-h:q,!1),bk(x?l-i:r,!1)),bu(),br(),bB(),e.enableKeyboardNavigation&&bw(),e.clickOnTrack&&bb(),by(),e.hijackInternalLinks&&bA()),e.autoReinitialise&&!J?J=setInterval(function(){T(e)},e.autoReinitialiseDelay):!e.autoReinitialise&&J&&clearInterval(J),u&&b.scrollTop(0)&&bk(u,!1),w&&b.scrollLeft(0)&&bl(w,!1),b.trigger("jsp-initialised",[p||o])}function U(){o&&(j.append(a('<div class="jspVerticalBar" />').append(a('<div class="jspCap jspCapTop" />'),a('<div class="jspTrack" />').append(a('<div class="jspDrag" />').append(a('<div class="jspDragTop" />'),a('<div class="jspDragBottom" />'))),a('<div class="jspCap jspCapBottom" />'))),w=j.find(">.jspVerticalBar"),x=w.find(">.jspTrack"),q=x.find(">.jspDrag"),e.showArrows&&(B=a('<a class="jspArrow jspArrowUp" />').bind("mousedown.jsp",_(0,-1)).bind("click.jsp",bt),C=a('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp",_(0,1)).bind("click.jsp",bt),e.arrowScrollOnHover&&(B.bind("mouseover.jsp",_(0,-1,B)),C.bind("mouseover.jsp",_(0,1,C))),Z(x,e.verticalArrowPositions,B,C)),z=i,j.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){z-=a(this).outerHeight()}),q.hover(function(){q.addClass("jspHover")},function(){q.removeClass("jspHover")}).bind("mousedown.jsp",function(b){a("html").bind("dragstart.jsp selectstart.jsp",bt),q.addClass("jspActive");var c=b.pageY-q.position().top;return a("html").bind("mousemove.jsp",function(a){be(a.pageY-c,!1)}).bind("mouseup.jsp mouseleave.jsp",bd),!1}),V())}function V(){x.height(z+"px"),s=0,y=e.verticalGutter+x.outerWidth(),g.width(h-y-L);try{w.position().left===0&&g.css("margin-left",y+"px")}catch(a){}}function W(){p&&(j.append(a('<div class="jspHorizontalBar" />').append(a('<div class="jspCap jspCapLeft" />'),a('<div class="jspTrack" />').append(a('<div class="jspDrag" />').append(a('<div class="jspDragLeft" />'),a('<div class="jspDragRight" />'))),a('<div class="jspCap jspCapRight" />'))),D=j.find(">.jspHorizontalBar"),E=D.find(">.jspTrack"),t=E.find(">.jspDrag"),e.showArrows&&(H=a('<a class="jspArrow jspArrowLeft" />').bind("mousedown.jsp",_(-1,0)).bind("click.jsp",bt),I=a('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp",_(1,0)).bind("click.jsp",bt),e.arrowScrollOnHover&&(H.bind("mouseover.jsp",_(-1,0,H)),I.bind("mouseover.jsp",_(1,0,I))),Z(E,e.horizontalArrowPositions,H,I)),t.hover(function(){t.addClass("jspHover")},function(){t.removeClass("jspHover")}).bind("mousedown.jsp",function(b){a("html").bind("dragstart.jsp selectstart.jsp",bt),t.addClass("jspActive");var c=b.pageX-t.position().left;return a("html").bind("mousemove.jsp",function(a){bg(a.pageX-c,!1)}).bind("mouseup.jsp mouseleave.jsp",bd),!1}),F=j.innerWidth(),X())}function X(){j.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){F-=a(this).outerWidth()}),E.width(F+"px"),v=0}function Y(){if(p&&o){var b=E.outerHeight(),c=x.outerWidth();z-=b,a(D).find(">.jspCap:visible,>.jspArrow").each(function(){F+=a(this).outerWidth()}),F-=c,i-=c,h-=b,E.parent().append(a('<div class="jspCorner" />').css("width",b+"px")),V(),X()}p&&g.width(j.outerWidth()-L+"px"),l=g.outerHeight(),n=l/i,p&&(G=Math.ceil(1/m*F),G>e.horizontalDragMaxWidth?G=e.horizontalDragMaxWidth:G<e.horizontalDragMinWidth&&(G=e.horizontalDragMinWidth),t.width(G+"px"),u=F-G,bh(v)),o&&(A=Math.ceil(1/n*z),A>e.verticalDragMaxHeight?A=e.verticalDragMaxHeight:A<e.verticalDragMinHeight&&(A=e.verticalDragMinHeight),q.height(A+"px"),r=z-A,bf(s))}function Z(a,b,c,d){var e="before",f="after",g;b=="os"&&(b=/Mac/.test(navigator.platform)?"after":"split"),b==e?f=b:b==f&&(e=b,g=c,c=d,d=g),a[e](c)[f](d)}function _(a,b,c){return function(){return ba(a,b,this,c),this.blur(),!1}}function ba(b,c,d,g){d=a(d).addClass("jspActive");var h,i,j=!0,k=function(){b!==0&&f.scrollByX(b*e.arrowButtonSpeed),c!==0&&f.scrollByY(c*e.arrowButtonSpeed),i=setTimeout(k,j?e.initialDelay:e.arrowRepeatFreq),j=!1};k(),h=g?"mouseout.jsp":"mouseup.jsp",g=g||a("html"),g.bind(h,function(){d.removeClass("jspActive"),i&&clearTimeout(i),i=null,g.unbind(h)})}function bb(){bc(),o&&x.bind("mousedown.jsp",function(b){if(b.originalTarget===c||b.originalTarget==b.currentTarget){var d=a(this),g=d.offset(),h=b.pageY-g.top-s,j,k=!0,m=function(){var a=d.offset(),c=b.pageY-a.top-A/2,g=i*e.scrollPagePercent,o=r*g/(l-i);if(h<0)s-o>c?f.scrollByY(-g):be(c);else if(h>0)s+o<c?f.scrollByY(g):be(c);else{n();return}j=setTimeout(m,k?e.initialDelay:e.trackClickRepeatFreq),k=!1},n=function(){j&&clearTimeout(j),j=null,a(document).unbind("mouseup.jsp",n)};return m(),a(document).bind("mouseup.jsp",n),!1}}),p&&E.bind("mousedown.jsp",function(b){if(b.originalTarget===c||b.originalTarget==b.currentTarget){var d=a(this),g=d.offset(),i=b.pageX-g.left-v,j,l=!0,m=function(){var a=d.offset(),c=b.pageX-a.left-G/2,g=h*e.scrollPagePercent,o=u*g/(k-h);if(i<0)v-o>c?f.scrollByX(-g):bg(c);else if(i>0)v+o<c?f.scrollByX(g):bg(c);else{n();return}j=setTimeout(m,l?e.initialDelay:e.trackClickRepeatFreq),l=!1},n=function(){j&&clearTimeout(j),j=null,a(document).unbind("mouseup.jsp",n)};return m(),a(document).bind("mouseup.jsp",n),!1}})}function bc(){E&&E.unbind("mousedown.jsp"),x&&x.unbind("mousedown.jsp")}function bd(){a("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp"),q&&q.removeClass("jspActive"),t&&t.removeClass("jspActive")}function be(a,b){if(!o)return;a<0?a=0:a>r&&(a=r),b===c&&(b=e.animateScroll),b?f.animate(q,"top",a,bf):(q.css("top",a),bf(a))}function bf(a){a===c&&(a=q.position().top),j.scrollTop(0),s=a;var d=s===0,e=s==r,f=a/r,h=-f*(l-i);if(N!=d||P!=e)N=d,P=e,b.trigger("jsp-arrow-change",[N,P,O,Q]);bi(d,e),g.css("top",h),b.trigger("jsp-scroll-y",[-h,d,e]).trigger("scroll")}function bg(a,b){if(!p)return;a<0?a=0:a>u&&(a=u),b===c&&(b=e.animateScroll),b?f.animate(t,"left",a,bh):(t.css("left",a),bh(a))}function bh(a){a===c&&(a=t.position().left),j.scrollTop(0),v=a;var d=v===0,e=v==u,f=a/u,i=-f*(k-h);if(O!=d||Q!=e)O=d,Q=e,b.trigger("jsp-arrow-change",[N,P,O,Q]);bj(d,e),g.css("left",i),b.trigger("jsp-scroll-x",[-i,d,e]).trigger("scroll")}function bi(a,b){e.showArrows&&(B[a?"addClass":"removeClass"]("jspDisabled"),C[b?"addClass":"removeClass"]("jspDisabled"))}function bj(a,b){e.showArrows&&(H[a?"addClass":"removeClass"]("jspDisabled"),I[b?"addClass":"removeClass"]("jspDisabled"))}function bk(a,b){var c=a/(l-i);be(c*r,b)}function bl(a,b){var c=a/(k-h);bg(c*u,b)}function bm(b,c,d){var f,g,k,l=0,m=0,n,o,p,q,r,s;try{f=a(b)}catch(t){return}g=f.outerHeight(),k=f.outerWidth(),j.scrollTop(0),j.scrollLeft(0);while(!f.is(".jspPane")){l+=f.position().top,m+=f.position().left,f=f.offsetParent();if(/^body|html$/i.test(f[0].nodeName))return}n=bo(),p=n+i,l<n||c?r=l-e.verticalGutter:l+g>p&&(r=l-i+g+e.verticalGutter),r&&bk(r,d),o=bn(),q=o+h,m<o||c?s=m-e.horizontalGutter:m+k>q&&(s=m-h+k+e.horizontalGutter),s&&bl(s,d)}function bn(){return-g.position().left}function bo(){return-g.position().top}function bp(){var a=l-i;return a>20&&a-bo()<10}function bq(){var a=k-h;return a>20&&a-bn()<10}function br(){j.unbind(S).bind(S,function(a,b,c,d){var g=v,h=s;return f.scrollBy(c*e.mouseWheelSpeed,-d*e.mouseWheelSpeed,!1),g==v&&h==s})}function bs(){j.unbind(S)}function bt(){return!1}function bu(){g.find(":input,a").unbind("focus.jsp").bind("focus.jsp",function(a){bm(a.target,!1)})}function bv(){g.find(":input,a").unbind("focus.jsp")}function bw(){function k(){var a=v,b=s;switch(c){case 40:f.scrollByY(e.keyboardSpeed,!1);break;case 38:f.scrollByY(-e.keyboardSpeed,!1);break;case 34:case 32:f.scrollByY(i*e.scrollPagePercent,!1);break;case 33:f.scrollByY(-i*e.scrollPagePercent,!1);break;case 39:f.scrollByX(e.keyboardSpeed,!1);break;case 37:f.scrollByX(-e.keyboardSpeed,!1)}return d=a!=v||b!=s,d}var c,d,h=[];p&&h.push(D[0]),o&&h.push(w[0]),g.focus(function(){b.focus()}),b.attr("tabindex",0).unbind("keydown.jsp keypress.jsp").bind("keydown.jsp",function(b){if(b.target!==this&&(!h.length||!a(b.target).closest(h).length))return;var e=v,f=s;switch(b.keyCode){case 40:case 38:case 34:case 32:case 33:case 39:case 37:c=b.keyCode,k();break;case 35:bk(l-i),c=null;break;case 36:bk(0),c=null}return d=b.keyCode==c&&e!=v||f!=s,!d}).bind("keypress.jsp",function(a){return a.keyCode==c&&k(),!d}),e.hideFocus?(b.css("outline","none"),"hideFocus"in j[0]&&b.attr("hideFocus",!0)):(b.css("outline",""),"hideFocus"in j[0]&&b.attr("hideFocus",!1))}function bx(){b.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp keypress.jsp")}function by(){if(location.hash&&location.hash.length>1){var b,c,d=escape(location.hash);try{b=a(d)}catch(e){return}b.length&&g.find(d)&&(j.scrollTop()===0?c=setInterval(function(){j.scrollTop()>0&&(bm(d,!0),a(document).scrollTop(j.position().top),clearInterval(c))},50):(bm(d,!0),a(document).scrollTop(j.position().top)))}}function bz(){a("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function bA(){bz(),a("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",function(){var a=this.href.split("#"),b;if(a.length>1){b=a[1];if(b.length>0&&g.find("#"+b).length>0)return bm("#"+b,!0),!1}})}function bB(){var a,b,c,d,e,g=!1;j.unbind("touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick").bind("touchstart.jsp",function(f){var h=f.originalEvent.touches[0];a=bn(),b=bo(),c=h.pageX,d=h.pageY,e=!1,g=!0}).bind("touchmove.jsp",function(h){if(!g)return;var i=h.originalEvent.touches[0],j=v,k=s;return f.scrollTo(a+c-i.pageX,b+d-i.pageY),e=e||Math.abs(c-i.pageX)>5||Math.abs(d-i.pageY)>5,j==v&&k==s}).bind("touchend.jsp",function(a){g=!1}).bind("click.jsp-touchclick",function(a){if(e)return e=!1,!1})}function bC(){var a=bo(),c=bn();b.removeClass("jspScrollable").unbind(".jsp"),b.replaceWith(R.append(g.children())),R.scrollTop(a),R.scrollLeft(c)}var e,f=this,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N=!0,O=!0,P=!1,Q=!1,R=b.clone(!1,!1).empty(),S=a.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";K=b.css("paddingTop")+" "+b.css("paddingRight")+" "+b.css("paddingBottom")+" "+b.css("paddingLeft"),L=(parseInt(b.css("paddingLeft"),10)||0)+(parseInt(b.css("paddingRight"),10)||0),a.extend(f,{reinitialise:function(b){b=a.extend({},e,b),T(b)},scrollToElement:function(a,b,c){bm(a,b,c)},scrollTo:function(a,b,c){bl(a,c),bk(b,c)},scrollToX:function(a,b){bl(a,b)},scrollToY:function(a,b){bk(a,b)},scrollToPercentX:function(a,b){bl(a*(k-h),b)},scrollToPercentY:function(a,b){bk(a*(l-i),b)},scrollBy:function(a,b,c){f.scrollByX(a,c),f.scrollByY(b,c)},scrollByX:function(a,b){var c=bn()+Math[a<0?"floor":"ceil"](a),d=c/(k-h);bg(d*u,b)},scrollByY:function(a,b){var c=bo()+Math[a<0?"floor":"ceil"](a),d=c/(l-i);be(d*r,b)},positionDragX:function(a,b){bg(a,b)},positionDragY:function(a,b){be(a,b)},animate:function(a,b,c,d){var f={};f[b]=c,a.animate(f,{duration:e.animateDuration,easing:e.animateEase,queue:!1,step:d})},getContentPositionX:function(){return bn()},getContentPositionY:function(){return bo()},getContentWidth:function(){return k},getContentHeight:function(){return l},getPercentScrolledX:function(){return bn()/(k-h)},getPercentScrolledY:function(){return bo()/(l-i)},getIsScrollableH:function(){return p},getIsScrollableV:function(){return o},getContentPane:function(){return g},scrollToBottom:function(a){be(r,a)},hijackInternalLinks:function(){bA()},destroy:function(){bC()}}),T(d)}return b=a.extend({},a.fn.jScrollPane.defaults,b),a.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){b[this]=b[this]||b.speed}),this.each(function(){var c=a(this),e=c.data("jsp");e?e.reinitialise(b):(e=new d(c,b),c.data("jsp",e))})},a.fn.jScrollPane.defaults={showArrows:!1,maintainPosition:!0,stickToBottom:!1,stickToRight:!1,clickOnTrack:!0,autoReinitialise:!1,autoReinitialiseDelay:500,verticalDragMinHeight:0,verticalDragMaxHeight:99999,horizontalDragMinWidth:0,horizontalDragMaxWidth:99999,contentWidth:c,animateScroll:!1,animateDuration:300,animateEase:"linear",hijackInternalLinks:!1,verticalGutter:4,horizontalGutter:4,mouseWheelSpeed:0,arrowButtonSpeed:0,arrowRepeatFreq:50,arrowScrollOnHover:!1,trackClickSpeed:0,trackClickRepeatFreq:70,verticalArrowPositions:"split",horizontalArrowPositions:"split",enableKeyboardNavigation:!0,hideFocus:!1,keyboardSpeed:0,initialDelay:300,speed:30,scrollPagePercent:.8}})(jQuery,this)
