var a,Spry;Spry||(Spry={});if(!Spry.Widget)Spry.Widget={};Spry.Widget.CollapsiblePanel=function(b,c){this.element=this.getElement(b);this.focusElement=null;this.hoverClass="CollapsiblePanelTabHover";this.openClass="CollapsiblePanelOpen";this.closedClass="CollapsiblePanelClosed";this.focusedClass="CollapsiblePanelFocused";this.enableKeyboardNavigation=this.enableAnimation=true;this.animator=null;this.hasFocus=false;this.contentIsOpen=true;this.openPanelKeyCode=Spry.Widget.CollapsiblePanel.KEY_DOWN;this.closePanelKeyCode=Spry.Widget.CollapsiblePanel.KEY_UP;Spry.Widget.CollapsiblePanel.setOptions(this,c);this.attachBehaviors()};a=Spry.Widget.CollapsiblePanel.prototype;a.getElement=function(b){if(b&&typeof b=="string")return document.getElementById(b);return b};a.addClassName=function(b,c){!b||!c||b.className&&b.className.search(new RegExp("\\b"+c+"\\b"))!=-1||(b.className+=(b.className?" ":"")+c)};a.removeClassName=function(b,c){if(!(!b||!c||b.className&&b.className.search(new RegExp("\\b"+c+"\\b"))==-1))b.className=b.className.replace(new RegExp("\\s*\\b"+c+"\\b","g"),"")};a.hasClassName=function(b,c){if(!b||!c||!b.className||b.className.search(new RegExp("\\b"+c+"\\b"))==-1)return false;return true};a.setDisplay=function(b,c){if(b)b.style.display=c};Spry.Widget.CollapsiblePanel.setOptions=function(b,c,d){if(c)for(var e in c)d&&c[e]==undefined||(b[e]=c[e])};a=Spry.Widget.CollapsiblePanel.prototype;a.onTabMouseOver=function(b){this.addClassName(this.getTab(),this.hoverClass);return false};a.onTabMouseOut=function(b){this.removeClassName(this.getTab(),this.hoverClass);return false};a.open=function(){this.contentIsOpen=true;if(this.enableAnimation){this.animator&&this.animator.stop();this.animator=new Spry.Widget.CollapsiblePanel.PanelAnimator(this,true,{duration:this.duration,fps:this.fps,transition:this.transition});this.animator.start()}else this.setDisplay(this.getContent(),"block");this.removeClassName(this.element,this.closedClass);this.addClassName(this.element,this.openClass)};a.close=function(){this.contentIsOpen=false;if(this.enableAnimation){this.animator&&this.animator.stop();this.animator=new Spry.Widget.CollapsiblePanel.PanelAnimator(this,false,{duration:this.duration,fps:this.fps,transition:this.transition});this.animator.start()}else this.setDisplay(this.getContent(),"none");this.removeClassName(this.element,this.openClass);this.addClassName(this.element,this.closedClass)};a.onTabClick=function(b){this.isOpen()?this.close():this.open();this.focus();return this.stopPropagation(b)};a.onFocus=function(b){this.hasFocus=true;this.addClassName(this.element,this.focusedClass);return false};a.onBlur=function(b){this.hasFocus=false;this.removeClassName(this.element,this.focusedClass);return false};Spry.Widget.CollapsiblePanel.KEY_UP=38;Spry.Widget.CollapsiblePanel.KEY_DOWN=40;Spry.Widget.CollapsiblePanel.prototype.onKeyDown=function(b){var c=b.keyCode;if(!this.hasFocus||c!=this.openPanelKeyCode&&c!=this.closePanelKeyCode)return true;if(this.isOpen()&&c==this.closePanelKeyCode)this.close();else c==this.openPanelKeyCode&&this.open();return this.stopPropagation(b)};Spry.Widget.CollapsiblePanel.prototype.stopPropagation=function(b){if(b.preventDefault)b.preventDefault();else b.returnValue=false;if(b.stopPropagation)b.stopPropagation();else b.cancelBubble=true;return false};Spry.Widget.CollapsiblePanel.prototype.attachPanelHandlers=function(){var b=this.getTab();if(b){var c=this;Spry.Widget.CollapsiblePanel.addEventListener(b,"click",function(f){return c.onTabClick(f)},false);Spry.Widget.CollapsiblePanel.addEventListener(b,"mouseover",function(f){return c.onTabMouseOver(f)},false);Spry.Widget.CollapsiblePanel.addEventListener(b,"mouseout",function(f){return c.onTabMouseOut(f)},false);if(this.enableKeyboardNavigation){var d=null,e=null;this.preorderTraversal(b,function(f){if(f.nodeType==1){var g=b.attributes.getNamedItem("tabindex");if(g){d=f;return true}if(!e&&f.nodeName.toLowerCase()=="a")e=f}return false});if(d)this.focusElement=d;else if(e)this.focusElement=e;if(this.focusElement){Spry.Widget.CollapsiblePanel.addEventListener(this.focusElement,"focus",function(f){return c.onFocus(f)},false);Spry.Widget.CollapsiblePanel.addEventListener(this.focusElement,"blur",function(f){return c.onBlur(f)},false);Spry.Widget.CollapsiblePanel.addEventListener(this.focusElement,"keydown",function(f){return c.onKeyDown(f)},false)}}}};Spry.Widget.CollapsiblePanel.addEventListener=function(b,c,d,e){try{if(b.addEventListener)b.addEventListener(c,d,e);else b.attachEvent&&b.attachEvent("on"+c,d)}catch(f){}};a=Spry.Widget.CollapsiblePanel.prototype;a.preorderTraversal=function(b,c){var d=false;if(b){d=c(b);if(b.hasChildNodes())for(b=b.firstChild;!d&&b;){d=this.preorderTraversal(b,c);try{b=b.nextSibling}catch(e){b=null}}}return d};a.attachBehaviors=function(){var b=this.element,c=this.getTab();c=this.getContent();if(this.contentIsOpen||this.hasClassName(b,this.openClass)){this.addClassName(b,this.openClass);this.removeClassName(b,this.closedClass);this.setDisplay(c,"block");this.contentIsOpen=true}else{this.removeClassName(b,this.openClass);this.addClassName(b,this.closedClass);this.setDisplay(c,"none");this.contentIsOpen=false}this.attachPanelHandlers()};a.getTab=function(){return this.getElementChildren(this.element)[0]};a.getContent=function(){return this.getElementChildren(this.element)[1]};a.isOpen=function(){return this.contentIsOpen};a.getElementChildren=function(b){var c=[];for(b=b.firstChild;b;){b.nodeType==1&&c.push(b);b=b.nextSibling}return c};a.focus=function(){this.focusElement&&this.focusElement.focus&&this.focusElement.focus()};Spry.Widget.CollapsiblePanel.PanelAnimator=function(b,c,d){this.timer=null;this.interval=0;this.fps=60;this.duration=500;this.startTime=0;this.transition=Spry.Widget.CollapsiblePanel.PanelAnimator.defaultTransition;this.onComplete=null;this.panel=b;this.content=b.getContent();this.doOpen=c;Spry.Widget.CollapsiblePanel.setOptions(this,d,true);this.interval=Math.floor(1000/this.fps);b=this.content;d=b.offsetHeight?b.offsetHeight:0;this.fromHeight=c&&b.style.display=="none"?0:d;if(c){if(b.style.display=="none"){b.style.visibility="hidden";b.style.display="block"}b.style.height="";this.toHeight=b.offsetHeight}else this.toHeight=0;this.distance=this.toHeight-this.fromHeight;this.overflow=b.style.overflow;b.style.height=this.fromHeight+"px";b.style.visibility="visible";b.style.overflow="hidden";b.style.display="block"};Spry.Widget.CollapsiblePanel.PanelAnimator.defaultTransition=function(b,c,d,e){b/=e;return c+(2-b)*b*d};Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.start=function(){var b=this;this.startTime=(new Date).getTime();this.timer=setTimeout(function(){b.stepAnimation()},this.interval)};Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.stop=function(){if(this.timer){clearTimeout(this.timer);this.content.style.overflow=this.overflow}this.timer=null};Spry.Widget.CollapsiblePanel.PanelAnimator.prototype.stepAnimation=function(){var b=(new Date).getTime();b=b-this.startTime;if(b>=this.duration){if(!this.doOpen)this.content.style.display="none";this.content.style.overflow=this.overflow;this.content.style.height=this.toHeight+"px";this.onComplete&&this.onComplete()}else{b=this.transition(b,this.fromHeight,this.distance,this.duration);this.content.style.height=(b<0?0:b)+"px";var c=this;this.timer=setTimeout(function(){c.stepAnimation()},this.interval)}};Spry.Widget.CollapsiblePanelGroup=function(b,c){this.element=this.getElement(b);this.opts=c;this.attachBehaviors()};a=Spry.Widget.CollapsiblePanelGroup.prototype;a.setOptions=Spry.Widget.CollapsiblePanel.prototype.setOptions;a.getElement=Spry.Widget.CollapsiblePanel.prototype.getElement;a.getElementChildren=Spry.Widget.CollapsiblePanel.prototype.getElementChildren;a.setElementWidget=function(b,c){if(b&&c){if(!b.spry)b.spry={};b.spry.collapsiblePanel=c}};a.getElementWidget=function(b){return b&&b.spry&&b.spry.collapsiblePanel?b.spry.collapsiblePanel:null};a.getPanels=function(){if(!this.element)return[];return this.getElementChildren(this.element)};a.getPanel=function(b){return this.getPanels()[b]};a.attachBehaviors=function(){if(this.element)for(var b=this.getPanels(),c=b.length,d=0;d<c;d++){var e=b[d];this.setElementWidget(e,new Spry.Widget.CollapsiblePanel(e,this.opts))}};a.openPanel=function(b){(b=this.getElementWidget(this.getPanel(b)))&&!b.isOpen()&&b.open()};a.closePanel=function(b){(b=this.getElementWidget(this.getPanel(b)))&&b.isOpen()&&b.close()};a.openAllPanels=function(){for(var b=this.getPanels(),c=b.length,d=0;d<c;d++){var e=this.getElementWidget(b[d]);e&&!e.isOpen()&&e.open()}};a.closeAllPanels=function(){for(var b=this.getPanels(),c=b.length,d=0;d<c;d++){var e=this.getElementWidget(b[d]);e&&e.isOpen()&&e.close()}};
