/*
 * jScrollPane - v2.0.0beta9 - 2011-01-31
 * http://jscrollpane.kelvinluck.com/
 *
 * Copyright (c) 2010 Kelvin Luck
 * Dual licensed under the MIT and GPL licenses.
 */
(function(b,a,c){b.fn.jScrollPane=function(f){function d(D,N){var ay,P=this,X,aj,w,al,S,Y,z,r,az,aE,au,j,I,i,k,Z,T,ap,W,u,B,aq,ae,am,G,m,at,ax,y,av,aI,g,K,ai=true,O=true,aH=false,l=false,ao=D.clone().empty(),ab=b.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";aI=D.css("paddingTop")+" "+D.css("paddingRight")+" "+D.css("paddingBottom")+" "+D.css("paddingLeft");g=(parseInt(D.css("paddingLeft"),10)||0)+(parseInt(D.css("paddingRight"),10)||0);function ar(aR){var aP,aQ,aL,aN,aM,aK,aJ,aO;ay=aR;if(X===c){aJ=D.scrollTop();aO=D.scrollLeft();D.css({overflow:"hidden",padding:0});aj=D.innerWidth()+g;w=D.innerHeight();D.width(aj);X=b('<div class="jspPane" />').css("padding",aI).append(D.children());al=b('<div class="jspContainer" />').css({width:aj+"px",height:w+"px"}).append(X).appendTo(D)}else{D.css("width","");aK=D.innerWidth()+g!=aj||D.outerHeight()!=w;if(aK){aj=D.innerWidth()+g;w=D.innerHeight();al.css({width:aj+"px",height:w+"px"})}if(!aK&&K==S&&X.outerHeight()==Y){D.width(aj);return}K=S;X.css("width","");D.width(aj);al.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}aP=X.clone().css("position","absolute");aQ=b('<div style="width:1px; position: relative;" />').append(aP);b("body").append(aQ);S=Math.max(X.outerWidth(),aP.outerWidth());aQ.remove();Y=X.outerHeight();z=S/aj;r=Y/w;az=r>1;aE=z>1;if(!(aE||az)){D.removeClass("jspScrollable");X.css({top:0,width:al.width()-g});o();E();Q();x();ah()}else{D.addClass("jspScrollable");aL=ay.maintainPosition&&(I||Z);if(aL){aN=aC();aM=aA()}aF();A();F();if(aL){M(aN,false);L(aM,false)}J();af();an();if(ay.enableKeyboardNavigation){R()}if(ay.clickOnTrack){q()}C();if(ay.hijackInternalLinks){n()}}if(ay.autoReinitialise&&!av){av=setInterval(function(){ar(ay)},ay.autoReinitialiseDelay)}else{if(!ay.autoReinitialise&&av){clearInterval(av)}}aJ&&D.scrollTop(0)&&L(aJ,false);aO&&D.scrollLeft(0)&&M(aO,false);D.trigger("jsp-initialised",[aE||az])}function aF(){if(az){al.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" />')));T=al.find(">.jspVerticalBar");ap=T.find(">.jspTrack");au=ap.find(">.jspDrag");if(ay.showArrows){aq=b('<a class="jspArrow jspArrowUp" />').bind("mousedown.html",aD(0,-1)).bind("click.html",aB);ae=b('<a class="jspArrow jspArrowDown" />').bind("mousedown.html",aD(0,1)).bind("click.html",aB);if(ay.arrowScrollOnHover){aq.bind("mouseover.html",aD(0,-1,aq));ae.bind("mouseover.html",aD(0,1,ae))}ak(ap,ay.verticalArrowPositions,aq,ae)}u=w;al.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){u-=b(this).outerHeight()});au.hover(function(){au.addClass("jspHover")},function(){au.removeClass("jspHover")}).bind("mousedown.html",function(aJ){b("html").bind("dragstart.jsp%20selectstart.html",aB);au.addClass("jspActive");var s=aJ.pageY-au.position().top;b("html").bind("mousemove.html",function(aK){U(aK.pageY-s,false)}).bind("mouseup.jsp%20mouseleave.html",aw);return false});p()}}function p(){ap.height(u+"px");I=0;W=ay.verticalGutter+ap.outerWidth();X.width(aj-W-g);if(T.position().left===0){X.css("margin-left",W+"px")}}function A(){if(aE){al.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" />')));am=al.find(">.jspHorizontalBar");G=am.find(">.jspTrack");i=G.find(">.jspDrag");if(ay.showArrows){ax=b('<a class="jspArrow jspArrowLeft" />').bind("mousedown.html",aD(-1,0)).bind("click.html",aB);y=b('<a class="jspArrow jspArrowRight" />').bind("mousedown.html",aD(1,0)).bind("click.html",aB);if(ay.arrowScrollOnHover){ax.bind("mouseover.html",aD(-1,0,ax));
y.bind("mouseover.html",aD(1,0,y))}ak(G,ay.horizontalArrowPositions,ax,y)}i.hover(function(){i.addClass("jspHover")},function(){i.removeClass("jspHover")}).bind("mousedown.html",function(aJ){b("html").bind("dragstart.jsp%20selectstart.html",aB);i.addClass("jspActive");var s=aJ.pageX-i.position().left;b("html").bind("mousemove.html",function(aK){V(aK.pageX-s,false)}).bind("mouseup.jsp%20mouseleave.html",aw);return false});m=al.innerWidth();ag()}}function ag(){al.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){m-=b(this).outerWidth()});G.width(m+"px");Z=0}function F(){if(aE&&az){var aJ=G.outerHeight(),s=ap.outerWidth();u-=aJ;b(am).find(">.jspCap:visible,>.jspArrow").each(function(){m+=b(this).outerWidth()});m-=s;w-=s;aj-=aJ;G.parent().append(b('<div class="jspCorner" />').css("width",aJ+"px"));p();ag()}if(aE){X.width((al.outerWidth()-g)+"px")}Y=X.outerHeight();r=Y/w;if(aE){at=Math.ceil(1/z*m);if(at>ay.horizontalDragMaxWidth){at=ay.horizontalDragMaxWidth}else{if(at<ay.horizontalDragMinWidth){at=ay.horizontalDragMinWidth}}i.width(at+"px");k=m-at;ad(Z)}if(az){B=Math.ceil(1/r*u);if(B>ay.verticalDragMaxHeight){B=ay.verticalDragMaxHeight}else{if(B<ay.verticalDragMinHeight){B=ay.verticalDragMinHeight}}au.height(B+"px");j=u-B;ac(I)}}function ak(aK,aM,aJ,s){var aO="before",aL="after",aN;if(aM=="os"){aM=/Mac/.test(navigator.platform)?"after":"split"}if(aM==aO){aL=aM}else{if(aM==aL){aO=aM;aN=aJ;aJ=s;s=aN}}aK[aO](aJ)[aL](s)}function aD(aJ,s,aK){return function(){H(aJ,s,this,aK);this.blur();return false}}function H(aM,aL,aP,aO){aP=b(aP).addClass("jspActive");var aN,aK,aJ=true,s=function(){if(aM!==0){P.scrollByX(aM*ay.arrowButtonSpeed)}if(aL!==0){P.scrollByY(aL*ay.arrowButtonSpeed)}aK=setTimeout(s,aJ?ay.initialDelay:ay.arrowRepeatFreq);aJ=false};s();aN=aO?"mouseout.jsp":"mouseup.jsp";aO=aO||b("html");aO.bind(aN,function(){aP.removeClass("jspActive");aK&&clearTimeout(aK);aK=null;aO.unbind(aN);aG()})}function q(){x();if(az){ap.bind("mousedown.html",function(aO){if(aO.originalTarget===c||aO.originalTarget==aO.currentTarget){var aM=b(this),aP=aM.offset(),aN=aO.pageY-aP.top-I,aK,aJ=true,s=function(){var aS=aM.offset(),aT=aO.pageY-aS.top-B/2,aQ=w*ay.scrollPagePercent,aR=j*aQ/(Y-w);if(aN<0){if(I-aR>aT){P.scrollByY(-aQ)}else{U(aT)}}else{if(aN>0){if(I+aR<aT){P.scrollByY(aQ)}else{U(aT)}}else{aL();return}}aK=setTimeout(s,aJ?ay.initialDelay:ay.trackClickRepeatFreq);aJ=false},aL=function(){aK&&clearTimeout(aK);aK=null;b(document).unbind("mouseup.html",aL);aG()};s();b(document).bind("mouseup.html",aL);return false}})}if(aE){G.bind("mousedown.html",function(aO){if(aO.originalTarget===c||aO.originalTarget==aO.currentTarget){var aM=b(this),aP=aM.offset(),aN=aO.pageX-aP.left-Z,aK,aJ=true,s=function(){var aS=aM.offset(),aT=aO.pageX-aS.left-at/2,aQ=aj*ay.scrollPagePercent,aR=k*aQ/(S-aj);if(aN<0){if(Z-aR>aT){P.scrollByX(-aQ)}else{V(aT)}}else{if(aN>0){if(Z+aR<aT){P.scrollByX(aQ)}else{V(aT)}}else{aL();return}}aK=setTimeout(s,aJ?ay.initialDelay:ay.trackClickRepeatFreq);aJ=false},aL=function(){aK&&clearTimeout(aK);aK=null;b(document).unbind("mouseup.html",aL);aG()};s();b(document).bind("mouseup.html",aL);return false}})}}function x(){if(G){G.unbind("mousedown.html")}if(ap){ap.unbind("mousedown.html")}}function aw(){b("html").unbind("dragstart.jsp%20selectstart.jsp%20mousemove.jsp%20mouseup.jsp%20mouseleave.html");if(au){au.removeClass("jspActive")}if(i){i.removeClass("jspActive")}aG()}function U(s,aJ){if(!az){return}if(s<0){s=0}else{if(s>j){s=j}}if(aJ===c){aJ=ay.animateScroll}if(aJ){P.animate(au,"top",s,ac)}else{au.css("top",s);ac(s)}}function ac(aJ){if(aJ===c){aJ=au.position().top}al.scrollTop(0);I=aJ;var aM=I===0,aK=I==j,aL=aJ/j,s=-aL*(Y-w);if(ai!=aM||aH!=aK){ai=aM;aH=aK;D.trigger("jsp-arrow-change",[ai,aH,O,l])}v(aM,aK);X.css("top",s);D.trigger("jsp-scroll-y",[-s,aM,aK]).trigger("scroll")}function V(aJ,s){if(!aE){return}if(aJ<0){aJ=0}else{if(aJ>k){aJ=k}}if(s===c){s=ay.animateScroll}if(s){P.animate(i,"left",aJ,ad)}else{i.css("left",aJ);ad(aJ)}}function ad(aJ){if(aJ===c){aJ=i.position().left
}al.scrollTop(0);Z=aJ;var aM=Z===0,aL=Z==k,aK=aJ/k,s=-aK*(S-aj);if(O!=aM||l!=aL){O=aM;l=aL;D.trigger("jsp-arrow-change",[ai,aH,O,l])}t(aM,aL);X.css("left",s);D.trigger("jsp-scroll-x",[-s,aM,aL]).trigger("scroll")}function v(aJ,s){if(ay.showArrows){aq[aJ?"addClass":"removeClass"]("jspDisabled");ae[s?"addClass":"removeClass"]("jspDisabled")}}function t(aJ,s){if(ay.showArrows){ax[aJ?"addClass":"removeClass"]("jspDisabled");y[s?"addClass":"removeClass"]("jspDisabled")}}function L(s,aJ){var aK=s/(Y-w);U(aK*j,aJ)}function M(aJ,s){var aK=aJ/(S-aj);V(aK*k,s)}function aa(aV,aQ,aK){var aO,aL,aM,s=0,aU=0,aJ,aP,aS,aR,aT;try{aO=b(aV)}catch(aN){return}aL=aO.outerHeight();aM=aO.outerWidth();al.scrollTop(0);al.scrollLeft(0);while(!aO.is(".jspPane")){s+=aO.position().top;aU+=aO.position().left;aO=aO.offsetParent();if(/^body|html$/i.test(aO[0].nodeName)){return}}aJ=aA();aP=aJ+w;if(s<aJ||aQ){aR=s-ay.verticalGutter}else{if(s+aL>aP){aR=s-w+aL+ay.verticalGutter}}if(aR){L(aR,aK)}viewportLeft=aC();aS=viewportLeft+aj;if(aU<viewportLeft||aQ){aT=aU-ay.horizontalGutter}else{if(aU+aM>aS){aT=aU-aj+aM+ay.horizontalGutter}}if(aT){M(aT,aK)}}function aC(){return -X.position().left}function aA(){return -X.position().top}function af(){al.unbind(ab).bind(ab,function(aM,aN,aL,aJ){var aK=Z,s=I;P.scrollBy(aL*ay.mouseWheelSpeed,-aJ*ay.mouseWheelSpeed,false);return aK==Z&&s==I})}function o(){al.unbind(ab)}function aB(){return false}function J(){X.find(":input,a").unbind("focus.html").bind("focus.html",function(s){aa(s.target,false)})}function E(){X.find(":input,a").unbind("focus.html")}function R(){var s,aJ;X.focus(function(){D.focus()});D.attr("tabindex",0).unbind("keydown.jsp%20keypress.html").bind("keydown.html",function(aN){if(aN.target!==this){return}var aM=Z,aL=I;switch(aN.keyCode){case 40:case 38:case 34:case 32:case 33:case 39:case 37:s=aN.keyCode;aK();break;case 35:L(Y-w);s=null;break;case 36:L(0);s=null;break}aJ=aN.keyCode==s&&aM!=Z||aL!=I;return !aJ}).bind("keypress.html",function(aL){if(aL.keyCode==s){aK()}return !aJ});if(ay.hideFocus){D.css("outline","none");if("hideFocus" in al[0]){D.attr("hideFocus",true)}}else{D.css("outline","");if("hideFocus" in al[0]){D.attr("hideFocus",false)}}function aK(){var aM=Z,aL=I;switch(s){case 40:P.scrollByY(ay.keyboardSpeed,false);break;case 38:P.scrollByY(-ay.keyboardSpeed,false);break;case 34:case 32:P.scrollByY(w*ay.scrollPagePercent,false);break;case 33:P.scrollByY(-w*ay.scrollPagePercent,false);break;case 39:P.scrollByX(ay.keyboardSpeed,false);break;case 37:P.scrollByX(-ay.keyboardSpeed,false);break}aJ=aM!=Z||aL!=I;return aJ}}function Q(){D.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp%20keypress.html")}function C(){if(location.hash&&location.hash.length>1){var aK,aJ;try{aK=b(location.hash)}catch(s){return}if(aK.length&&X.find(location.hash)){if(al.scrollTop()===0){aJ=setInterval(function(){if(al.scrollTop()>0){aa(location.hash,true);b(document).scrollTop(al.position().top);clearInterval(aJ)}},50)}else{aa(location.hash,true);b(document).scrollTop(al.position().top)}}}}function ah(){b("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function n(){ah();b("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",function(){var s=this.href.split("#"),aJ;if(s.length>1){aJ=s[1];if(aJ.length>0&&X.find("#"+aJ).length>0){aa("#"+aJ,true);return false}}})}function aG(){if(!b(":focus").length){D.focus()}}function an(){var aK,aJ,aM,aL,aN,s=false;al.unbind("touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick").bind("touchstart.html",function(aO){var aP=aO.originalEvent.touches[0];aK=aC();aJ=aA();aM=aP.pageX;aL=aP.pageY;aN=false;s=true}).bind("touchmove.html",function(aR){if(!s){return}var aQ=aR.originalEvent.touches[0],aP=Z,aO=I;P.scrollTo(aK+aM-aQ.pageX,aJ+aL-aQ.pageY);aN=aN||Math.abs(aM-aQ.pageX)>5||Math.abs(aL-aQ.pageY)>5;return aP==Z&&aO==I}).bind("touchend.html",function(aO){s=false}).bind("click.jsp-touchclick",function(aO){if(aN){aN=false;return false}})}function h(){var s=aA(),aJ=aC();D.removeClass("jspScrollable").unbind(".jsp");
D.replaceWith(ao.append(X.children()));ao.scrollTop(s);ao.scrollLeft(aJ)}b.extend(P,{reinitialise:function(aJ){aJ=b.extend({},ay,aJ);ar(aJ)},scrollToElement:function(aK,aJ,s){aa(aK,aJ,s)},scrollTo:function(aK,s,aJ){M(aK,aJ);L(s,aJ)},scrollToX:function(aJ,s){M(aJ,s)},scrollToY:function(s,aJ){L(s,aJ)},scrollToPercentX:function(aJ,s){M(aJ*(S-aj),s)},scrollToPercentY:function(aJ,s){L(aJ*(Y-w),s)},scrollBy:function(aJ,s,aK){P.scrollByX(aJ,aK);P.scrollByY(s,aK)},scrollByX:function(s,aK){var aJ=aC()+s,aL=aJ/(S-aj);V(aL*k,aK)},scrollByY:function(s,aK){var aJ=aA()+s,aL=aJ/(Y-w);U(aL*j,aK)},positionDragX:function(s,aJ){V(s,aJ)},positionDragY:function(aJ,s){V(aJ,s)},animate:function(aJ,aM,s,aL){var aK={};aK[aM]=s;aJ.animate(aK,{duration:ay.animateDuration,ease:ay.animateEase,queue:false,step:aL})},getContentPositionX:function(){return aC()},getContentPositionY:function(){return aA()},getContentWidth:function(){return S()},getContentHeight:function(){return Y()},getPercentScrolledX:function(){return aC()/(S-aj)},getPercentScrolledY:function(){return aA()/(Y-w)},getIsScrollableH:function(){return aE},getIsScrollableV:function(){return az},getContentPane:function(){return X},scrollToBottom:function(s){U(j,s)},hijackInternalLinks:function(){n()},destroy:function(){h()}});ar(N)}f=b.extend({},b.fn.jScrollPane.defaults,f);b.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){f[this]=f[this]||f.speed});var e;this.each(function(){var g=b(this),h=g.data("jsp");if(h){h.reinitialise(f)}else{h=new d(g,f);g.data("jsp",h)}e=e?e.add(g):g});return e};b.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,initialDelay:300,speed:30,scrollPagePercent:0.8}})(jQuery,this);
