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

