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