/*
 * jScrollPane - v2.0.0beta11 - 2011-07-04
 * http://jscrollpane.kelvinluck.com/
 *
 * Copyright (c) 2010 Kelvin Luck
 * Dual licensed under the MIT and GPL licenses.
 */
(function(b,Da,r){b.fn.jScrollPane=function(x){function ba(c,x){function ca(a){var d,j,ja,n,o,p=!1,k=!1;e=a;if(f===r)n=c.scrollTop(),o=c.scrollLeft(),c.css({overflow:"hidden",padding:0}),h=c.innerWidth()+I,i=c.innerHeight(),c.width(h),f=b('<div class="jspPane" />').css("padding",ka).append(c.children()),g=b('<div class="jspContainer" />').css({width:h+"px",height:i+"px"}).append(f).appendTo(c);else{c.css("width","");p=e.stickToBottom&&ta();k=e.stickToRight&&ua();if(ja=c.innerWidth()+I!=h||c.outerHeight()!=
i)h=c.innerWidth()+I,i=c.innerHeight(),g.css({width:h+"px",height:i+"px"});if(!ja&&la==s&&f.outerHeight()==q){c.width(h);return}la=s;f.css("width","");c.width(h);g.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}f.css("overflow","auto");s=a.contentWidth?a.contentWidth:f[0].scrollWidth;q=f[0].scrollHeight;f.css("overflow","");da=s/h;T=q/i;w=T>1;v=da>1;if(!v&&!w)c.removeClass("jspScrollable"),f.css({top:0,width:g.width()-I}),g.unbind(ea),f.find(":input,a").unbind("focus.jsp"),c.attr("tabindex",
"-1").removeAttr("tabindex").unbind("keydown.jsp keypress.jsp"),ma(),na();else{c.addClass("jspScrollable");if(a=e.maintainPosition&&(l||m))d=B(),j=C();ba();va();wa();a&&(L(k?s-h:d,!1),D(p?q-i:j,!1));xa();ya();e.enableKeyboardNavigation&&za();e.clickOnTrack&&Aa();Ba();e.hijackInternalLinks&&oa()}e.autoReinitialise&&!U?U=setInterval(function(){ca(e)},e.autoReinitialiseDelay):!e.autoReinitialise&&U&&clearInterval(U);n&&c.scrollTop(0)&&D(n,!1);o&&c.scrollLeft(0)&&L(o,!1);c.trigger("jsp-initialised",[v||
w])}function ba(){w&&(g.append(b('<div class="jspVerticalBar" />').append(b('<div class="jspCap jspCapTop" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragTop" />'),b('<div class="jspDragBottom" />'))),b('<div class="jspCap jspCapBottom" />'))),V=g.find(">.jspVerticalBar"),y=V.find(">.jspTrack"),t=y.find(">.jspDrag"),e.showArrows&&(P=b('<a class="jspArrow jspArrowUp" />').bind("mousedown.jsp",E(0,-1)).bind("click.jsp",M),Q=b('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp",
E(0,1)).bind("click.jsp",M),e.arrowScrollOnHover&&(P.bind("mouseover.jsp",E(0,-1,P)),Q.bind("mouseover.jsp",E(0,1,Q))),pa(y,e.verticalArrowPositions,P,Q)),N=i,g.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){N-=b(this).outerHeight()}),t.hover(function(){t.addClass("jspHover")},function(){t.removeClass("jspHover")}).bind("mousedown.jsp",function(a){b("html").bind("dragstart.jsp selectstart.jsp",M);t.addClass("jspActive");var d=a.pageY-t.position().top;b("html").bind("mousemove.jsp",
function(a){J(a.pageY-d,!1)}).bind("mouseup.jsp mouseleave.jsp",qa);return!1}),ra())}function ra(){y.height(N+"px");l=0;fa=e.verticalGutter+y.outerWidth();f.width(h-fa-I);try{V.position().left===0&&f.css("margin-left",fa+"px")}catch(a){}}function va(){v&&(g.append(b('<div class="jspHorizontalBar" />').append(b('<div class="jspCap jspCapLeft" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragLeft" />'),b('<div class="jspDragRight" />'))),b('<div class="jspCap jspCapRight" />'))),
W=g.find(">.jspHorizontalBar"),z=W.find(">.jspTrack"),u=z.find(">.jspDrag"),e.showArrows&&(R=b('<a class="jspArrow jspArrowLeft" />').bind("mousedown.jsp",E(-1,0)).bind("click.jsp",M),S=b('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp",E(1,0)).bind("click.jsp",M),e.arrowScrollOnHover&&(R.bind("mouseover.jsp",E(-1,0,R)),S.bind("mouseover.jsp",E(1,0,S))),pa(z,e.horizontalArrowPositions,R,S)),u.hover(function(){u.addClass("jspHover")},function(){u.removeClass("jspHover")}).bind("mousedown.jsp",
function(a){b("html").bind("dragstart.jsp selectstart.jsp",M);u.addClass("jspActive");var d=a.pageX-u.position().left;b("html").bind("mousemove.jsp",function(a){O(a.pageX-d,!1)}).bind("mouseup.jsp mouseleave.jsp",qa);return!1}),K=g.innerWidth(),sa())}function sa(){g.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){K-=b(this).outerWidth()});z.width(K+"px");m=0}function wa(){if(v&&w){var a=z.outerHeight(),d=y.outerWidth();N-=a;b(W).find(">.jspCap:visible,>.jspArrow").each(function(){K+=
b(this).outerWidth()});K-=d;i-=d;h-=a;z.parent().append(b('<div class="jspCorner" />').css("width",a+"px"));ra();sa()}v&&f.width(g.outerWidth()-I+"px");q=f.outerHeight();T=q/i;if(v){F=Math.ceil(1/da*K);if(F>e.horizontalDragMaxWidth)F=e.horizontalDragMaxWidth;else if(F<e.horizontalDragMinWidth)F=e.horizontalDragMinWidth;u.width(F+"px");G=K-F;ga(m)}if(w){H=Math.ceil(1/T*N);if(H>e.verticalDragMaxHeight)H=e.verticalDragMaxHeight;else if(H<e.verticalDragMinHeight)H=e.verticalDragMinHeight;t.height(H+"px");
A=N-H;ha(l)}}function pa(a,d,j,e){var b="before",c="after";d=="os"&&(d=/Mac/.test(navigator.platform)?"after":"split");d==b?c=d:d==c&&(b=d,d=j,j=e,e=d);a[b](j)[c](e)}function E(a,d,e){return function(){Ca(a,d,this,e);this.blur();return!1}}function Ca(a,d,j,c){var j=b(j).addClass("jspActive"),n,o,p=!0,g=function(){a!==0&&k.scrollByX(a*e.arrowButtonSpeed);d!==0&&k.scrollByY(d*e.arrowButtonSpeed);o=setTimeout(g,p?e.initialDelay:e.arrowRepeatFreq);p=!1};g();n=c?"mouseout.jsp":"mouseup.jsp";c=c||b("html");
c.bind(n,function(){j.removeClass("jspActive");o&&clearTimeout(o);o=null;c.unbind(n)})}function Aa(){ma();w&&y.bind("mousedown.jsp",function(a){if(a.originalTarget===r||a.originalTarget==a.currentTarget){var d=b(this),j=d.offset(),c=a.pageY-j.top-l,n,o=!0,p=function(){var b=d.offset(),b=a.pageY-b.top-H/2,j=i*e.scrollPagePercent,f=A*j/(q-i);if(c<0)l-f>b?k.scrollByY(-j):J(b);else if(c>0)l+f<b?k.scrollByY(j):J(b);else{g();return}n=setTimeout(p,o?e.initialDelay:e.trackClickRepeatFreq);o=!1},g=function(){n&&
clearTimeout(n);n=null;b(document).unbind("mouseup.jsp",g)};p();b(document).bind("mouseup.jsp",g);return!1}});v&&z.bind("mousedown.jsp",function(a){if(a.originalTarget===r||a.originalTarget==a.currentTarget){var d=b(this),j=d.offset(),c=a.pageX-j.left-m,n,g=!0,p=function(){var b=d.offset(),b=a.pageX-b.left-F/2,j=h*e.scrollPagePercent,i=G*j/(s-h);if(c<0)m-i>b?k.scrollByX(-j):O(b);else if(c>0)m+i<b?k.scrollByX(j):O(b);else{f();return}n=setTimeout(p,g?e.initialDelay:e.trackClickRepeatFreq);g=!1},f=function(){n&&
clearTimeout(n);n=null;b(document).unbind("mouseup.jsp",f)};p();b(document).bind("mouseup.jsp",f);return!1}})}function ma(){z&&z.unbind("mousedown.jsp");y&&y.unbind("mousedown.jsp")}function qa(){b("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp");t&&t.removeClass("jspActive");u&&u.removeClass("jspActive")}function J(a,d){if(w){a<0?a=0:a>A&&(a=A);if(d===r)d=e.animateScroll;d?k.animate(t,"top",a,ha):(t.css("top",a),ha(a))}}function ha(a){if(a===r)a=t.position().top;
g.scrollTop(0);l=a;var d=l===0,b=l==A,a=-(a/A)*(q-i);if(X!=d||Y!=b)X=d,Y=b,c.trigger("jsp-arrow-change",[X,Y,Z,$]);e.showArrows&&(P[d?"addClass":"removeClass"]("jspDisabled"),Q[b?"addClass":"removeClass"]("jspDisabled"));f.css("top",a);c.trigger("jsp-scroll-y",[-a,d,b]).trigger("scroll")}function O(a,d){if(v){a<0?a=0:a>G&&(a=G);if(d===r)d=e.animateScroll;d?k.animate(u,"left",a,ga):(u.css("left",a),ga(a))}}function ga(a){if(a===r)a=u.position().left;g.scrollTop(0);m=a;var d=m===0,b=m==G,a=-(a/G)*(s-
h);if(Z!=d||$!=b)Z=d,$=b,c.trigger("jsp-arrow-change",[X,Y,Z,$]);e.showArrows&&(R[d?"addClass":"removeClass"]("jspDisabled"),S[b?"addClass":"removeClass"]("jspDisabled"));f.css("left",a);c.trigger("jsp-scroll-x",[-a,d,b]).trigger("scroll")}function D(a,d){J(a/(q-i)*A,d)}function L(a,d){O(a/(s-h)*G,d)}function aa(a,d,c){var f,n,o=0,p=0,k,l,m;try{f=b(a)}catch(q){return}n=f.outerHeight();a=f.outerWidth();g.scrollTop(0);for(g.scrollLeft(0);!f.is(".jspPane");)if(o+=f.position().top,p+=f.position().left,
f=f.offsetParent(),/^body|html$/i.test(f[0].nodeName))return;f=C();k=f+i;o<f||d?l=o-e.verticalGutter:o+n>k&&(l=o-i+n+e.verticalGutter);l&&D(l,c);o=B();l=o+h;p<o||d?m=p-e.horizontalGutter:p+a>l&&(m=p-h+a+e.horizontalGutter);m&&L(m,c)}function B(){return-f.position().left}function C(){return-f.position().top}function ta(){var a=q-i;return a>20&&a-C()<10}function ua(){var a=s-h;return a>20&&a-B()<10}function xa(){g.unbind(ea).bind(ea,function(a,d,b,c){a=m;d=l;k.scrollBy(b*e.mouseWheelSpeed,-c*e.mouseWheelSpeed,
!1);return a==m&&d==l})}function M(){return!1}function za(){function a(){var a=m,b=l;switch(d){case 40:k.scrollByY(e.keyboardSpeed,!1);break;case 38:k.scrollByY(-e.keyboardSpeed,!1);break;case 34:case 32:k.scrollByY(i*e.scrollPagePercent,!1);break;case 33:k.scrollByY(-i*e.scrollPagePercent,!1);break;case 39:k.scrollByX(e.keyboardSpeed,!1);break;case 37:k.scrollByX(-e.keyboardSpeed,!1)}return j=a!=m||b!=l}var d,j,h=[];v&&h.push(W[0]);w&&h.push(V[0]);f.focus(function(){c.focus()});c.attr("tabindex",
0).unbind("keydown.jsp keypress.jsp").bind("keydown.jsp",function(c){if(!(c.target!==this&&(!h.length||!b(c.target).closest(h).length))){var e=m,f=l;switch(c.keyCode){case 40:case 38:case 34:case 32:case 33:case 39:case 37:d=c.keyCode;a();break;case 35:D(q-i);d=null;break;case 36:D(0),d=null}j=c.keyCode==d&&e!=m||f!=l;return!j}}).bind("keypress.jsp",function(b){b.keyCode==d&&a();return!j});e.hideFocus?(c.css("outline","none"),"hideFocus"in g[0]&&c.attr("hideFocus",!0)):(c.css("outline",""),"hideFocus"in
g[0]&&c.attr("hideFocus",!1))}function Ba(){if(location.hash&&location.hash.length>1){var a,d,c=escape(location.hash);try{a=b(c)}catch(e){return}a.length&&f.find(c)&&(g.scrollTop()===0?d=setInterval(function(){g.scrollTop()>0&&(aa(c,!0),b(document).scrollTop(g.position().top),clearInterval(d))},50):(aa(c,!0),b(document).scrollTop(g.position().top)))}}function na(){b("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function oa(){na();b("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",
function(){var a=this.href.split("#");if(a.length>1&&(a=a[1],a.length>0&&f.find("#"+a).length>0))return aa("#"+a,!0),!1})}function ya(){var a,d,b,c,e,f=!1;g.unbind("touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick").bind("touchstart.jsp",function(g){g=g.originalEvent.touches[0];a=B();d=C();b=g.pageX;c=g.pageY;e=!1;f=!0}).bind("touchmove.jsp",function(g){if(f){var g=g.originalEvent.touches[0],h=m,i=l;k.scrollTo(a+b-g.pageX,d+c-g.pageY);e=e||Math.abs(b-g.pageX)>5||Math.abs(c-g.pageY)>
5;return h==m&&i==l}}).bind("touchend.jsp",function(){f=!1}).bind("click.jsp-touchclick",function(){if(e)return e=!1})}var e,k=this,f,h,i,g,s,q,da,T,w,v,t,A,l,u,G,m,V,y,fa,N,H,P,Q,W,z,K,F,R,S,U,ka,I,la,X=!0,Z=!0,Y=!1,$=!1,ia=c.clone(!1,!1).empty(),ea=b.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";ka=c.css("paddingTop")+" "+c.css("paddingRight")+" "+c.css("paddingBottom")+" "+c.css("paddingLeft");I=(parseInt(c.css("paddingLeft"),10)||0)+(parseInt(c.css("paddingRight"),10)||0);b.extend(k,{reinitialise:function(a){a=
b.extend({},e,a);ca(a)},scrollToElement:function(a,d,b){aa(a,d,b)},scrollTo:function(a,d,b){L(a,b);D(d,b)},scrollToX:function(a,b){L(a,b)},scrollToY:function(a,b){D(a,b)},scrollToPercentX:function(a,b){L(a*(s-h),b)},scrollToPercentY:function(a,b){D(a*(q-i),b)},scrollBy:function(a,b,c){k.scrollByX(a,c);k.scrollByY(b,c)},scrollByX:function(a,b){var c=(B()+Math[a<0?"floor":"ceil"](a))/(s-h);O(c*G,b)},scrollByY:function(a,b){var c=(C()+Math[a<0?"floor":"ceil"](a))/(q-i);J(c*A,b)},positionDragX:function(a,
b){O(a,b)},positionDragY:function(a,b){J(a,b)},animate:function(a,b,c,f){var g={};g[b]=c;a.animate(g,{duration:e.animateDuration,easing:e.animateEase,queue:!1,step:f})},getContentPositionX:function(){return B()},getContentPositionY:function(){return C()},getContentWidth:function(){return s},getContentHeight:function(){return q},getPercentScrolledX:function(){return B()/(s-h)},getPercentScrolledY:function(){return C()/(q-i)},getIsScrollableH:function(){return v},getIsScrollableV:function(){return w},
getContentPane:function(){return f},scrollToBottom:function(a){J(A,a)},hijackInternalLinks:function(){oa()},destroy:function(){var a=C(),b=B();c.removeClass("jspScrollable").unbind(".jsp");c.replaceWith(ia.append(f.children()));ia.scrollTop(a);ia.scrollLeft(b)}});ca(x)}x=b.extend({},b.fn.jScrollPane.defaults,x);b.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){x[this]=x[this]||x.speed});return this.each(function(){var c=b(this),r=c.data("jsp");r?r.reinitialise(x):
(r=new ba(c,x),c.data("jsp",r))})};b.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:r,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:0.8}})(jQuery,this);
