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