(function(a,b,c){a.fn.jScrollPane=function(b){function d(b,d){function bC(){var a=bo(),c=bn();b.removeClass("jspScrollable").unbind(".jsp");b.replaceWith(R.append(g.children()));R.scrollTop(a);R.scrollLeft(c)}function bB(){var a,b,c,d,e,g=false;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=false;g=true}).bind("touchmove.jsp",function(h){if(!g){return}var i=h.originalEvent.touches[0],j=v,k=s;f.scrollTo(a+c-i.pageX,b+d-i.pageY);e=e||Math.abs(c-i.pageX)>5||Math.abs(d-i.pageY)>5;return j==v&&k==s}).bind("touchend.jsp",function(a){g=false}).bind("click.jsp-touchclick",function(a){if(e){e=false;return false}})}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){bm("#"+b,true);return false}}})}function bz(){a("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function by(){if(location.hash&&location.hash.length>1){var b,c,d=escape(location.hash);try{b=a(d)}catch(e){return}if(b.length&&g.find(d)){if(j.scrollTop()===0){c=setInterval(function(){if(j.scrollTop()>0){bm(d,true);a(document).scrollTop(j.position().top);clearInterval(c)}},50)}else{bm(d,true);a(document).scrollTop(j.position().top)}}}}function bx(){b.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp keypress.jsp")}function bw(){function k(){var a=v,b=s;switch(c){case 40:f.scrollByY(e.keyboardSpeed,false);break;case 38:f.scrollByY(-e.keyboardSpeed,false);break;case 34:case 32:f.scrollByY(i*e.scrollPagePercent,false);break;case 33:f.scrollByY(-i*e.scrollPagePercent,false);break;case 39:f.scrollByX(e.keyboardSpeed,false);break;case 37:f.scrollByX(-e.keyboardSpeed,false);break}d=a!=v||b!=s;return 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;break}d=b.keyCode==c&&e!=v||f!=s;return!d}).bind("keypress.jsp",function(a){if(a.keyCode==c){k()}return!d});if(e.hideFocus){b.css("outline","none");if("hideFocus"in j[0]){b.attr("hideFocus",true)}}else{b.css("outline","");if("hideFocus"in j[0]){b.attr("hideFocus",false)}}}function bv(){g.find(":input,a").unbind("focus.jsp")}function bu(){g.find(":input,a").unbind("focus.jsp").bind("focus.jsp",function(a){bm(a.target,false)})}function bt(){return false}function bs(){j.unbind(S)}function br(){j.unbind(S).bind(S,function(a,b,c,d){var g=v,h=s;f.scrollBy(c*e.mouseWheelSpeed,-d*e.mouseWheelSpeed,false);return g==v&&h==s})}function bq(){var a=k-h;return a>20&&a-bn()<10}function bp(){var a=l-i;return a>20&&a-bo()<10}function bo(){return-g.position().top}function bn(){return-g.position().left}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;if(l<n||c){r=l-e.verticalGutter}else if(l+g>p){r=l-i+g+e.verticalGutter}if(r){bk(r,d)}o=bn();q=o+h;if(m<o||c){s=m-e.horizontalGutter}else if(m+k>q){s=m-h+k+e.horizontalGutter}if(s){bl(s,d)}}function bl(a,b){var c=a/(k-h);bg(c*u,b)}function bk(a,b){var c=a/(l-i);be(c*r,b)}function bj(a,b){if(e.showArrows){H[a?"addClass":"removeClass"]("jspDisabled");I[b?"addClass":"removeClass"]("jspDisabled")}}function bi(a,b){if(e.showArrows){B[a?"addClass":"removeClass"]("jspDisabled");C[b?"addClass":"removeClass"]("jspDisabled")}}function bh(a){if(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 bg(a,b){if(!p){return}if(a<0){a=0}else if(a>u){a=u}if(b===c){b=e.animateScroll}if(b){f.animate(t,"left",a,bh)}else{t.css("left",a);bh(a)}}function bf(a){if(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 be(a,b){if(!o){return}if(a<0){a=0}else if(a>r){a=r}if(b===c){b=e.animateScroll}if(b){f.animate(q,"top",a,bf)}else{q.css("top",a);bf(a)}}function bd(){a("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp");if(q){q.removeClass("jspActive")}if(t){t.removeClass("jspActive")}}function bc(){if(E){E.unbind("mousedown.jsp")}if(x){x.unbind("mousedown.jsp")}}function bb(){bc();if(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=true,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){if(s-o>c){f.scrollByY(-g)}else{be(c)}}else if(h>0){if(s+o<c){f.scrollByY(g)}else{be(c)}}else{n();return}j=setTimeout(m,k?e.initialDelay:e.trackClickRepeatFreq);k=false},n=function(){j&&clearTimeout(j);j=null;a(document).unbind("mouseup.jsp",n)};m();a(document).bind("mouseup.jsp",n);return false}})}if(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=true,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){if(v-o>c){f.scrollByX(-g)}else{bg(c)}}else if(i>0){if(v+o<c){f.scrollByX(g)}else{bg(c)}}else{n();return}j=setTimeout(m,l?e.initialDelay:e.trackClickRepeatFreq);l=false},n=function(){j&&clearTimeout(j);j=null;a(document).unbind("mouseup.jsp",n)};m();a(document).bind("mouseup.jsp",n);return false}})}}function ba(b,c,d,g){d=a(d).addClass("jspActive");var h,i,j=true,k=function(){if(b!==0){f.scrollByX(b*e.arrowButtonSpeed)}if(c!==0){f.scrollByY(c*e.arrowButtonSpeed)}i=setTimeout(k,j?e.initialDelay:e.arrowRepeatFreq);j=false};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 _(a,b,c){return function(){ba(a,b,this,c);this.blur();return false}}function Z(a,b,c,d){var e="before",f="after",g;if(b=="os"){b=/Mac/.test(navigator.platform)?"after":"split"}if(b==e){f=b}else if(b==f){e=b;g=c;c=d;d=g}a[e](c)[f](d)}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()}if(p){g.width(j.outerWidth()-L+"px")}l=g.outerHeight();n=l/i;if(p){G=Math.ceil(1/m*F);if(G>e.horizontalDragMaxWidth){G=e.horizontalDragMaxWidth}else if(G<e.horizontalDragMinWidth){G=e.horizontalDragMinWidth}t.width(G+"px");u=F-G;bh(v)}if(o){A=Math.ceil(1/n*z);if(A>e.verticalDragMaxHeight){A=e.verticalDragMaxHeight}else if(A<e.verticalDragMinHeight){A=e.verticalDragMinHeight}q.height(A+"px");r=z-A;bf(s)}}function X(){j.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){F-=a(this).outerWidth()});E.width(F+"px");v=0}function W(){if(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");if(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);if(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;a("html").bind("mousemove.jsp",function(a){bg(a.pageX-c,false)}).bind("mouseup.jsp mouseleave.jsp",bd);return false});F=j.innerWidth()-160;if(F<880)F=880;X()}}function V(){x.height(z+"px");s=0;y=e.verticalGutter+x.outerWidth();g.width(h-y-L);try{if(w.position().left===0){g.css("margin-left",y+"px")}}catch(a){}}function U(){if(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");if(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);if(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;a("html").bind("mousemove.jsp",function(a){be(a.pageY-c,false)}).bind("mouseup.jsp mouseleave.jsp",bd);return false});V()}}function T(d){var f,q,r,t,u,w,x=false,y=false;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;if(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");if(d.contentWidth){k=d.contentWidth}else{k=g[0].scrollWidth}l=g[0].scrollHeight;g.css("overflow","");m=k/h;n=l/i;o=n>1;p=m>1;if(!(p||o)){b.removeClass("jspScrollable");g.css({top:0,width:j.width()-L});bs();bv();bx();bc();bz()}else{b.addClass("jspScrollable");f=e.maintainPosition&&(s||v);if(f){q=bn();r=bo()}U();W();Y();if(f){bl(y?k-h:q,false);bk(x?l-i:r,false)}bu();br();bB();if(e.enableKeyboardNavigation){bw()}if(e.clickOnTrack){bb()}by();if(e.hijackInternalLinks){bA()}}if(e.autoReinitialise&&!J){J=setInterval(function(){T(e)},e.autoReinitialiseDelay)}else if(!e.autoReinitialise&&J){clearInterval(J)}u&&b.scrollTop(0)&&bk(u,false);w&&b.scrollLeft(0)&&bl(w,false);b.trigger("jsp-initialised",[p||o])}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=true,O=true,P=false,Q=false,R=b.clone(false,false).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:false,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)}b=a.extend({},a.fn.jScrollPane.defaults,b);a.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){b[this]=b[this]||b.speed});return this.each(function(){var c=a(this),e=c.data("jsp");if(e){e.reinitialise(b)}else{e=new d(c,b);c.data("jsp",e)}})};a.fn.jScrollPane.defaults={showArrows:false,maintainPosition:true,stickToBottom:false,stickToRight:false,clickOnTrack:true,autoReinitialise:false,autoReinitialiseDelay:500,verticalDragMinHeight:0,verticalDragMaxHeight:99999,horizontalDragMinWidth:0,horizontalDragMaxWidth:99999,contentWidth:c,animateScroll:false,animateDuration:300,animateEase:"linear",hijackInternalLinks:false,verticalGutter:4,horizontalGutter:4,mouseWheelSpeed:0,arrowButtonSpeed:0,arrowRepeatFreq:50,arrowScrollOnHover:false,trackClickSpeed:0,trackClickRepeatFreq:70,verticalArrowPositions:"split",horizontalArrowPositions:"split",enableKeyboardNavigation:true,hideFocus:false,keyboardSpeed:0,initialDelay:300,speed:30,scrollPagePercent:.8}})(jQuery,this)
