(function(J){J.a11y=J.a11y||{};J.a11y.keys={UP:38,DOWN:40,LEFT:37,RIGHT:39,SPACE:32,ENTER:13,TAB:9,CTRL:17,SHIFT:16,ALT:18};J.a11y.orientation={HORIZONTAL:0,VERTICAL:1,BOTH:2};var T="keyboard-a11y";var N="selectionContext";var P="userHandlers";var c="defaultActivate";var U={next:J.a11y.keys.DOWN,previous:J.a11y.keys.UP};var B={next:J.a11y.keys.RIGHT,previous:J.a11y.keys.LEFT};var Z=function(e){return(e.jquery)?e[0]:e};var O=function(f,e,g){if(f.willLeaveContainer){f.willLeaveContainer(e.activeItem)}else{if(f.willUnselect){f.willUnselect(e.activeItem)}}if(!g){e.activeItem=null}};var A=function(j,f){if(!j.modifier){return true}var g=j.modifier;var h=(g&&f.ctrlKey);var e=(g&&f.altKey);var i=(g&&f.shiftKey);return(h||e||i)};var F=function(e){return function(f){if(f.which===e.key&&e.activateHandler&&A(e,f)){e.activateHandler(f.target,f);f.preventDefault()}}};var M=function(e,f){if(f){f(e)}};var W=function(f,e){if(e){e(f)}};var E=function(g,e,f){W(g,f.willUnselect)};var X=function(e,f,g){if(f.activeItem){E(f.activeItem,f,g)}e=Z(e);if(f.selectables.index(e)===-1){return }f.activeItem=e;M(e,g.willSelect)};var d=function(e,f){return function(g){X(g.target,e,f);return g.stopPropagation()}};var G=function(e,f){return function(g){E(g.target,e,f);return g.stopPropagation()}};var a=function(f){var g=f.selectables;var i=f.activeItem;var h=(!i)?-1:g.index(i);var e=h+1;e=(e>=g.length)?e=0:e;g.eq(e).focus()};var L=function(e){var f=e.selectables;var i=e.activeItem;var h=(!i)?0:f.index(i);var g=h-1;g=(g<0)?f.length-1:g;f.eq(g).focus()};var I=function(e,g,f){return function(h){if(h.which===g.next){a(e);h.preventDefault()}else{if(h.which===g.previous){L(e);h.preventDefault()}}}};var S=function(e){var f;if(e===J.a11y.orientation.HORIZONTAL){f=B}else{f=U}return f};var Q=function(f,e,g){return function(h){var i=(g.constructor===Function)?g():g;if(f.focusIsLeavingContainer){i=false}if(i&&h.target===e.get(0)){if(!f.activeItem){a(f)}else{jQuery(f.activeItem).focus()}}return h.stopPropagation()}};var Y=function(e){return function(f){e.focusIsLeavingContainer=false;return f.stopPropagation()}};var V=function(e){e.each(function(f,g){g=J(g);if(!g.hasTabindex()||(g.tabindex()<0)){g.tabindex(0)}})};var b=function(h,l,e,f){var k=[];J(e).each(function(i,m){k.push({modifier:null,key:m,activateHandler:l})});if(f&&f.additionalBindings){k=k.concat(f.additionalBindings)}for(var g=0;g<k.length;g=g+1){var j=k[g];h.keydown(F(j))}};var C=function(f,e,g){return function(h){if(h.which!==J.a11y.keys.TAB){return }O(f,e,g);if(h.shiftKey){e.focusIsLeavingContainer=true}}};var D=function(g,e,h,j,i){h=h||{};var l=J.extend({},j,i);var k=S(l.direction);var f={activeItem:undefined,selectables:e,focusIsLeavingContainer:false};g.keydown(I(f,k,h));g.keydown(C(h,f,l.rememberSelectionState));g.focus(Q(f,g,l.shouldSelectOnFocus));g.blur(Y(f));e.tabindex(-1);e.focus(d(f,h));e.blur(G(f,h));return f};var K=function(f,e){return function(g){if(!e){return }g=Z(g);if(f.index(g)===-1){return }e(g)}};var R=function(f,e){var g=f.data(T);return g?g[e]:undefined};var H=function(f,e,h){var g=f.data(T)||{};g[e]=h;f.data(T,g)};J.fn.tabbable=function(){V(this);return this};J.fn.selectable=function(f,g,h){var e=D(J(f),this,g,this.selectable.defaults,h);H(this,N,e);H(this,P,g);return this};J.fn.activatable=function(f,e){b(this,f,this.activatable.defaults.keys,e);H(this,c,K(this,f));return this};J.fn.select=function(e){e.focus();return this};J.fn.selectNext=function(){a(R(this,N));return this};J.fn.selectPrevious=function(){L(R(this,N));return this};J.fn.currentSelection=function(){return J(R(this,N).activeItem)};J.fn.activate=function(f){var e=R(this,c);e(f);return this};J.fn.activatable.defaults={keys:[J.a11y.keys.ENTER,J.a11y.keys.SPACE]};J.fn.selectable.defaults={direction:this.VERTICAL,shouldSelectOnFocus:true,rememberSelectionState:true}})(jQuery);