var Spry;
if(!Spry){
Spry={};
}
if(!Spry.Widget){
Spry.Widget={};
}
Spry.Widget.CollapsiblePanel=function(_1,_2){
this.init(_1);
Spry.Widget.CollapsiblePanel.setOptions(this,_2);
this.attachBehaviors();
};
Spry.Widget.CollapsiblePanel.prototype.init=function(_3){
this.element=this.getElement(_3);
this.focusElement=null;
this.hoverClass="CollapsiblePanelTabHover";
this.openClass="CollapsiblePanelOpen";
this.closedClass="CollapsiblePanelClosed";
this.focusedClass="CollapsiblePanelFocused";
this.enableAnimation=true;
this.enableKeyboardNavigation=true;
this.animator=null;
this.hasFocus=false;
this.contentIsOpen=true;
};
Spry.Widget.CollapsiblePanel.prototype.getElement=function(_4){
if(_4&&typeof _4=="string"){
return document.getElementById(_4);
}
return _4;
};
Spry.Widget.CollapsiblePanel.prototype.addClassName=function(_5,_6){
if(!_5||!_6||(_5.className&&_5.className.search(new RegExp("\\b"+_6+"\\b"))!=-1)){
return;
}
_5.className+=(_5.className?" ":"")+_6;
};
Spry.Widget.CollapsiblePanel.prototype.removeClassName=function(_7,_8){
if(!_7||!_8||(_7.className&&_7.className.search(new RegExp("\\b"+_8+"\\b"))==-1)){
return;
}
_7.className=_7.className.replace(new RegExp("\\s*\\b"+_8+"\\b","g"),"");
};
Spry.Widget.CollapsiblePanel.prototype.hasClassName=function(_9,_a){
if(!_9||!_a||!_9.className||_9.className.search(new RegExp("\\b"+_a+"\\b"))==-1){
return false;
}
return true;
};
Spry.Widget.CollapsiblePanel.prototype.setDisplay=function(_b,_c){
if(_b){
_b.style.display=_c;
}
};
Spry.Widget.CollapsiblePanel.setOptions=function(_d,_e,_f){
if(!_e){
return;
}
for(var _10 in _e){
if(_f&&_e[_10]==undefined){
continue;
}
_d[_10]=_e[_10];
}
};
Spry.Widget.CollapsiblePanel.prototype.onTabMouseOver=function(){
this.addClassName(this.getTab(),this.hoverClass);
};
Spry.Widget.CollapsiblePanel.prototype.onTabMouseOut=function(){
this.removeClassName(this.getTab(),this.hoverClass);
};
Spry.Widget.CollapsiblePanel.prototype.open=function(){
this.contentIsOpen=true;
if(this.enableAnimation){
if(this.animator){
this.animator.stop();
}
this.animator=new Spry.Widget.CollapsiblePanel.PanelAnimator(this,true);
this.animator.start();
}else{
this.setDisplay(this.getContent(),"block");
}
this.removeClassName(this.element,this.closedClass);
this.addClassName(this.element,this.openClass);
};
Spry.Widget.CollapsiblePanel.prototype.close=function(){
this.contentIsOpen=false;
if(this.enableAnimation){
if(this.animator){
this.animator.stop();
}
this.animator=new Spry.Widget.CollapsiblePanel.PanelAnimator(this,false);
this.animator.start();
}else{
this.setDisplay(this.getContent(),"none");
}
this.removeClassName(this.element,this.openClass);
this.addClassName(this.element,this.closedClass);
};
Spry.Widget.CollapsiblePanel.prototype.onTabClick=function(){
if(this.isOpen()){
this.close();
}else{
this.open();
}
this.focus();
};
Spry.Widget.CollapsiblePanel.prototype.onFocus=function(e){
this.hasFocus=true;
this.addClassName(this.element,this.focusedClass);
};
Spry.Widget.CollapsiblePanel.prototype.onBlur=function(e){
this.hasFocus=false;
this.removeClassName(this.element,this.focusedClass);
};
Spry.Widget.CollapsiblePanel.ENTER_KEY=13;
Spry.Widget.CollapsiblePanel.SPACE_KEY=32;
Spry.Widget.CollapsiblePanel.prototype.onKeyDown=function(e){
var key=e.keyCode;
if(!this.hasFocus||(key!=Spry.Widget.CollapsiblePanel.ENTER_KEY&&key!=Spry.Widget.CollapsiblePanel.SPACE_KEY)){
return true;
}
if(this.isOpen()){
this.close();
}else{
this.open();
}
if(e.stopPropagation){
e.stopPropagation();
}
if(e.preventDefault){
e.preventDefault();
}
return false;
};
Spry.Widget.CollapsiblePanel.prototype.attachPanelHandlers=function(){
var tab=this.getTab();
if(!tab){
return;
}
var _11=this;
Spry.Widget.CollapsiblePanel.addEventListener(tab,"click",function(e){
return _11.onTabClick();
},false);
Spry.Widget.CollapsiblePanel.addEventListener(tab,"mouseover",function(e){
return _11.onTabMouseOver();
},false);
Spry.Widget.CollapsiblePanel.addEventListener(tab,"mouseout",function(e){
return _11.onTabMouseOut();
},false);
if(this.enableKeyboardNavigation){
var _12=null;
var _13=null;
this.preorderTraversal(tab,function(_14){
if(_14.nodeType==1){
var _15=tab.attributes.getNamedItem("tabindex");
if(_15){
_12=_14;
return true;
}
if(!_13&&_14.nodeName.toLowerCase()=="a"){
_13=_14;
}
}
return false;
});
if(_12){
this.focusElement=_12;
}else{
if(_13){
this.focusElement=_13;
}
}
if(this.focusElement){
Spry.Widget.CollapsiblePanel.addEventListener(this.focusElement,"focus",function(e){
return _11.onFocus(e);
},false);
Spry.Widget.CollapsiblePanel.addEventListener(this.focusElement,"blur",function(e){
return _11.onBlur(e);
},false);
Spry.Widget.CollapsiblePanel.addEventListener(this.focusElement,"keydown",function(e){
return _11.onKeyDown(e);
},false);
}
}
};
Spry.Widget.CollapsiblePanel.addEventListener=function(_16,_17,_18,_19){
try{
if(_16.addEventListener){
_16.addEventListener(_17,_18,_19);
}else{
if(_16.attachEvent){
_16.attachEvent("on"+_17,_18);
}
}
}
catch(e){
}
};
Spry.Widget.CollapsiblePanel.prototype.preorderTraversal=function(_1a,_1b){
var _1c=false;
if(_1a){
_1c=_1b(_1a);
if(_1a.hasChildNodes()){
var _1d=_1a.firstChild;
while(!_1c&&_1d){
_1c=this.preorderTraversal(_1d,_1b);
try{
_1d=_1d.nextSibling;
}
catch(e){
_1d=null;
}
}
}
}
return _1c;
};
Spry.Widget.CollapsiblePanel.prototype.attachBehaviors=function(){
var _1e=this.element;
var tab=this.getTab();
var _1f=this.getContent();
if(this.contentIsOpen||this.hasClassName(_1e,this.openClass)){
this.removeClassName(_1e,this.closedClass);
this.setDisplay(_1f,"block");
this.contentIsOpen=true;
}else{
this.removeClassName(_1e,this.openClass);
this.addClassName(_1e,this.closedClass);
this.setDisplay(_1f,"none");
this.contentIsOpen=false;
}
this.attachPanelHandlers();
};
Spry.Widget.CollapsiblePanel.prototype.getTab=function(){
return this.getElementChildren(this.element)[0];
};
Spry.Widget.CollapsiblePanel.prototype.getContent=function(){
return this.getElementChildren(this.element)[1];
};
Spry.Widget.CollapsiblePanel.prototype.isOpen=function(){
return this.contentIsOpen;
};
Spry.Widget.CollapsiblePanel.prototype.getElementChildren=function(_20){
var _21=[];
var _22=_20.firstChild;
while(_22){
if(_22.nodeType==1){
_21.push(_22);
}
_22=_22.nextSibling;
}
return _21;
};
Spry.Widget.CollapsiblePanel.prototype.focus=function(){
if(this.focusElement&&this.focusElement.focus){
this.focusElement.focus();
}
};
Spry.Widget.CollapsiblePanel.PanelAnimator=function(_23,_24,_25){
this.timer=null;
this.interval=0;
this.stepCount=0;
this.fps=0;
this.steps=10;
this.duration=500;
this.onComplete=null;
this.panel=_23;
this.content=_23.getContent();
this.panelData=[];
this.doOpen=_24;
Spry.Widget.CollapsiblePanel.setOptions(this,_25);
if(this.fps>0){
this.interval=Math.floor(1000/this.fps);
this.steps=parseInt((this.duration+(this.interval-1))/this.interval);
}else{
if(this.steps>0){
this.interval=this.duration/this.steps;
}
}
var c=this.content;
var _26=c.offsetHeight?c.offsetHeight:0;
if(_24&&c.style.display=="none"){
this.fromHeight=0;
}else{
this.fromHeight=_26;
}
if(!_24){
this.toHeight=0;
}else{
if(c.style.display=="none"){
c.style.visibility="hidden";
c.style.display="block";
}
c.style.height="";
this.toHeight=c.offsetHeight;
}
this.increment=(this.toHeight-this.fromHeight)/this.steps;
this.overflow=c.style.overflow;
c.style.height=this.fromHeight+"px";
c.style.visibility="visible";
c.style.overflow="hidden";
c.style.display="block";
};
Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.start=function(){
var _27=this;
this.timer=setTimeout(function(){
_27.stepAnimation();
},this.interval);
};
Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.stop=function(){
if(this.timer){
clearTimeout(this.timer);
if(this.stepCount<this.steps){
this.content.style.overflow=this.overflow;
}
}
this.timer=null;
};
Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.stepAnimation=function(){
++this.stepCount;
this.animate();
if(this.stepCount<this.steps){
this.start();
}else{
if(this.onComplete){
this.onComplete();
}
}
};
Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.animate=function(){
if(this.stepCount>=this.steps){
if(!this.doOpen){
this.content.style.display="none";
}
this.content.style.overflow=this.overflow;
this.content.style.height=this.toHeight+"px";
}else{
this.fromHeight+=this.increment;
this.content.style.height=this.fromHeight+"px";
}
};


