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