var Spry;
if(!Spry){
Spry={};
}
if(!Spry.Widget){
Spry.Widget={};
}
Spry.Widget.TabbedPanels=function(_1,_2){
this.element=this.getElement(_1);
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,_2);
if(typeof (this.defaultTab)=="number"){
if(this.defaultTab<0){
this.defaultTab=0;
}else{
var _3=this.getTabbedPanelCount();
if(this.defaultTab>=_3){
this.defaultTab=(_3>1)?(_3-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(_4){
if(_4&&typeof _4=="string"){
return document.getElementById(_4);
}
return _4;
};
Spry.Widget.TabbedPanels.prototype.getElementChildren=function(_5){
var _6=[];
var _7=_5.firstChild;
while(_7){
if(_7.nodeType==1){
_6.push(_7);
}
_7=_7.nextSibling;
}
return _6;
};
Spry.Widget.TabbedPanels.prototype.addClassName=function(_8,_9){
if(!_8||!_9||(_8.className&&_8.className.search(new RegExp("\\b"+_9+"\\b"))!=-1)){
return;
}
_8.className+=(_8.className?" ":"")+_9;
};
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(_c,_d,_e){
if(!_d){
return;
}
for(var _f in _d){
if(_e&&_d[_f]==undefined){
continue;
}
_c[_f]=_d[_f];
}
};
Spry.Widget.TabbedPanels.prototype.getTabGroup=function(){
if(this.element){
var _10=this.getElementChildren(this.element);
if(_10.length){
return _10[0];
}
}
return null;
};
Spry.Widget.TabbedPanels.prototype.getTabs=function(){
var _11=[];
var tg=this.getTabGroup();
if(tg){
_11=this.getElementChildren(tg);
}
return _11;
};
Spry.Widget.TabbedPanels.prototype.getContentPanelGroup=function(){
if(this.element){
var _13=this.getElementChildren(this.element);
if(_13.length>1){
return _13[1];
}
}
return null;
};
Spry.Widget.TabbedPanels.prototype.getContentPanels=function(){
var _14=[];
var pg=this.getContentPanelGroup();
if(pg){
_14=this.getElementChildren(pg);
}
return _14;
};
Spry.Widget.TabbedPanels.prototype.getIndex=function(ele,arr){
ele=this.getElement(ele);
if(ele&&arr&&arr.length){
for(var i=0;i<arr.length;i++){
if(ele==arr[i]){
return i;
}
}
}
return -1;
};
Spry.Widget.TabbedPanels.prototype.getTabIndex=function(ele){
var i=this.getIndex(ele,this.getTabs());
if(i<0){
i=this.getIndex(ele,this.getContentPanels());
}
return i;
};
Spry.Widget.TabbedPanels.prototype.getCurrentTabIndex=function(){
return this.currentTabIndex;
};
Spry.Widget.TabbedPanels.prototype.getTabbedPanelCount=function(ele){
return Math.min(this.getTabs().length,this.getContentPanels().length);
};
Spry.Widget.TabbedPanels.addEventListener=function(_1c,_1d,_1e,_1f){
try{
if(_1c.addEventListener){
_1c.addEventListener(_1d,_1e,_1f);
}else{
if(_1c.attachEvent){
_1c.attachEvent("on"+_1d,_1e);
}
}
}
catch(e){
}
};
Spry.Widget.TabbedPanels.prototype.onTabClick=function(e,tab){
this.showPanel(tab);
};
Spry.Widget.TabbedPanels.prototype.onTabMouseOver=function(e,tab){
this.addClassName(tab,this.tabHoverClass);
};
Spry.Widget.TabbedPanels.prototype.onTabMouseOut=function(e,tab){
this.removeClassName(tab,this.tabHoverClass);
};
Spry.Widget.TabbedPanels.prototype.onTabFocus=function(e,tab){
this.hasFocus=true;
this.addClassName(this.element,this.tabFocusedClass);
};
Spry.Widget.TabbedPanels.prototype.onTabBlur=function(e,tab){
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(e,tab){
var key=e.keyCode;
if(!this.hasFocus||(key!=Spry.Widget.TabbedPanels.ENTER_KEY&&key!=Spry.Widget.TabbedPanels.SPACE_KEY)){
return true;
}
this.showPanel(tab);
if(e.stopPropagation){
e.stopPropagation();
}
if(e.preventDefault){
e.preventDefault();
}
return false;
};
Spry.Widget.TabbedPanels.prototype.preorderTraversal=function(_2d,_2e){
var _2f=false;
if(_2d){
_2f=_2e(_2d);
if(_2d.hasChildNodes()){
var _30=_2d.firstChild;
while(!_2f&&_30){
_2f=this.preorderTraversal(_30,_2e);
try{
_30=_30.nextSibling;
}
catch(e){
_30=null;
}
}
}
}
return _2f;
};
Spry.Widget.TabbedPanels.prototype.addPanelEventListeners=function(tab,_32){
var _33=this;
Spry.Widget.TabbedPanels.addEventListener(tab,"click",function(e){
return _33.onTabClick(e,tab);
},false);
Spry.Widget.TabbedPanels.addEventListener(tab,"mouseover",function(e){
return _33.onTabMouseOver(e,tab);
},false);
Spry.Widget.TabbedPanels.addEventListener(tab,"mouseout",function(e){
return _33.onTabMouseOut(e,tab);
},false);
if(this.enableKeyboardNavigation){
var _37=null;
var _38=null;
this.preorderTraversal(tab,function(_39){
if(_39.nodeType==1){
var _3a=tab.attributes.getNamedItem("tabindex");
if(_3a){
_37=_39;
return true;
}
if(!_38&&_39.nodeName.toLowerCase()=="a"){
_38=_39;
}
}
return false;
});
if(_37){
this.focusElement=_37;
}else{
if(_38){
this.focusElement=_38;
}
}
if(this.focusElement){
Spry.Widget.TabbedPanels.addEventListener(this.focusElement,"focus",function(e){
return _33.onTabFocus(e,tab);
},false);
Spry.Widget.TabbedPanels.addEventListener(this.focusElement,"blur",function(e){
return _33.onTabBlur(e,tab);
},false);
Spry.Widget.TabbedPanels.addEventListener(this.focusElement,"keydown",function(e){
return _33.onTabKeyDown(e,tab);
},false);
}
}
};
Spry.Widget.TabbedPanels.prototype.showPanel=function(_3e){
var _3f=-1;
if(typeof _3e=="number"){
_3f=_3e;
}else{
_3f=this.getTabIndex(_3e);
}
if(!_3f<0||_3f>=this.getTabbedPanelCount()){
return;
}
var _40=this.getTabs();
var _41=this.getContentPanels();
var _42=Math.max(_40.length,_41.length);
for(var i=0;i<_42;i++){
if(i!=_3f){
if(_40[i]){
this.removeClassName(_40[i],this.tabSelectedClass);
}
if(_41[i]){
this.removeClassName(_41[i],this.panelVisibleClass);
_41[i].style.display="none";
}
}
}
this.addClassName(_40[_3f],this.tabSelectedClass);
this.addClassName(_41[_3f],this.panelVisibleClass);
_41[_3f].style.display="block";
this.currentTabIndex=_3f;
};
Spry.Widget.TabbedPanels.prototype.attachBehaviors=function(_44){
var _45=this.getTabs();
var _46=this.getContentPanels();
var _47=this.getTabbedPanelCount();
for(var i=0;i<_47;i++){
this.addPanelEventListeners(_45[i],_46[i]);
}
this.showPanel(this.defaultTab);
};

