﻿var howToBrowser=Class.create();Object.extend(howToBrowser.prototype,{keyDirection:null,_didShowNotificationListenerIsSet:false,keyLeft:function(a){if(Element.hasClassName(Event.element(a),"howto-content")||Event.element(a).up("howto-content")){$$(".how-to .active")[0].focus();
Event.stop(a);return}var c=this.getListItemFromEvent(a),d,b=(c.previous())?c.previous():false;
if(c.getAttribute("aria-level")==1&&b!==false){this.scrollAndSetFocusForElements(b,c)
}},keyUp:function(a){if(Element.hasClassName(Event.element(a),"howto-content")||Event.element(a).up("howto-content")){return
}var c=this.getListItemFromEvent(a),b;if(c.getAttribute("aria-level")==2){b=(c.previous())?c.previous():false;
if(b){this.setFocusForElements(b,c)}else{$$(".nav-item .active")[0].up("li").focus();
Element.removeClassName($$(".how-to.activedescendant")[0],"activedescendant")}}},keyRight:function(a){if(Element.hasClassName(Event.element(a),"howto-content")||Event.element(a).up("howto-content")){return
}var c=this.getListItemFromEvent(a),d,b=(c.next())?c.next():false,e;if(c.getAttribute("aria-level")==1&&b!==false){this.scrollAndSetFocusForElements(b,c)
}else{if(c.getAttribute("aria-level")==2){e=$$(".howto-content")[0];e.setAttribute("tabindex","0");
e.setAttribute("aria-level","3");Event.stopObserving(e,"keydown");Event.observe(e,"keydown",this.keyPressHandler.bindAsEventListener(this));
Element.removeClassName($$(".how-to.activedescendant")[0],"activedescendant");e.focus()
}}},keyDown:function(b){if(Element.hasClassName(Event.element(b),"howto-content")||Event.element(b).up("howto-content")){return
}var d=this.getListItemFromEvent(b),a,c;if(d.getAttribute("aria-level")==1&&Element.hasClassName(d.down("a"),"active")){d.setAttribute("aria-expanded","true");
a=$$(".howto-list .active")[0].up("li");this.setFocusForElements(a,d)}else{if(d.getAttribute("aria-level")==2){c=(d.next())?d.next():false;
if(c){this.setFocusForElements(c,d)}}}},getListItemFromEvent:function(a){Event.stop(a);
return Event.findElement(a,"li")},scrollAndSetFocusForElements:function(a,b){Element.childElements(b.parentNode).each(function(d,c){if(d===a){triggerIndex=c
}});if(triggerIndex!==false){slider.maskInnerDimension=parseInt(b.getWidth()*slider.itemsPerPage);
slider.scrollToItem(triggerIndex);slider.resetPages()}if((triggerIndex%slider.itemsPerPage)===0&&this.keyDirection!=="left"){window.setTimeout(this.setFocusForElements.bind(this,a,b),500)
}else{this.setFocusForElements(a,b)}},setFocusForElements:function(a,b){b.parentNode.setAttribute("aria-activedescendant",a.id);
a.down("a").focus();Element.removeClassName(b,"activedescendant");Element.addClassName(a,"activedescendant")
},keyPressHandler:function(a){switch(a.keyCode){case Event.KEY_LEFT:this.keyDirection="left";
this.keyLeft(a);break;case Event.KEY_UP:this.keyDirection="up";this.keyUp(a);break;
case Event.KEY_RIGHT:this.keyDirection="right";this.keyRight(a);break;case Event.KEY_DOWN:this.keyDirection="down";
this.keyDown(a);break;default:return}Event.stop(a)},willSetSwapView:function(d,b,g){var a,e,g,h,f,c;
$$(".browser-selector-link").each(function(j,i){a=j.up("li"),e=a.parentNode,g=(Element.hasClassName(j,"nav-link"))?"nav-link":j.up("div").id.split("MASKED-")[1]+"-howto-link",h=(g==="nav-link")?1:2,f=j.href.split("#")[1]+"_"+g;
a.id=f;a.setAttribute("aria-level",h);a.setAttribute("role","treeitem");a.setAttribute("tabindex","-1");
if(h!==1){e.setAttribute("role","group")}if(Element.hasClassName(j,"active")){a.setAttribute("aria-expanded","true");
e.setAttribute("aria-activedescendant",f);e.setAttribute("role","tree");e.setAttribute("tabindex","0")
}Event.stopObserving(a,"keydown");Event.observe(a,"keydown",this.keyPressHandler.bindAsEventListener(this))
}.bind(this));c=d.currentViewIndex();return d.getSelectedViewIdForHref_selectedViewAtIndex_andTriggerClassName_(window.location.href,c,g)
},didSetSwapView:function(b,a,d){var c=this;if(this._didShowNotificationListenerIsSet===false){Event.Listener.listenForEvent(AC.ViewMaster,"ViewMasterDidShowNotification",false,function(r){b.currentTrigger=(r.event_data.data.trigger&&!b.nextSelectedId&&!Element.hasClassName(b.currentTrigger,"browser-link"))?r.event_data.data.trigger:b.currentTrigger;
var z=parseInt(b.currentViewIndex()+1),p=b.currentTrigger.href.split("#")[1],C,u,w,f,t=false,D,k,A,m=false,x=0,l,s="",B,j,y=b.viewmasters(),e=30,v,h=0,E="500px",q,g;
if(b.currentTrigger.hasClassName(b.viewsToSet[0].triggerClassName)){u=p+"-howto-content";
w=p+"-howto-link";C=$(u);f=b.viewsToSet.find(function(i){return(i.view===u)?true:false
});if(!f){$$("."+w).each(function(i){D=i.down("span").innerHTML;v=D.match(/&\w+;/g);
h=0;if(v){v.each(function(F){h+=F.toString().length-1})}e=(h>0)?parseInt(e+h):30;
i.down("span").innerHTML=D.truncate(e)});b.setView(p,u,w);b.draw(z);A=$$("."+w)[0].up("ul");
k=A.getHeight();A.style.height=(k>500)?k+"px":"500px";q=c.getMarginHeightFromElement(A);
g=c.getMarginHeightFromElement(C);A.style.height=(k>500)?k+"px":"500px";C.style.height=(k>500)?((k+q)-g)+"px":((500+q)-g)+"px";
C.up().style.height=(k>500)?(k+q)+"px":(500+q)+"px"}else{if(this.nextSelectedId!==null){while(m===false&&x<y.length){m=(y[x].id===p)?y[x]:false;
x++}l=m.viewmaster.sectionWithId(this.nextSelectedId);this.nextSelectedId=null;
m.viewmaster.show(l,true)}}}else{$$(".active.browser-selector-link").each(function(F,i){Element.addClassName(F,"visited");
B=F.href.split("#")[1];if(i===0&&Element.hasClassName(F,"nav-link")){j=B}else{s+="."
}s+=B});$$(".nav-link").each(function(F,i){if(F.href.split("#")[1]===j){t=i}});
if(t!==false){slider.scrollToItem(t);slider.resetPages()}document.location.hash=s;
var o=$$(".howto-browser")[0];var n=o.viewportOffset()[1];if(n<0||n>(document.viewport.getHeight()*0.75)){new Effect.ScrollTo(o,{duration:0.3})
}}}.bindAsEventListener(b));this._didShowNotificationListenerIsSet=true}},getMarginHeightFromElement:function(a){return parseInt(a.getStyle("margin-top").split("px")[0])+parseInt(a.getStyle("margin-bottom").split("px")[0])
}});
