(function(a,b,c){a.fn.jScrollPane=function(b){function d(b,d){function bB(){var a=bn(),c=bm();b.removeClass("jspScrollable").unbind(".jsp");b.replaceWith(R.append(g.children()));R.scrollTop(a);R.scrollLeft(c)}function bA(){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=bm();b=bn();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 bz(){by();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){bl("#"+b,true);return false}}})}function by(){a("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function bx(){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){bl(d,true);a(document).scrollTop(j.position().top);clearInterval(c)}},50)}else{bl(d,true);a(document).scrollTop(j.position().top)}}}}function bw(){b.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp keypress.jsp")}function bv(){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:bj(l-i);c=null;break;case 36:bj(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 bu(){g.find(":input,a").unbind("focus.jsp")}function bt(){g.find(":input,a").unbind("focus.jsp").bind("focus.jsp",function(a){bl(a.target,false)})}function bs(){return false}function br(){j.unbind(S)}function bq(){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 bp(){var a=k-h;return a>20&&a-bm()<10}function bo(){var a=l-i;return a>20&&a-bn()<10}function bn(){return-g.position().top}function bm(){return-g.position().left}function bl(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=bn();p=n+i;if(l<n||c){r=l-e.verticalGutter}else{if(l+g>p){r=l-i+g+e.verticalGutter}}if(r){bj(r,d)}o=bm();q=o+h;if(m<o||c){s=m-e.horizontalGutter}else{if(m+k>q){s=m-h+k+e.horizontalGutter}}if(s){bk(s,d)}}function bk(a,b){var c=a/(k-h);bf(c*u,b)}function bj(a,b){var c=a/(l-i);bd(c*r,b)}function bi(a,b){if(e.showArrows){H[a?"addClass":"removeClass"]("jspDisabled");I[b?"addClass":"removeClass"]("jspDisabled")}}function bh(a,b){if(e.showArrows){B[a?"addClass":"removeClass"]("jspDisabled");C[b?"addClass":"removeClass"]("jspDisabled")}}function bg(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])}bi(d,e);g.css("left",i);b.trigger("jsp-scroll-x",[-i,d,e]).trigger("scroll")}function bf(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,bg)}else{t.css("left",a);bg(a)}}function be(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])}bh(d,e);g.css("top",h);b.trigger("jsp-scroll-y",[-h,d,e]).trigger("scroll")}function bd(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,be)}else{q.css("top",a);be(a)}}function bc(){a("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp");if(q){q.removeClass("jspActive")}if(t){t.removeClass("jspActive")}}function bb(){if(E){E.unbind("mousedown.jsp")}if(x){x.unbind("mousedown.jsp")}}function ba(){bb();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{bd(c)}}else{if(h>0){if(s+o<c){f.scrollByY(g)}else{bd(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{bf(c)}}else{if(i>0){if(v+o<c){f.scrollByX(g)}else{bf(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 _(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(){_(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;bg(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;be(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",bs);I=a('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp",$(1,0)).bind("click.jsp",bs);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",bs);t.addClass("jspActive");var c=b.pageX-t.position().left;a("html").bind("mousemove.jsp",function(a){bf(a.pageX-c,false)}).bind("mouseup.jsp mouseleave.jsp",bc);return false});F=j.innerWidth();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",bs);C=a('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp",$(0,1)).bind("click.jsp",bs);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",bs);q.addClass("jspActive");var c=b.pageY-q.position().top;a("html").bind("mousemove.jsp",function(a){bd(a.pageY-c,false)}).bind("mouseup.jsp mouseleave.jsp",bc);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&&bo();y=e.stickToRight&&bp();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});br();bu();bw();bb();by()}else{b.addClass("jspScrollable");f=e.maintainPosition&&(s||v);if(f){q=bm();r=bn()}U();W();Y();if(f){bk(y?k-h:q,false);bj(x?l-i:r,false)}bt();bq();bA();if(e.enableKeyboardNavigation){bv()}if(e.clickOnTrack){ba()}bx();if(e.hijackInternalLinks){bz()}}if(e.autoReinitialise&&!J){J=setInterval(function(){T(e)},e.autoReinitialiseDelay)}else{if(!e.autoReinitialise&&J){clearInterval(J)}}u&&b.scrollTop(0)&&bj(u,false);w&&b.scrollLeft(0)&&bk(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){bl(a,b,c)},scrollTo:function(a,b,c){bk(a,c);bj(b,c)},scrollToX:function(a,b){bk(a,b)},scrollToY:function(a,b){bj(a,b)},scrollToPercentX:function(a,b){bk(a*(k-h),b)},scrollToPercentY:function(a,b){bj(a*(l-i),b)},scrollBy:function(a,b,c){f.scrollByX(a,c);f.scrollByY(b,c)},scrollByX:function(a,b){var c=bm()+Math[a<0?"floor":"ceil"](a),d=c/(k-h);bf(d*u,b)},scrollByY:function(a,b){var c=bn()+Math[a<0?"floor":"ceil"](a),d=c/(l-i);bd(d*r,b)},positionDragX:function(a,b){bf(a,b)},positionDragY:function(a,b){bd(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 bm()},getContentPositionY:function(){return bn()},getContentWidth:function(){return k},getContentHeight:function(){return l},getPercentScrolledX:function(){return bm()/(k-h)},getPercentScrolledY:function(){return bn()/(l-i)},getIsScrollableH:function(){return p},getIsScrollableV:function(){return o},getContentPane:function(){return g},scrollToBottom:function(a){bd(r,a)},hijackInternalLinks:function(){bz()},destroy:function(){bB()}});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),f=c.data("jsp");if(f){f.reinitialise(b)}else{f=new d(c,b);c.data("jsp",f)}})};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)
