/*!
 * jScrollPane - v2.0.0beta9 - 2011-02-04
 * http://jscrollpane.kelvinluck.com/
 *
 * Copyright (c) 2010 Kelvin Luck
 * Dual licensed under the MIT and GPL licenses.
 */

// Script: jScrollPane - cross browser customisable scrollbars
//
// *Version: 2.0.0beta10, Last updated: 2011-02-04*
//
// Project Home - http://jscrollpane.kelvinluck.com/
// GitHub       - http://github.com/vitch/jScrollPane
// Source       - http://github.com/vitch/jScrollPane/raw/master/script/jquery.jscrollpane.js
// (Minified)   - http://github.com/vitch/jScrollPane/raw/master/script/jquery.jscrollpane.min.js
//
// About: License
//
// Copyright (c) 2010 Kelvin Luck
// Dual licensed under the MIT or GPL Version 2 licenses.
// http://jscrollpane.kelvinluck.com/MIT-LICENSE.txt
// http://jscrollpane.kelvinluck.com/GPL-LICENSE.txt
//
// About: Examples
//
// All examples and demos are available through the jScrollPane example site at:
// http://jscrollpane.kelvinluck.com/
//
// About: Support and Testing
//
// This plugin is tested on the browsers below and has been found to work reliably on them. If you run
// into a problem on one of the supported browsers then please visit the support section on the jScrollPane
// website (http://jscrollpane.kelvinluck.com/) for more information on getting support. You are also
// welcome to fork the project on GitHub if you can contribute a fix for a given issue. 
//
// jQuery Versions - tested in 1.4.2+ - reported to work in 1.3.x
// Browsers Tested - Firefox 3.6.8, Safari 5, Opera 10.6, Chrome 5.0, IE 6, 7, 8
//
// About: Release History
//
// 2.0.0beta10 - (in progress)
// 2.0.0beta9 - (2011-01-31) new API methods, bug fixes and correct keyboard support for FF/OSX
// 2.0.0beta8 - (2011-01-29) touchscreen support, improved keyboard support
// 2.0.0beta7 - (2011-01-23) scroll speed consistent (thanks Aivo Paas)
// 2.0.0beta6 - (2010-12-07) scrollToElement horizontal support
// 2.0.0beta5 - (2010-10-18) jQuery 1.4.3 support, various bug fixes
// 2.0.0beta4 - (2010-09-17) clickOnTrack support, bug fixes
// 2.0.0beta3 - (2010-08-27) Horizontal mousewheel, mwheelIntent, keyboard support, bug fixes
// 2.0.0beta2 - (2010-08-21) Bug fixes
// 2.0.0beta1 - (2010-08-17) Rewrite to follow modern best practices and enable horizontal scrolling, initially hidden
//							 elements and dynamically sized elements.
// 1.x - (2006-12-31 - 2010-07-31) Initial version, hosted at googlecode, deprecated

