var Spry;if(!Spry){Spry={}}if(!Spry.Widget){Spry.Widget={}}Spry.Widget.TabbedPanels=function(F,D){this.element=this.getElement(F);this.defaultTab=0;this.bindings=[];this.tabSelectedClass="TabbedPanelsTabSelected";this.tabHoverClass="TabbedPanelsTabHover";this.tabFocusedClass="TabbedPanelsTabFocused";this.panelVisibleClass="TabbedPanelsContentVisible";this.focusElement=null;this.hasFocus=false;this.currentTabIndex=0;this.enableKeyboardNavigation=true;Spry.Widget.TabbedPanels.setOptions(this,D);if(typeof (this.defaultTab)=="number"){if(this.defaultTab<0){this.defaultTab=0}else{var E=this.getTabbedPanelCount();if(this.defaultTab>=E){this.defaultTab=(E>1)?(E-1):0}}this.defaultTab=this.getTabs()[this.defaultTab]}if(this.defaultTab){this.defaultTab=this.getElement(this.defaultTab)}this.attachBehaviors()};Spry.Widget.TabbedPanels.prototype.getElement=function(B){if(B&&typeof B=="string"){return document.getElementById(B)}return B};Spry.Widget.TabbedPanels.prototype.getElementChildren=function(E){var F=[];var D=E.firstChild;while(D){if(D.nodeType==1){F.push(D)}D=D.nextSibling}return F};Spry.Widget.TabbedPanels.prototype.addClassName=function(C,D){if(!C||!D||(C.className&&C.className.search(new RegExp("\\b"+D+"\\b"))!=-1)){return }C.className+=(C.className?" ":"")+D};Spry.Widget.TabbedPanels.prototype.removeClassName=function(C,D){if(!C||!D||(C.className&&C.className.search(new RegExp("\\b"+D+"\\b"))==-1)){return }C.className=C.className.replace(new RegExp("\\s*\\b"+D+"\\b","g"),"")};Spry.Widget.TabbedPanels.setOptions=function(G,H,F){if(!H){return }for(var E in H){if(F&&H[E]==undefined){continue}G[E]=H[E]}};Spry.Widget.TabbedPanels.prototype.getTabGroup=function(){if(this.element){var B=this.getElementChildren(this.element);if(B.length){return B[0]}}return null};Spry.Widget.TabbedPanels.prototype.getTabs=function(){var D=[];var C=this.getTabGroup();if(C){D=this.getElementChildren(C)}return D};Spry.Widget.TabbedPanels.prototype.getContentPanelGroup=function(){if(this.element){var B=this.getElementChildren(this.element);if(B.length>1){return B[1]}}return null};Spry.Widget.TabbedPanels.prototype.getContentPanels=function(){var D=[];var C=this.getContentPanelGroup();if(C){D=this.getElementChildren(C)}return D};Spry.Widget.TabbedPanels.prototype.getIndex=function(D,F){D=this.getElement(D);if(D&&F&&F.length){for(var E=0;E<F.length;E++){if(D==F[E]){return E}}}return -1};Spry.Widget.TabbedPanels.prototype.getTabIndex=function(C){var D=this.getIndex(C,this.getTabs());if(D<0){D=this.getIndex(C,this.getContentPanels())}return D};Spry.Widget.TabbedPanels.prototype.getCurrentTabIndex=function(){return this.currentTabIndex};Spry.Widget.TabbedPanels.prototype.getTabbedPanelCount=function(B){return Math.min(this.getTabs().length,this.getContentPanels().length)};Spry.Widget.TabbedPanels.addEventListener=function(F,G,J,H){try{if(F.addEventListener){F.addEventListener(G,J,H)}else{if(F.attachEvent){F.attachEvent("on"+G,J)}}}catch(I){}};Spry.Widget.TabbedPanels.prototype.onTabClick=function(C,D){this.showPanel(D)};Spry.Widget.TabbedPanels.prototype.onTabMouseOver=function(C,D){this.addClassName(D,this.tabHoverClass)};Spry.Widget.TabbedPanels.prototype.onTabMouseOut=function(C,D){this.removeClassName(D,this.tabHoverClass)};Spry.Widget.TabbedPanels.prototype.onTabFocus=function(C,D){this.hasFocus=true;this.addClassName(this.element,this.tabFocusedClass)};Spry.Widget.TabbedPanels.prototype.onTabBlur=function(C,D){this.hasFocus=false;this.removeClassName(this.element,this.tabFocusedClass)};Spry.Widget.TabbedPanels.ENTER_KEY=13;Spry.Widget.TabbedPanels.SPACE_KEY=32;Spry.Widget.TabbedPanels.prototype.onTabKeyDown=function(D,E){var F=D.keyCode;if(!this.hasFocus||(F!=Spry.Widget.TabbedPanels.ENTER_KEY&&F!=Spry.Widget.TabbedPanels.SPACE_KEY)){return true}this.showPanel(E);if(D.stopPropagation){D.stopPropagation()}if(D.preventDefault){D.preventDefault()}return false};Spry.Widget.TabbedPanels.prototype.preorderTraversal=function(H,G){var J=false;if(H){J=G(H);if(H.hasChildNodes()){var I=H.firstChild;while(!J&&I){J=this.preorderTraversal(I,G);try{I=I.nextSibling}catch(F){I=null}}}}return J};Spry.Widget.TabbedPanels.prototype.addPanelEventListeners=function(J,G){var F=this;Spry.Widget.TabbedPanels.addEventListener(J,"click",function(A){return F.onTabClick(A,J)},false);Spry.Widget.TabbedPanels.addEventListener(J,"mouseover",function(A){return F.onTabMouseOver(A,J)},false);Spry.Widget.TabbedPanels.addEventListener(J,"mouseout",function(A){return F.onTabMouseOut(A,J)},false);if(this.enableKeyboardNavigation){var I=null;var H=null;this.preorderTraversal(J,function(A){if(A.nodeType==1){var B=J.attributes.getNamedItem("tabindex");if(B){I=A;return true}if(!H&&A.nodeName.toLowerCase()=="a"){H=A}}return false});if(I){this.focusElement=I}else{if(H){this.focusElement=H}}if(this.focusElement){Spry.Widget.TabbedPanels.addEventListener(this.focusElement,"focus",function(A){return F.onTabFocus(A,J)},false);Spry.Widget.TabbedPanels.addEventListener(this.focusElement,"blur",function(A){return F.onTabBlur(A,J)},false);Spry.Widget.TabbedPanels.addEventListener(this.focusElement,"keydown",function(A){return F.onTabKeyDown(A,J)},false)}}};Spry.Widget.TabbedPanels.prototype.showPanel=function(K){var G=-1;if(typeof K=="number"){G=K}else{G=this.getTabIndex(K)}if(!G<0||G>=this.getTabbedPanelCount()){return }var H=this.getTabs();var J=this.getContentPanels();var L=Math.max(H.length,J.length);for(var I=0;I<L;I++){if(I!=G){if(H[I]){this.removeClassName(H[I],this.tabSelectedClass)}if(J[I]){this.removeClassName(J[I],this.panelVisibleClass);J[I].style.display="none"}}}this.addClassName(H[G],this.tabSelectedClass);this.addClassName(J[G],this.panelVisibleClass);J[G].style.display="block";this.currentTabIndex=G};Spry.Widget.TabbedPanels.prototype.attachBehaviors=function(J){var F=this.getTabs();var H=this.getContentPanels();var I=this.getTabbedPanelCount();for(var G=0;G<I;G++){this.addPanelEventListeners(F[G],H[G])}this.showPanel(this.defaultTab)};