(function(){var animationFrameDelay=10;var animationLength=500;var expanderHeight=41;var expanderTagName="a";var expanderCssClass="expander";var itemCssClass="curtainitem";var itemTagName="div";var menuCssClass="curtainmenu";var menuTagName="div";var containerId="atmospherewithcurtains";var activeMenuCssClass="menuactive";function array_contains(array,val){for(var i=0;i<array.length;i++){if(array[i]==val){return true;}}
return false;};function getEventTarget(evt){if(evt&&evt.target){return evt.target;}else if(window.event){return window.event.srcElement;}}
function isDescendantOf(node,ancestorNode){while(node){if(ancestorNode==node){return true;}
node=node.parentNode;}
return false;}
function getAncestorWithClass(node,tagName,cssClass){tagName=tagName.toLowerCase();while(node&&node.tagName){if(node.tagName.toLowerCase()==tagName&&hasClass(node,cssClass)){return node;}
node=node.parentNode;}
return null;}
function addClass(el,cssClass){if(!hasClass(el,cssClass)){if(el.className){el.className+=" "+cssClass;}else{el.className=cssClass;}}}
function hasClass(el,cssClass){if(el.className){var classNames=el.className.split(" ");return array_contains(classNames,cssClass);}
return false;}
function removeClass(el,cssClass){if(hasClass(el,cssClass)){var existingClasses=el.className.split(" ");var newClasses=new Array()
for(var i=0;i<existingClasses.length;i++){if(existingClasses[i]!=cssClass){newClasses[newClasses.length]=existingClasses[i];}}
el.className=newClasses.join(" ");}}
var animationTimer=null;var animations=[];function Animation(animationFunction,len){this.animationFunction=animationFunction;this.frameDelay=animationFrameDelay;this.len=len;this.framesShown=0;this.startTime=new Date();this.finished=false;this.cancelled=false;}
Animation.prototype.cancel=function(){this.cancelled=true;};Animation.doFrame=function(){for(var i=0;i<animations.length;i++){if(!animations[i].cancelled){var currentTime=new Date();var elapsedMilliseconds=currentTime.getTime()-animations[i].startTime.getTime();var animationProgress=Math.min(1,elapsedMilliseconds/animations[i].len);animations[i].finished=animations[i].animationFunction(animationProgress);animations[i].framesShown++;}}
var tempAnimations=[];for(i=0;i<animations.length;i++){if(!animations[i].finished&&!animations[i].cancelled){tempAnimations[tempAnimations.length]=animations[i];}}
animations=tempAnimations;if(animations.length==0){clearInterval(animationTimer);animationTimer=null;}};function createAnimation(animationFunction,len){var animation=new Animation(animationFunction,len);animations[animations.length]=animation;if(animations.length==1){Animation.doFrame();animationTimer=setInterval(Animation.doFrame,animationFrameDelay);}
return animation;}
function appearMenu(item){addClass(item,activeMenuCssClass);var menu=getItemMenu(item);if(menu.animation){menu.animation.cancel();}
if(menu){menu.expandedHeight=menu.offsetHeight;var height=expanderHeight;var animationDistance=menu.expandedHeight-expanderHeight;var expand=function(t){height=expanderHeight+Math.floor(animationDistance*t*(2-t));menu.style.top=(expanderHeight-height)+"px";menu.style.clip="rect(0 200px "+height+"px 0)";if(height<menu.expandedHeight){return false;}else{menu.animation=null;return true;}};menu.animation=createAnimation(expand,animationLength);}}
function disappearMenu(item){var menu=getItemMenu(item);if(menu.animation){menu.animation.cancel();}
if(menu){var initialHeight=expanderHeight-parseInt(menu.style.top);var height=initialHeight;var animationDistance=initialHeight-expanderHeight;var collapse=function(t){height=initialHeight-Math.floor(animationDistance*t*(2-t));menu.style.top=(expanderHeight-height)+"px";menu.style.clip="rect(0 200px "+height+"px 0)";if(height>expanderHeight){return false;}else{removeClass(item,activeMenuCssClass);menu.animation=null;return true;}};menu.animation=createAnimation(collapse,animationLength);}}
function getItem(expander){return getAncestorWithClass(expander,itemTagName,itemCssClass);}
function getItemMenu(item){var els=item.getElementsByTagName(menuTagName);for(var i=0;i<els.length;i++){if(hasClass(els[i],menuCssClass)){return els[i];}}
return null;}
function focusItem(item){appearMenu(item);if(menuDisappearTimer){window.clearTimeout(menuDisappearTimer);}
if(activeMenu){if(!isDescendantOf(item,activeMenu)){disappearMenu(activeMenu);activeMenu=item;}}else{activeMenu=item;}}
function blurItem(){window.clearTimeout(menuDisappearTimer);}
function expanderClick(){this.blur();toggleItem(getItem(this));return false;}
function toggleItem(item){if(activeMenu&&isDescendantOf(item,activeMenu)){disappearMenu(activeMenu);activeMenu=null;}else{focusItem(item);}}
function expanderKeyPress(evt){evt=evt?evt:event;if(evt.keyCode==10||evt.keyCode==13||evt.keyCode==32){toggleItem(getItem(this));}}
function linkClick(){return false;}
function containerClicked(evt){var elementClicked=getEventTarget(evt);var item=getItem(elementClicked);if(item){if(elementClicked.tagName.toLowerCase()==expanderTagName&&hasClass(elementClicked,expanderCssClass)){toggleItem(item);}}else if(activeMenu){disappearMenu(activeMenu);activeMenu=null;}}
function initMenus(){var container=document.getElementById(containerId);var els=container.getElementsByTagName(expanderTagName);container.onclick=containerClicked;addClass(container,"loaded");}
function pollDocument(){if(document&&document.getElementById(containerId)){initMenus();}else{setTimeout(pollDocument,100);}}
var activeMenu=null;var menuDisappearTimer=null;pollDocument();})();
