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 _12=this.getElementChildren(this.element);
if(_12.length>1){
return _12[1];
}
}
return null;
};
Spry.Widget.TabbedPanels.prototype.getContentPanels=function(){
var _13=[];
var pg=this.getContentPanelGroup();
if(pg){
_13=this.getElementChildren(pg);
}
return _13;
};
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(_14,_15,_16,_17){
try{
if(_14.addEventListener){
_14.addEventListener(_15,_16,_17);
}else{
if(_14.attachEvent){
_14.attachEvent("on"+_15,_16);
}
}
}
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(_18,_19){
var _1a=false;
if(_18){
_1a=_19(_18);
if(_18.hasChildNodes()){
var _1b=_18.firstChild;
while(!_1a&&_1b){
_1a=this.preorderTraversal(_1b,_19);
try{
_1b=_1b.nextSibling;
}
catch(e){
_1b=null;
}
}
}
}
return _1a;
};
Spry.Widget.TabbedPanels.prototype.addPanelEventListeners=function(tab,_1c){
var _1d=this;
Spry.Widget.TabbedPanels.addEventListener(tab,"click",function(e){
return _1d.onTabClick(e,tab);
},false);
Spry.Widget.TabbedPanels.addEventListener(tab,"mouseover",function(e){
return _1d.onTabMouseOver(e,tab);
},false);
Spry.Widget.TabbedPanels.addEventListener(tab,"mouseout",function(e){
return _1d.onTabMouseOut(e,tab);
},false);
if(this.enableKeyboardNavigation){
var _1e=null;
var _1f=null;
this.preorderTraversal(tab,function(_20){
if(_20.nodeType==1){
var _21=tab.attributes.getNamedItem("tabindex");
if(_21){
_1e=_20;
return true;
}
if(!_1f&&_20.nodeName.toLowerCase()=="a"){
_1f=_20;
}
}
return false;
});
if(_1e){
this.focusElement=_1e;
}else{
if(_1f){
this.focusElement=_1f;
}
}
if(this.focusElement){
Spry.Widget.TabbedPanels.addEventListener(this.focusElement,"focus",function(e){
return _1d.onTabFocus(e,tab);
},false);
Spry.Widget.TabbedPanels.addEventListener(this.focusElement,"blur",function(e){
return _1d.onTabBlur(e,tab);
},false);
Spry.Widget.TabbedPanels.addEventListener(this.focusElement,"keydown",function(e){
return _1d.onTabKeyDown(e,tab);
},false);
}
}
};
Spry.Widget.TabbedPanels.prototype.showPanel=function(_22){
var _23=-1;
if(typeof _22=="number"){
_23=_22;
}else{
_23=this.getTabIndex(_22);
}
if(!_23<0||_23>=this.getTabbedPanelCount()){
return;
}
var _24=this.getTabs();
var _25=this.getContentPanels();
var _26=Math.max(_24.length,_25.length);
for(var i=0;i<_26;i++){
if(i!=_23){
if(_24[i]){
this.removeClassName(_24[i],this.tabSelectedClass);
}
if(_25[i]){
this.removeClassName(_25[i],this.panelVisibleClass);
_25[i].style.display="none";
}
}
}
this.addClassName(_24[_23],this.tabSelectedClass);
this.addClassName(_25[_23],this.panelVisibleClass);
_25[_23].style.display="block";
this.currentTabIndex=_23;
};
Spry.Widget.TabbedPanels.prototype.attachBehaviors=function(_27){
var _28=this.getTabs();
var _29=this.getContentPanels();
var _2a=this.getTabbedPanelCount();
for(var i=0;i<_2a;i++){
this.addPanelEventListeners(_28[i],_29[i]);
}
this.showPanel(this.defaultTab);
};


