/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.4
 * 
 * Requires: 1.2.2+
 */(function($){var types=["DOMMouseScroll","mousewheel"];$.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var i=types.length;i;)this.addEventListener(types[--i],handler,!1);else this.onmousewheel=handler},teardown:function(){if(this.removeEventListener)for(var i=types.length;i;)this.removeEventListener(types[--i],handler,!1);else this.onmousewheel=null}},$.fn.extend({mousewheel:function(fn){return fn?this.bind("mousewheel",fn):this.trigger("mousewheel")},unmousewheel:function(fn){return this.unbind("mousewheel",fn)}});function handler(event){var orgEvent=event||window.event,args=[].slice.call(arguments,1),delta=0,returnValue=!0,deltaX=0,deltaY=0;return event=$.event.fix(orgEvent),event.type="mousewheel",event.wheelDelta&&(delta=event.wheelDelta/120),event.detail&&(delta=-event.detail/3),deltaY=delta,orgEvent.axis!==undefined&&orgEvent.axis===orgEvent.HORIZONTAL_AXIS&&(deltaY=0,deltaX=-1*delta),orgEvent.wheelDeltaY!==undefined&&(deltaY=orgEvent.wheelDeltaY/120),orgEvent.wheelDeltaX!==undefined&&(deltaX=-1*orgEvent.wheelDeltaX/120),args.unshift(event,delta,deltaX,deltaY),$.event.handle.apply(this,args)}})(jQuery),function($){var mwheelI={pos:[-260,-260]},minDif=3,doc=document,root=doc.documentElement,body=doc.body,longDelay,shortDelay;function unsetPos(){this===mwheelI.elem&&(mwheelI.pos=[-260,-260],mwheelI.elem=!1,minDif=3)}$.event.special.mwheelIntent={setup:function(){var jElm=$(this).bind("mousewheel",$.event.special.mwheelIntent.handler);return this!==doc&&this!==root&&this!==body&&jElm.bind("mouseleave",unsetPos),jElm=null,!0},teardown:function(){return $(this).unbind("mousewheel",$.event.special.mwheelIntent.handler).unbind("mouseleave",unsetPos),!0},handler:function(e,d){var pos=[e.clientX,e.clientY];if(this===mwheelI.elem||Math.abs(mwheelI.pos[0]-pos[0])>minDif||Math.abs(mwheelI.pos[1]-pos[1])>minDif)return mwheelI.elem=this,mwheelI.pos=pos,minDif=250,clearTimeout(shortDelay),shortDelay=setTimeout(function(){minDif=10},200),clearTimeout(longDelay),longDelay=setTimeout(function(){minDif=3},1500),e=$.extend({},e,{type:"mwheelIntent"}),$.event.handle.apply(this,arguments)}},$.fn.extend({mwheelIntent:function(fn){return fn?this.bind("mwheelIntent",fn):this.trigger("mwheelIntent")},unmwheelIntent:function(fn){return this.unbind("mwheelIntent",fn)}}),$(function(){body=doc.body,$(doc).bind("mwheelIntent.mwheelIntentDefault",$.noop)})}(jQuery),function($,window,undefined){$.fn.jScrollPane=function(settings){function JScrollPane(elem,s){var settings,jsp=this,pane,paneWidth,paneHeight,container,contentWidth,contentHeight,percentInViewH,percentInViewV,isScrollableV,isScrollableH,verticalDrag,dragMaxY,verticalDragPosition,horizontalDrag,dragMaxX,horizontalDragPosition,verticalBar,verticalTrack,scrollbarWidth,verticalTrackHeight,verticalDragHeight,arrowUp,arrowDown,horizontalBar,horizontalTrack,horizontalTrackWidth,horizontalDragWidth,arrowLeft,arrowRight,reinitialiseInterval,originalPadding,originalPaddingTotalWidth,previousContentWidth,wasAtTop=!0,wasAtLeft=!0,wasAtBottom=!1,wasAtRight=!1,originalElement=elem.clone(!1,!1).empty(),mwEvent=$.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";originalPadding=elem.css("paddingTop")+" "+elem.css("paddingRight")+" "+elem.css("paddingBottom")+" "+elem.css("paddingLeft"),originalPaddingTotalWidth=(parseInt(elem.css("paddingLeft"),10)||0)+(parseInt(elem.css("paddingRight"),10)||0);function initialise(s){var isMaintainingPositon,lastContentX,lastContentY,hasContainingSpaceChanged,originalScrollTop,originalScrollLeft,maintainAtBottom=!1,maintainAtRight=!1;settings=s;if(pane===undefined)originalScrollTop=elem.scrollTop(),originalScrollLeft=elem.scrollLeft(),elem.css({overflow:"hidden",padding:0}),paneWidth=elem.innerWidth()+originalPaddingTotalWidth,paneHeight=elem.innerHeight(),elem.width(paneWidth),pane=$('<div class="jspPane" />').css("padding",originalPadding).append(elem.children()),container=$('<div class="jspContainer" />').css({width:paneWidth+"px",height:paneHeight+"px"}).append(pane).appendTo(elem);else{elem.css("width",""),maintainAtBottom=settings.stickToBottom&&isCloseToBottom(),maintainAtRight=settings.stickToRight&&isCloseToRight(),hasContainingSpaceChanged=elem.innerWidth()+originalPaddingTotalWidth!=paneWidth||elem.outerHeight()!=paneHeight,hasContainingSpaceChanged&&(paneWidth=elem.innerWidth()+originalPaddingTotalWidth,paneHeight=elem.innerHeight(),container.css({width:paneWidth+"px",height:paneHeight+"px"}));if(!hasContainingSpaceChanged&&previousContentWidth==contentWidth&&pane.outerHeight()==contentHeight){elem.width(paneWidth);return}previousContentWidth=contentWidth,pane.css("width",""),elem.width(paneWidth),container.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}pane.css("overflow","auto"),s.contentWidth?contentWidth=s.contentWidth:contentWidth=pane[0].scrollWidth,contentHeight=pane[0].scrollHeight,pane.css("overflow",""),percentInViewH=contentWidth/paneWidth,percentInViewV=contentHeight/paneHeight,isScrollableV=percentInViewV>1,isScrollableH=percentInViewH>1,!isScrollableH&&!isScrollableV?(elem.removeClass("jspScrollable"),pane.css({top:0,width:container.width()-originalPaddingTotalWidth}),removeMousewheel(),removeFocusHandler(),removeKeyboardNav(),removeClickOnTrack(),unhijackInternalLinks()):(elem.addClass("jspScrollable"),isMaintainingPositon=settings.maintainPosition&&(verticalDragPosition||horizontalDragPosition),isMaintainingPositon&&(lastContentX=contentPositionX(),lastContentY=contentPositionY()),initialiseVerticalScroll(),initialiseHorizontalScroll(),resizeScrollbars(),isMaintainingPositon&&(scrollToX(maintainAtRight?contentWidth-paneWidth:lastContentX,!1),scrollToY(maintainAtBottom?contentHeight-paneHeight:lastContentY,!1)),initFocusHandler(),initMousewheel(),initTouch(),settings.enableKeyboardNavigation&&initKeyboardNav(),settings.clickOnTrack&&initClickOnTrack(),observeHash(),settings.hijackInternalLinks&&hijackInternalLinks()),settings.autoReinitialise&&!reinitialiseInterval?reinitialiseInterval=setInterval(function(){initialise(settings)},settings.autoReinitialiseDelay):!settings.autoReinitialise&&reinitialiseInterval&&clearInterval(reinitialiseInterval),originalScrollTop&&elem.scrollTop(0)&&scrollToY(originalScrollTop,!1),originalScrollLeft&&elem.scrollLeft(0)&&scrollToX(originalScrollLeft,!1),elem.trigger("jsp-initialised",[isScrollableH||isScrollableV])}function initialiseVerticalScroll(){isScrollableV&&(container.append($('<div class="jspVerticalBar" />').append($('<div class="jspCap jspCapTop" />'),$('<div class="jspTrack" />').append($('<div class="jspDrag" />').append($('<div class="jspDragTop" />'),$('<div class="jspDragBottom" />'))),$('<div class="jspCap jspCapBottom" />'))),verticalBar=container.find(">.jspVerticalBar"),verticalTrack=verticalBar.find(">.jspTrack"),verticalDrag=verticalTrack.find(">.jspDrag"),settings.showArrows&&(arrowUp=$('<a class="jspArrow jspArrowUp" />').bind("mousedown.jsp",getArrowScroll(0,-1)).bind("click.jsp",nil),arrowDown=$('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp",getArrowScroll(0,1)).bind("click.jsp",nil),settings.arrowScrollOnHover&&(arrowUp.bind("mouseover.jsp",getArrowScroll(0,-1,arrowUp)),arrowDown.bind("mouseover.jsp",getArrowScroll(0,1,arrowDown))),appendArrows(verticalTrack,settings.verticalArrowPositions,arrowUp,arrowDown)),verticalTrackHeight=paneHeight,container.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){verticalTrackHeight-=$(this).outerHeight()}),verticalDrag.hover(function(){verticalDrag.addClass("jspHover")},function(){verticalDrag.removeClass("jspHover")}).bind("mousedown.jsp",function(e){$("html").bind("dragstart.jsp selectstart.jsp",nil),verticalDrag.addClass("jspActive");var startY=e.pageY-verticalDrag.position().top;return $("html").bind("mousemove.jsp",function(e){positionDragY(e.pageY-startY,!1)}).bind("mouseup.jsp mouseleave.jsp",cancelDrag),!1}),sizeVerticalScrollbar())}function sizeVerticalScrollbar(){verticalTrack.height(verticalTrackHeight+"px"),verticalDragPosition=0,scrollbarWidth=settings.verticalGutter+verticalTrack.outerWidth(),pane.width(paneWidth-scrollbarWidth-originalPaddingTotalWidth);try{verticalBar.position().left===0&&pane.css("margin-left",scrollbarWidth+"px")}catch(err){}}function initialiseHorizontalScroll(){isScrollableH&&(container.append($('<div class="jspHorizontalBar" />').append($('<div class="jspCap jspCapLeft" />'),$('<div class="jspTrack" />').append($('<div class="jspDrag" />').append($('<div class="jspDragLeft" />'),$('<div class="jspDragRight" />'))),$('<div class="jspCap jspCapRight" />'))),horizontalBar=container.find(">.jspHorizontalBar"),horizontalTrack=horizontalBar.find(">.jspTrack"),horizontalDrag=horizontalTrack.find(">.jspDrag"),settings.showArrows&&(arrowLeft=$('<a class="jspArrow jspArrowLeft" />').bind("mousedown.jsp",getArrowScroll(-1,0)).bind("click.jsp",nil),arrowRight=$('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp",getArrowScroll(1,0)).bind("click.jsp",nil),settings.arrowScrollOnHover&&(arrowLeft.bind("mouseover.jsp",getArrowScroll(-1,0,arrowLeft)),arrowRight.bind("mouseover.jsp",getArrowScroll(1,0,arrowRight))),appendArrows(horizontalTrack,settings.horizontalArrowPositions,arrowLeft,arrowRight)),horizontalDrag.hover(function(){horizontalDrag.addClass("jspHover")},function(){horizontalDrag.removeClass("jspHover")}).bind("mousedown.jsp",function(e){$("html").bind("dragstart.jsp selectstart.jsp",nil),horizontalDrag.addClass("jspActive");var startX=e.pageX-horizontalDrag.position().left;return $("html").bind("mousemove.jsp",function(e){positionDragX(e.pageX-startX,!1)}).bind("mouseup.jsp mouseleave.jsp",cancelDrag),!1}),horizontalTrackWidth=container.innerWidth(),sizeHorizontalScrollbar())}function sizeHorizontalScrollbar(){container.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){horizontalTrackWidth-=$(this).outerWidth()}),horizontalTrack.width(horizontalTrackWidth+"px"),horizontalDragPosition=0}function resizeScrollbars(){if(isScrollableH&&isScrollableV){var horizontalTrackHeight=horizontalTrack.outerHeight(),verticalTrackWidth=verticalTrack.outerWidth();verticalTrackHeight-=horizontalTrackHeight,$(horizontalBar).find(">.jspCap:visible,>.jspArrow").each(function(){horizontalTrackWidth+=$(this).outerWidth()}),horizontalTrackWidth-=verticalTrackWidth,paneHeight-=verticalTrackWidth,paneWidth-=horizontalTrackHeight,horizontalTrack.parent().append($('<div class="jspCorner" />').css("width",horizontalTrackHeight+"px")),sizeVerticalScrollbar(),sizeHorizontalScrollbar()}isScrollableH&&pane.width(container.outerWidth()-originalPaddingTotalWidth+"px"),contentHeight=pane.outerHeight(),percentInViewV=contentHeight/paneHeight,isScrollableH&&(horizontalDragWidth=Math.ceil(1/percentInViewH*horizontalTrackWidth),horizontalDragWidth>settings.horizontalDragMaxWidth?horizontalDragWidth=settings.horizontalDragMaxWidth:horizontalDragWidth<settings.horizontalDragMinWidth&&(horizontalDragWidth=settings.horizontalDragMinWidth),horizontalDrag.width(horizontalDragWidth+"px"),dragMaxX=horizontalTrackWidth-horizontalDragWidth,_positionDragX(horizontalDragPosition)),isScrollableV&&(verticalDragHeight=Math.ceil(1/percentInViewV*verticalTrackHeight),verticalDragHeight>settings.verticalDragMaxHeight?verticalDragHeight=settings.verticalDragMaxHeight:verticalDragHeight<settings.verticalDragMinHeight&&(verticalDragHeight=settings.verticalDragMinHeight),verticalDrag.height(verticalDragHeight+"px"),dragMaxY=verticalTrackHeight-verticalDragHeight,_positionDragY(verticalDragPosition))}function appendArrows(ele,p,a1,a2){var p1="before",p2="after",aTemp;p=="os"&&(p=/Mac/.test(navigator.platform)?"after":"split"),p==p1?p2=p:p==p2&&(p1=p,aTemp=a1,a1=a2,a2=aTemp),ele[p1](a1)[p2](a2)}function getArrowScroll(dirX,dirY,ele){return function(){return arrowScroll(dirX,dirY,this,ele),this.blur(),!1}}function arrowScroll(dirX,dirY,arrow,ele){arrow=$(arrow).addClass("jspActive");var eve,scrollTimeout,isFirst=!0,doScroll=function(){dirX!==0&&jsp.scrollByX(dirX*settings.arrowButtonSpeed),dirY!==0&&jsp.scrollByY(dirY*settings.arrowButtonSpeed),scrollTimeout=setTimeout(doScroll,isFirst?settings.initialDelay:settings.arrowRepeatFreq),isFirst=!1};doScroll(),eve=ele?"mouseout.jsp":"mouseup.jsp",ele=ele||$("html"),ele.bind(eve,function(){arrow.removeClass("jspActive"),scrollTimeout&&clearTimeout(scrollTimeout),scrollTimeout=null,ele.unbind(eve)})}function initClickOnTrack(){removeClickOnTrack(),isScrollableV&&verticalTrack.bind("mousedown.jsp",function(e){if(e.originalTarget===undefined||e.originalTarget==e.currentTarget){var clickedTrack=$(this),offset=clickedTrack.offset(),direction=e.pageY-offset.top-verticalDragPosition,scrollTimeout,isFirst=!0,doScroll=function(){var offset=clickedTrack.offset(),pos=e.pageY-offset.top-verticalDragHeight/2,contentDragY=paneHeight*settings.scrollPagePercent,dragY=dragMaxY*contentDragY/(contentHeight-paneHeight);if(direction<0)verticalDragPosition-dragY>pos?jsp.scrollByY(-contentDragY):positionDragY(pos);else if(direction>0)verticalDragPosition+dragY<pos?jsp.scrollByY(contentDragY):positionDragY(pos);else{cancelClick();return}scrollTimeout=setTimeout(doScroll,isFirst?settings.initialDelay:settings.trackClickRepeatFreq),isFirst=!1},cancelClick=function(){scrollTimeout&&clearTimeout(scrollTimeout),scrollTimeout=null,$(document).unbind("mouseup.jsp",cancelClick)};return doScroll(),$(document).bind("mouseup.jsp",cancelClick),!1}}),isScrollableH&&horizontalTrack.bind("mousedown.jsp",function(e){if(e.originalTarget===undefined||e.originalTarget==e.currentTarget){var clickedTrack=$(this),offset=clickedTrack.offset(),direction=e.pageX-offset.left-horizontalDragPosition,scrollTimeout,isFirst=!0,doScroll=function(){var offset=clickedTrack.offset(),pos=e.pageX-offset.left-horizontalDragWidth/2,contentDragX=paneWidth*settings.scrollPagePercent,dragX=dragMaxX*contentDragX/(contentWidth-paneWidth);if(direction<0)horizontalDragPosition-dragX>pos?jsp.scrollByX(-contentDragX):positionDragX(pos);else if(direction>0)horizontalDragPosition+dragX<pos?jsp.scrollByX(contentDragX):positionDragX(pos);else{cancelClick();return}scrollTimeout=setTimeout(doScroll,isFirst?settings.initialDelay:settings.trackClickRepeatFreq),isFirst=!1},cancelClick=function(){scrollTimeout&&clearTimeout(scrollTimeout),scrollTimeout=null,$(document).unbind("mouseup.jsp",cancelClick)};return doScroll(),$(document).bind("mouseup.jsp",cancelClick),!1}})}function removeClickOnTrack(){horizontalTrack&&horizontalTrack.unbind("mousedown.jsp"),verticalTrack&&verticalTrack.unbind("mousedown.jsp")}function cancelDrag(){$("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp"),verticalDrag&&verticalDrag.removeClass("jspActive"),horizontalDrag&&horizontalDrag.removeClass("jspActive")}function positionDragY(destY,animate){if(!isScrollableV)return;destY<0?destY=0:destY>dragMaxY&&(destY=dragMaxY),animate===undefined&&(animate=settings.animateScroll),animate?jsp.animate(verticalDrag,"top",destY,_positionDragY):(verticalDrag.css("top",destY),_positionDragY(destY))}function _positionDragY(destY){destY===undefined&&(destY=verticalDrag.position().top),container.scrollTop(0),verticalDragPosition=destY;var isAtTop=verticalDragPosition===0,isAtBottom=verticalDragPosition==dragMaxY,percentScrolled=destY/dragMaxY,destTop=-percentScrolled*(contentHeight-paneHeight);if(wasAtTop!=isAtTop||wasAtBottom!=isAtBottom)wasAtTop=isAtTop,wasAtBottom=isAtBottom,elem.trigger("jsp-arrow-change",[wasAtTop,wasAtBottom,wasAtLeft,wasAtRight]);updateVerticalArrows(isAtTop,isAtBottom),pane.css("top",destTop),elem.trigger("jsp-scroll-y",[-destTop,isAtTop,isAtBottom]).trigger("scroll")}function positionDragX(destX,animate){if(!isScrollableH)return;destX<0?destX=0:destX>dragMaxX&&(destX=dragMaxX),animate===undefined&&(animate=settings.animateScroll),animate?jsp.animate(horizontalDrag,"left",destX,_positionDragX):(horizontalDrag.css("left",destX),_positionDragX(destX))}function _positionDragX(destX){destX===undefined&&(destX=horizontalDrag.position().left),container.scrollTop(0),horizontalDragPosition=destX;var isAtLeft=horizontalDragPosition===0,isAtRight=horizontalDragPosition==dragMaxX,percentScrolled=destX/dragMaxX,destLeft=-percentScrolled*(contentWidth-paneWidth);if(wasAtLeft!=isAtLeft||wasAtRight!=isAtRight)wasAtLeft=isAtLeft,wasAtRight=isAtRight,elem.trigger("jsp-arrow-change",[wasAtTop,wasAtBottom,wasAtLeft,wasAtRight]);updateHorizontalArrows(isAtLeft,isAtRight),pane.css("left",destLeft),elem.trigger("jsp-scroll-x",[-destLeft,isAtLeft,isAtRight]).trigger("scroll")}function updateVerticalArrows(isAtTop,isAtBottom){settings.showArrows&&(arrowUp[isAtTop?"addClass":"removeClass"]("jspDisabled"),arrowDown[isAtBottom?"addClass":"removeClass"]("jspDisabled"))}function updateHorizontalArrows(isAtLeft,isAtRight){settings.showArrows&&(arrowLeft[isAtLeft?"addClass":"removeClass"]("jspDisabled"),arrowRight[isAtRight?"addClass":"removeClass"]("jspDisabled"))}function scrollToY(destY,animate){var percentScrolled=destY/(contentHeight-paneHeight);positionDragY(percentScrolled*dragMaxY,animate)}function scrollToX(destX,animate){var percentScrolled=destX/(contentWidth-paneWidth);positionDragX(percentScrolled*dragMaxX,animate)}function scrollToElement(ele,stickToTop,animate){var e,eleHeight,eleWidth,eleTop=0,eleLeft=0,viewportTop,viewportLeft,maxVisibleEleTop,maxVisibleEleLeft,destY,destX;try{e=$(ele)}catch(err){return}eleHeight=e.outerHeight(),eleWidth=e.outerWidth(),container.scrollTop(0),container.scrollLeft(0);while(!e.is(".jspPane")){eleTop+=e.position().top,eleLeft+=e.position().left,e=e.offsetParent();if(/^body|html$/i.test(e[0].nodeName))return}viewportTop=contentPositionY(),maxVisibleEleTop=viewportTop+paneHeight,eleTop<viewportTop||stickToTop?destY=eleTop-settings.verticalGutter:eleTop+eleHeight>maxVisibleEleTop&&(destY=eleTop-paneHeight+eleHeight+settings.verticalGutter),destY&&scrollToY(destY,animate),viewportLeft=contentPositionX(),maxVisibleEleLeft=viewportLeft+paneWidth,eleLeft<viewportLeft||stickToTop?destX=eleLeft-settings.horizontalGutter:eleLeft+eleWidth>maxVisibleEleLeft&&(destX=eleLeft-paneWidth+eleWidth+settings.horizontalGutter),destX&&scrollToX(destX,animate)}function contentPositionX(){return-pane.position().left}function contentPositionY(){return-pane.position().top}function isCloseToBottom(){var scrollableHeight=contentHeight-paneHeight;return scrollableHeight>20&&scrollableHeight-contentPositionY()<10}function isCloseToRight(){var scrollableWidth=contentWidth-paneWidth;return scrollableWidth>20&&scrollableWidth-contentPositionX()<10}function initMousewheel(){container.unbind(mwEvent).bind(mwEvent,function(event,delta,deltaX,deltaY){var dX=horizontalDragPosition,dY=verticalDragPosition;return jsp.scrollBy(deltaX*settings.mouseWheelSpeed,-deltaY*settings.mouseWheelSpeed,!1),dX==horizontalDragPosition&&dY==verticalDragPosition})}function removeMousewheel(){container.unbind(mwEvent)}function nil(){return!1}function initFocusHandler(){pane.find(":input,a").unbind("focus.jsp").bind("focus.jsp",function(e){scrollToElement(e.target,!1)})}function removeFocusHandler(){pane.find(":input,a").unbind("focus.jsp")}function initKeyboardNav(){var keyDown,elementHasScrolled,validParents=[];isScrollableH&&validParents.push(horizontalBar[0]),isScrollableV&&validParents.push(verticalBar[0]),pane.focus(function(){elem.focus()}),elem.attr("tabindex",0).unbind("keydown.jsp keypress.jsp").bind("keydown.jsp",function(e){if(e.target!==this&&(!validParents.length||!$(e.target).closest(validParents).length))return;var dX=horizontalDragPosition,dY=verticalDragPosition;switch(e.keyCode){case 40:case 38:case 34:case 32:case 33:case 39:case 37:keyDown=e.keyCode,keyDownHandler();break;case 35:scrollToY(contentHeight-paneHeight),keyDown=null;break;case 36:scrollToY(0),keyDown=null}return elementHasScrolled=e.keyCode==keyDown&&dX!=horizontalDragPosition||dY!=verticalDragPosition,!elementHasScrolled}).bind("keypress.jsp",function(e){return e.keyCode==keyDown&&keyDownHandler(),!elementHasScrolled}),settings.hideFocus?(elem.css("outline","none"),"hideFocus"in container[0]&&elem.attr("hideFocus",!0)):(elem.css("outline",""),"hideFocus"in container[0]&&elem.attr("hideFocus",!1));function keyDownHandler(){var dX=horizontalDragPosition,dY=verticalDragPosition;switch(keyDown){case 40:jsp.scrollByY(settings.keyboardSpeed,!1);break;case 38:jsp.scrollByY(-settings.keyboardSpeed,!1);break;case 34:case 32:jsp.scrollByY(paneHeight*settings.scrollPagePercent,!1);break;case 33:jsp.scrollByY(-paneHeight*settings.scrollPagePercent,!1);break;case 39:jsp.scrollByX(settings.keyboardSpeed,!1);break;case 37:jsp.scrollByX(-settings.keyboardSpeed,!1)}return elementHasScrolled=dX!=horizontalDragPosition||dY!=verticalDragPosition,elementHasScrolled}}function removeKeyboardNav(){elem.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp keypress.jsp")}function observeHash(){if(location.hash&&location.hash.length>1){var e,retryInt,hash=escape(location.hash);try{e=$(hash)}catch(err){return}e.length&&pane.find(hash)&&(container.scrollTop()===0?retryInt=setInterval(function(){container.scrollTop()>0&&(scrollToElement(hash,!0),$(document).scrollTop(container.position().top),clearInterval(retryInt))},50):(scrollToElement(hash,!0),$(document).scrollTop(container.position().top)))}}function unhijackInternalLinks(){$("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function hijackInternalLinks(){unhijackInternalLinks(),$("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",function(){var uriParts=this.href.split("#"),hash;if(uriParts.length>1){hash=uriParts[1];if(hash.length>0&&pane.find("#"+hash).length>0)return scrollToElement("#"+hash,!0),!1}})}function initTouch(){var startX,startY,touchStartX,touchStartY,moved,moving=!1;container.unbind("touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick").bind("touchstart.jsp",function(e){var touch=e.originalEvent.touches[0];startX=contentPositionX(),startY=contentPositionY(),touchStartX=touch.pageX,touchStartY=touch.pageY,moved=!1,moving=!0}).bind("touchmove.jsp",function(ev){if(!moving)return;var touchPos=ev.originalEvent.touches[0],dX=horizontalDragPosition,dY=verticalDragPosition;return jsp.scrollTo(startX+touchStartX-touchPos.pageX,startY+touchStartY-touchPos.pageY),moved=moved||Math.abs(touchStartX-touchPos.pageX)>5||Math.abs(touchStartY-touchPos.pageY)>5,dX==horizontalDragPosition&&dY==verticalDragPosition}).bind("touchend.jsp",function(e){moving=!1}).bind("click.jsp-touchclick",function(e){if(moved)return moved=!1,!1})}function destroy(){var currentY=contentPositionY(),currentX=contentPositionX();elem.removeClass("jspScrollable").unbind(".jsp"),elem.replaceWith(originalElement.append(pane.children())),originalElement.scrollTop(currentY),originalElement.scrollLeft(currentX)}$.extend(jsp,{reinitialise:function(s){s=$.extend({},settings,s),initialise(s)},scrollToElement:function(ele,stickToTop,animate){scrollToElement(ele,stickToTop,animate)},scrollTo:function(destX,destY,animate){scrollToX(destX,animate),scrollToY(destY,animate)},scrollToX:function(destX,animate){scrollToX(destX,animate)},scrollToY:function(destY,animate){scrollToY(destY,animate)},scrollToPercentX:function(destPercentX,animate){scrollToX(destPercentX*(contentWidth-paneWidth),animate)},scrollToPercentY:function(destPercentY,animate){scrollToY(destPercentY*(contentHeight-paneHeight),animate)},scrollBy:function(deltaX,deltaY,animate){jsp.scrollByX(deltaX,animate),jsp.scrollByY(deltaY,animate)},scrollByX:function(deltaX,animate){var destX=contentPositionX()+Math[deltaX<0?"floor":"ceil"](deltaX),percentScrolled=destX/(contentWidth-paneWidth);positionDragX(percentScrolled*dragMaxX,animate)},scrollByY:function(deltaY,animate){var destY=contentPositionY()+Math[deltaY<0?"floor":"ceil"](deltaY),percentScrolled=destY/(contentHeight-paneHeight);positionDragY(percentScrolled*dragMaxY,animate)},positionDragX:function(x,animate){positionDragX(x,animate)},positionDragY:function(y,animate){positionDragY(y,animate)},animate:function(ele,prop,value,stepCallback){var params={};params[prop]=value,ele.animate(params,{duration:settings.animateDuration,easing:settings.animateEase,queue:!1,step:stepCallback})},getContentPositionX:function(){return contentPositionX()},getContentPositionY:function(){return contentPositionY()},getContentWidth:function(){return contentWidth},getContentHeight:function(){return contentHeight},getPercentScrolledX:function(){return contentPositionX()/(contentWidth-paneWidth)},getPercentScrolledY:function(){return contentPositionY()/(contentHeight-paneHeight)},getIsScrollableH:function(){return isScrollableH},getIsScrollableV:function(){return isScrollableV},getContentPane:function(){return pane},scrollToBottom:function(animate){positionDragY(dragMaxY,animate)},hijackInternalLinks:function(){hijackInternalLinks()},destroy:function(){destroy()}}),initialise(s)}return settings=$.extend({},$.fn.jScrollPane.defaults,settings),$.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){settings[this]=settings[this]||settings.speed}),this.each(function(){var elem=$(this),jspApi=elem.data("jsp");jspApi?jspApi.reinitialise(settings):(jspApi=new JScrollPane(elem,settings),elem.data("jsp",jspApi))})},$.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:undefined,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:.8}}(jQuery,this),function($){$.fn.tweet=function(o){var s=$.extend({username:null,list:null,favorites:!1,query:null,avatar_size:null,count:3,fetch:null,page:1,retweets:!0,intro_text:null,outro_text:null,join_text:null,auto_join_text_default:"i said,",auto_join_text_ed:"i",auto_join_text_ing:"i am",auto_join_text_reply:"i replied to",auto_join_text_url:"i was looking at",loading_text:null,refresh_interval:null,twitter_url:"twitter.com",twitter_api_url:"api.twitter.com",twitter_search_url:"search.twitter.com",template:"{avatar}{time}{join}{text}",comparator:function(tweet1,tweet2){return tweet2.tweet_time-tweet1.tweet_time},filter:function(tweet){return!0}},o),url_regexp=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi;function t(template,info){if(typeof template=="string"){var result=template;for(var key in info){var val=info[key];result=result.replace(new RegExp("{"+key+"}","g"),val===null?"":val)}return result}return template(info)}$.extend({tweet:{t:t}});function replacer(regex,replacement){return function(){var returning=[];return this.each(function(){returning.push(this.replace(regex,replacement))}),$(returning)}}$.fn.extend({linkUrl:replacer(url_regexp,function(match){var url=/^[a-z]+:/i.test(match)?match:"http://"+match;return'<a href="'+url+'">'+match+"</a>"}),linkUser:replacer(/@(\w+)/gi,'@<a href="http://'+s.twitter_url+'/$1">$1</a>'),linkHash:replacer(/(?:^| )[\#]+([\w\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0600-\u06ff]+)/gi,' <a href="http://'+s.twitter_search_url+"/search?q=&tag=$1&lang=all"+(s.username&&s.username.length==1?"&from="+s.username.join("%2BOR%2B"):"")+'">#$1</a>'),capAwesome:replacer(/\b(awesome)\b/gi,'<span class="awesome">$1</span>'),capEpic:replacer(/\b(epic)\b/gi,'<span class="epic">$1</span>'),makeHeart:replacer(/(&lt;)+[3]/gi,"<tt class='heart'>&#x2665;</tt>")});function parse_date(date_str){return Date.parse(date_str.replace(/^([a-z]{3})( [a-z]{3} \d\d?)(.*)( \d{4})$/i,"$1,$2$4$3"))}function relative_time(date){var relative_to=arguments.length>1?arguments[1]:new Date,delta=parseInt((relative_to.getTime()-date)/1e3,10),r="";return delta<60?r=delta+" seconds ago":delta<120?r="a minute ago":delta<2700?r=parseInt(delta/60,10).toString()+" minutes ago":delta<7200?r="an hour ago":delta<86400?r=""+parseInt(delta/3600,10).toString()+" hours ago":delta<172800?r="a day ago":r=parseInt(delta/86400,10).toString()+" days ago","about "+r}function build_auto_join_text(text){return text.match(/^(@([A-Za-z0-9-_]+)) .*/i)?s.auto_join_text_reply:text.match(url_regexp)?s.auto_join_text_url:text.match(/^((\w+ed)|just) .*/im)?s.auto_join_text_ed:text.match(/^(\w*ing) .*/i)?s.auto_join_text_ing:s.auto_join_text_default}function maybe_https(url){return"https:"==document.location.protocol?url.replace(/^http:/,"https:"):url}function build_api_url(){var proto="https:"==document.location.protocol?"https:":"http:",count=s.fetch===null?s.count:s.fetch;if(s.list)return proto+"//"+s.twitter_api_url+"/1/"+s.username[0]+"/lists/"+s.list+"/statuses.json?page="+s.page+"&per_page="+count+"&callback=?";if(s.favorites)return proto+"//"+s.twitter_api_url+"/favorites/"+s.username[0]+".json?page="+s.page+"&count="+count+"&callback=?";if(s.query===null&&s.username.length==1)return proto+"//"+s.twitter_api_url+"/1/statuses/user_timeline.json?screen_name="+s.username[0]+"&count="+count+(s.retweets?"&include_rts=1":"")+"&page="+s.page+"&callback=?";var query=s.query||"from:"+s.username.join(" OR from:");return proto+"//"+s.twitter_search_url+"/search.json?&q="+encodeURIComponent(query)+"&rpp="+count+"&page="+s.page+"&callback=?"}function extract_template_data(item){var o={};return o.item=item,o.source=item.source,o.screen_name=item.from_user||item.user.screen_name,o.avatar_size=s.avatar_size,o.avatar_url=maybe_https(item.profile_image_url||item.user.profile_image_url),o.retweet=typeof item.retweeted_status!="undefined",o.tweet_time=parse_date(item.created_at),o.join_text=s.join_text=="auto"?build_auto_join_text(item.text):s.join_text,o.tweet_id=item.id_str,o.twitter_base="http://"+s.twitter_url+"/",o.user_url=o.twitter_base+o.screen_name,o.tweet_url=o.user_url+"/status/"+o.tweet_id,o.reply_url=o.twitter_base+"intent/tweet?in_reply_to="+o.tweet_id,o.retweet_url=o.twitter_base+"intent/retweet?tweet_id="+o.tweet_id,o.favorite_url=o.twitter_base+"intent/favorite?tweet_id="+o.tweet_id,o.retweeted_screen_name=o.retweet&&item.retweeted_status.user.screen_name,o.tweet_relative_time=relative_time(o.tweet_time),o.tweet_raw_text=o.retweet?"RT @"+o.retweeted_screen_name+" "+item.retweeted_status.text:item.text,o.tweet_text=$([o.tweet_raw_text]).linkUrl().linkUser().linkHash()[0],o.tweet_text_fancy=$([o.tweet_text]).makeHeart().capAwesome().capEpic()[0],o.user=t('<a class="tweet_user" href="{user_url}">{screen_name}</a>',o),o.join=s.join_text?t(' <span class="tweet_join">{join_text}</span> ',o):" ",o.avatar=o.avatar_size?t('<a class="tweet_avatar" href="{user_url}"><img src="{avatar_url}" height="{avatar_size}" width="{avatar_size}" alt="{screen_name}\'s avatar" title="{screen_name}\'s avatar" border="0"/></a>',o):"",o.time=t('<span class="tweet_time"><a href="{tweet_url}" title="view tweet on twitter">{tweet_relative_time}</a></span>',o),o.text=t('<span class="tweet_text">{tweet_text_fancy}</span>',o),o.reply_action=t('<a class="tweet_action tweet_reply" href="{reply_url}">reply</a>',o),o.retweet_action=t('<a class="tweet_action tweet_retweet" href="{retweet_url}">retweet</a>',o),o.favorite_action=t('<a class="tweet_action tweet_favorite" href="{favorite_url}">favorite</a>',o),o}return this.each(function(i,widget){var list=$('<ul class="tweet_list">').appendTo(widget),intro='<p class="tweet_intro">'+s.intro_text+"</p>",outro='<p class="tweet_outro">'+s.outro_text+"</p>",loading=$('<p class="loading">'+s.loading_text+"</p>");s.username&&typeof s.username=="string"&&(s.username=[s.username]),s.loading_text&&$(widget).append(loading),$(widget).bind("tweet:load",function(){$.getJSON(build_api_url(),function(data){s.loading_text&&loading.remove(),s.intro_text&&list.before(intro),list.empty();var tweets=$.map(data.results||data,extract_template_data);tweets=$.grep(tweets,s.filter).sort(s.comparator).slice
(0,s.count),list.append($.map(tweets,function(o){return"<li>"+t(s.template,o)+"</li>"}).join("")).children("li:first").addClass("tweet_first").end().children("li:odd").addClass("tweet_even").end().children("li:even").addClass("tweet_odd"),s.outro_text&&list.after(outro),$(widget).trigger("loaded").trigger(tweets.length===0?"empty":"full"),s.refresh_interval&&window.setTimeout(function(){$(widget).trigger("tweet:load")},1e3*s.refresh_interval)})}).trigger("tweet:load")})}}(jQuery)
