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