(function(d,Ja,I){d.fn.jScrollPane=function(J){function ya(g,O){function ga(a){var b,c,f,h,i;e=a;if(l===I){h=g.scrollTop();i=g.scrollLeft();g.css({overflow:"hidden",padding:"0 8px 0 0"});s=g.innerWidth()+U;m=g.innerHeight();l=d('<div class="jspPane" />').css("padding",oa).append(g.children());k=d('<div class="jspContainer" />').css({height:m+"px"}).append(l).appendTo(g)}else{g.css("width","");if(a=g.innerWidth()+U!=s||g.outerHeight()!=m){s=g.innerWidth()+U;m=g.innerHeight();k.css({height:m+"px"})}if(!a&& pa==x&&l.outerHeight()==t)return;pa=x;l.css("width","");k.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}a=l.clone(false,false).css("position","absolute");b=d('<div style="width:1px; position: relative;" />').append(a);d("body").append(b);x=Math.max(l.outerWidth(),a.outerWidth());b.remove();t=l.outerHeight();ha=x/s;$=t/m;y=$>1;if((z=ha>1)||y){g.addClass("jspScrollable");if(a=e.maintainPosition&&(p||q)){c=K();f=L()}za();Aa();Ba();if(a){P(c,false);D(f,false)}Ca();Da();Ea();e.enableKeyboardNavigation&& Fa();e.clickOnTrack&&Ga();Ha();e.hijackInternalLinks&&qa()}else{g.removeClass("jspScrollable");l.css({top:0});k.unbind(ia);l.find(":input,a").unbind("focus.jsp");g.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp keypress.jsp");ra();sa()}if(e.autoReinitialise&&!aa)aa=setInterval(function(){ga(e)},e.autoReinitialiseDelay);else!e.autoReinitialise&&aa&&clearInterval(aa);h&&g.scrollTop(0)&&D(h,false);i&&g.scrollLeft(0)&&P(i,false);g.trigger("jsp-initialised",[z||y])}function za(){if(y){k.append(d('<div class="jspVerticalBar" />').append(d('<div class="jspCap jspCapTop" />'), d('<div class="jspTrack" />').append(d('<div class="jspDrag" />').append(d('<div class="jspDragTop" />'),d('<div class="jspDragBottom" />'))),d('<div class="jspCap jspCapBottom" />')));ja=k.find(">.jspVerticalBar");A=ja.find(">.jspTrack");u=A.find(">.jspDrag");if(e.showArrows){V=d('<a class="jspArrow jspArrowUp" />').bind("mousedown.jsp",E(0,-1)).bind("click.jsp",Q);W=d('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp",E(0,1)).bind("click.jsp",Q);if(e.arrowScrollOnHover){V.bind("mouseover.jsp", E(0,-1,V));W.bind("mouseover.jsp",E(0,1,W))}ta(A,e.verticalArrowPositions,V,W)}R=m;k.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){R-=d(this).outerHeight()});u.hover(function(){u.addClass("jspHover")},function(){u.removeClass("jspHover")}).bind("mousedown.jsp",function(a){d("html").bind("dragstart.jsp selectstart.jsp",Q);u.addClass("jspActive");var b=a.pageY-u.position().top;d("html").bind("mousemove.jsp",function(c){S(c.pageY-b,false)}).bind("mouseup.jsp mouseleave.jsp", ua);return false});va()}}function va(){A.height(R+"px");p=0;wa=e.verticalGutter+A.outerWidth();ja.position().left===0&&l.css("margin-left",wa+"px")}function Aa(){if(z){k.append(d('<div class="jspHorizontalBar" />').append(d('<div class="jspCap jspCapLeft" />'),d('<div class="jspTrack" />').append(d('<div class="jspDrag" />').append(d('<div class="jspDragLeft" />'),d('<div class="jspDragRight" />'))),d('<div class="jspCap jspCapRight" />')));ka=k.find(">.jspHorizontalBar");B=ka.find(">.jspTrack"); v=B.find(">.jspDrag");if(e.showArrows){X=d('<a class="jspArrow jspArrowLeft" />').bind("mousedown.jsp",E(-1,0)).bind("click.jsp",Q);Y=d('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp",E(1,0)).bind("click.jsp",Q);if(e.arrowScrollOnHover){X.bind("mouseover.jsp",E(-1,0,X));Y.bind("mouseover.jsp",E(1,0,Y))}ta(B,e.horizontalArrowPositions,X,Y)}v.hover(function(){v.addClass("jspHover")},function(){v.removeClass("jspHover")}).bind("mousedown.jsp",function(a){d("html").bind("dragstart.jsp selectstart.jsp", Q);v.addClass("jspActive");var b=a.pageX-v.position().left;d("html").bind("mousemove.jsp",function(c){M(c.pageX-b,false)}).bind("mouseup.jsp mouseleave.jsp",ua);return false});N=k.innerWidth();xa()}}function xa(){k.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){N-=d(this).outerWidth()});B.width(N+"px");q=0}function Ba(){if(z&&y){var a=B.outerHeight(),b=A.outerWidth();R-=a;d(ka).find(">.jspCap:visible,>.jspArrow").each(function(){N+=d(this).outerWidth()});N-= b;m-=b;s-=a;B.parent().append(d('<div class="jspCorner" />').css("width",a+"px"));va();xa()}z&&l.width(k.outerWidth()-U+"px");t=l.outerHeight();$=t/m;if(z){F=Math.ceil(1/ha*N);if(F>e.horizontalDragMaxWidth)F=e.horizontalDragMaxWidth;else if(F<e.horizontalDragMinWidth)F=e.horizontalDragMinWidth;v.width(F+"px");G=N-F;la(q)}if(y){H=Math.ceil(1/$*R);if(H>e.verticalDragMaxHeight)H=e.verticalDragMaxHeight;else if(H<e.verticalDragMinHeight)H=e.verticalDragMinHeight;u.height(H+"px");C=R-H;ma(p)}}function ta(a, b,c,f){var h="before",i="after";if(b=="os")b=/Mac/.test(navigator.platform)?"after":"split";if(b==h)i=b;else if(b==i){h=b;b=c;c=f;f=b}a[h](c)[i](f)}function E(a,b,c){return function(){Ia(a,b,this,c);this.blur();return false}}function Ia(a,b,c,f){c=d(c).addClass("jspActive");var h,i,j=true,r=function(){a!==0&&o.scrollByX(a*e.arrowButtonSpeed);b!==0&&o.scrollByY(b*e.arrowButtonSpeed);i=setTimeout(r,j?e.initialDelay:e.arrowRepeatFreq);j=false};r();h=f?"mouseout.jsp":"mouseup.jsp";f=f||d("html");f.bind(h, function(){c.removeClass("jspActive");i&&clearTimeout(i);i=null;f.unbind(h)})}function Ga(){ra();y&&A.bind("mousedown.jsp",function(a){if(a.originalTarget===I||a.originalTarget==a.currentTarget){var b=d(this),c=b.offset(),f=a.pageY-c.top-p,h,i=true,j=function(){var n=b.offset();n=a.pageY-n.top-H/2;var w=m*e.scrollPagePercent,T=C*w/(t-m);if(f<0)p-T>n?o.scrollByY(-w):S(n);else if(f>0)p+T<n?o.scrollByY(w):S(n);else{r();return}h=setTimeout(j,i?e.initialDelay:e.trackClickRepeatFreq);i=false},r=function(){h&& clearTimeout(h);h=null;d(document).unbind("mouseup.jsp",r)};j();d(document).bind("mouseup.jsp",r);return false}});z&&B.bind("mousedown.jsp",function(a){if(a.originalTarget===I||a.originalTarget==a.currentTarget){var b=d(this),c=b.offset(),f=a.pageX-c.left-q,h,i=true,j=function(){var n=b.offset();n=a.pageX-n.left-F/2;var w=s*e.scrollPagePercent,T=G*w/(x-s);if(f<0)q-T>n?o.scrollByX(-w):M(n);else if(f>0)q+T<n?o.scrollByX(w):M(n);else{r();return}h=setTimeout(j,i?e.initialDelay:e.trackClickRepeatFreq); i=false},r=function(){h&&clearTimeout(h);h=null;d(document).unbind("mouseup.jsp",r)};j();d(document).bind("mouseup.jsp",r);return false}})}function ra(){B&&B.unbind("mousedown.jsp");A&&A.unbind("mousedown.jsp")}function ua(){d("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp");u&&u.removeClass("jspActive");v&&v.removeClass("jspActive")}function S(a,b){if(y){if(a<0)a=0;else if(a>C)a=C;if(b===I)b=e.animateScroll;if(b)o.animate(u,"top",a,ma);else{u.css("top",a); ma(a)}}}function ma(a){if(a===I)a=u.position().top;k.scrollTop(0);p=a;var b=p===0,c=p==C;a=-(a/C)*(t-m);if(ba!=b||ca!=c){ba=b;ca=c;g.trigger("jsp-arrow-change",[ba,ca,da,ea])}if(e.showArrows){V[b?"addClass":"removeClass"]("jspDisabled");W[c?"addClass":"removeClass"]("jspDisabled")}l.css("top",a);g.trigger("jsp-scroll-y",[-a,b,c]).trigger("scroll")}function M(a,b){if(z){if(a<0)a=0;else if(a>G)a=G;if(b===I)b=e.animateScroll;if(b)o.animate(v,"left",a,la);else{v.css("left",a);la(a)}}}function la(a){if(a=== I)a=v.position().left;k.scrollTop(0);q=a;var b=q===0,c=q==G;a=-(a/G)*(x-s);if(da!=b||ea!=c){da=b;ea=c;g.trigger("jsp-arrow-change",[ba,ca,da,ea])}if(e.showArrows){X[b?"addClass":"removeClass"]("jspDisabled");Y[c?"addClass":"removeClass"]("jspDisabled")}l.css("left",a);g.trigger("jsp-scroll-x",[-a,b,c]).trigger("scroll")}function D(a,b){S(a/(t-m)*C,b)}function P(a,b){M(a/(x-s)*G,b)}function Z(a,b,c){var f,h,i=0,j=0,r,n,w;try{f=d(a)}catch(T){return}h=f.outerHeight();a=f.outerWidth();k.scrollTop(0); for(k.scrollLeft(0);!f.is(".jspPane");){i+=f.position().top;j+=f.position().left;f=f.offsetParent();if(/^body|html$/i.test(f[0].nodeName))return}f=L();r=f+m;if(i<f||b)n=i-e.verticalGutter;else if(i+h>r)n=i-m+h+e.verticalGutter;n&&D(n,c);viewportLeft=K();i=viewportLeft+s;if(j<viewportLeft||b)w=j-e.horizontalGutter;else if(j+a>i)w=j-s+a+e.horizontalGutter;w&&P(w,c)}function K(){return-l.position().left}function L(){return-l.position().top}function Da(){k.unbind(ia).bind(ia,function(a,b,c,f){a=q;b=p; o.scrollBy(c*e.mouseWheelSpeed,-f*e.mouseWheelSpeed,false);return a==q&&b==p})}function Q(){return false}function Ca(){l.find(":input,a").unbind("focus.jsp").bind("focus.jsp",function(a){Z(a.target,false)})}function Fa(){function a(){var f=q,h=p;switch(b){case 40:o.scrollByY(e.keyboardSpeed,false);break;case 38:o.scrollByY(-e.keyboardSpeed,false);break;case 34:case 32:o.scrollByY(m*e.scrollPagePercent,false);break;case 33:o.scrollByY(-m*e.scrollPagePercent,false);break;case 39:o.scrollByX(e.keyboardSpeed, false);break;case 37:o.scrollByX(-e.keyboardSpeed,false)}return c=f!=q||h!=p}var b,c;l.focus(function(){g.focus()});g.attr("tabindex",0).unbind("keydown.jsp keypress.jsp").bind("keydown.jsp",function(f){if(f.target===this){var h=q,i=p;switch(f.keyCode){case 40:case 38:case 34:case 32:case 33:case 39:case 37:b=f.keyCode;a();break;case 35:D(t-m);b=null;break;case 36:D(0);b=null}c=f.keyCode==b&&h!=q||i!=p;return!c}}).bind("keypress.jsp",function(f){f.keyCode==b&&a();return!c});if(e.hideFocus){g.css("outline", "none");"hideFocus"in k[0]&&g.attr("hideFocus",true)}else{g.css("outline","");"hideFocus"in k[0]&&g.attr("hideFocus",false)}}function Ha(){if(location.hash&&location.hash.length>1){var a,b;try{a=d(location.hash)}catch(c){return}if(a.length&&l.find(location.hash))if(k.scrollTop()===0)b=setInterval(function(){if(k.scrollTop()>0){Z(location.hash,true);d(document).scrollTop(k.position().top);clearInterval(b)}},50);else{Z(location.hash,true);d(document).scrollTop(k.position().top)}}}function sa(){d("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")} function qa(){sa();d("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&&l.find("#"+a).length>0){Z("#"+a,true);return false}}})}function Ea(){var a,b,c,f,h,i=false;k.unbind("touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick").bind("touchstart.jsp",function(j){j=j.originalEvent.touches[0];a=K();b=L();c=j.pageX;f=j.pageY;h=false;i=true}).bind("touchmove.jsp",function(j){if(i){j=j.originalEvent.touches[0]; var r=q,n=p;o.scrollTo(a+c-j.pageX,b+f-j.pageY);h=h||Math.abs(c-j.pageX)>5||Math.abs(f-j.pageY)>5;return r==q&&n==p}}).bind("touchend.jsp",function(){i=false}).bind("click.jsp-touchclick",function(){if(h)return h=false})}var e,o=this,l,s,m,k,x,t,ha,$,y,z,u,C,p,v,G,q,ja,A,wa,R,H,V,W,ka,B,N,F,X,Y,aa,oa,U,pa,ba=true,da=true,ca=false,ea=false,na=g.clone(false,false).empty(),ia=d.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";oa=g.css("paddingTop")+" "+g.css("paddingRight")+" "+g.css("paddingBottom")+ " "+g.css("paddingLeft");U=(parseInt(g.css("paddingLeft"),10)||0)+(parseInt(g.css("paddingRight"),10)||0);d.extend(o,{reinitialise:function(a){a=d.extend({},e,a);ga(a)},scrollToElement:function(a,b,c){Z(a,b,c)},scrollTo:function(a,b,c){P(a,c);D(b,c)},scrollToX:function(a,b){P(a,b)},scrollToY:function(a,b){D(a,b)},scrollToPercentX:function(a,b){P(a*(x-s),b)},scrollToPercentY:function(a,b){D(a*(t-m),b)},scrollBy:function(a,b,c){o.scrollByX(a,c);o.scrollByY(b,c)},scrollByX:function(a,b){var c=(K()+a)/ (x-s);M(c*G,b)},scrollByY:function(a,b){var c=(L()+a)/(t-m);S(c*C,b)},positionDragX:function(a,b){M(a,b)},positionDragY:function(a,b){M(a,b)},animate:function(a,b,c,f){var h={};h[b]=c;a.animate(h,{duration:e.animateDuration,ease:e.animateEase,queue:false,step:f})},getContentPositionX:function(){return K()},getContentPositionY:function(){return L()},getContentWidth:function(){return x()},getContentHeight:function(){return t()},getPercentScrolledX:function(){return K()/(x-s)},getPercentScrolledY:function(){return L()/ (t-m)},getIsScrollableH:function(){return z},getIsScrollableV:function(){return y},getContentPane:function(){return l},scrollToBottom:function(a){S(C,a)},hijackInternalLinks:function(){qa()},destroy:function(){var a=L(),b=K();g.removeClass("jspScrollable").unbind(".jsp");g.replaceWith(na.append(l.children()));na.scrollTop(a);na.scrollLeft(b)}});ga(O)}J=d.extend({},d.fn.jScrollPane.defaults,J);d.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){J[this]=J[this]|| J.speed});var fa;this.each(function(){var g=d(this),O=g.data("jsp");if(O)O.reinitialise(J);else{O=new ya(g,J);g.data("jsp",O)}fa=fa?fa.add(g):g});return fa};d.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);
