text: Monocle.Controls.Contents=function(a){var c={constructor:Monocle.Controls.Contents};var b=c.constants=c.constructor;var f=c.properties={reader:a};function e(){var h=a.dom.make("div","controls_contents_container");d(h,a.getBook());return h}function d(m,h){while(m.hasChildNodes()){m.removeChild(m.firstChild)}var l=m.dom.append("ol","controls_contents_list");var k=h.properties.contents;for(var j=0;j<k.length;++j){g(l,k[j],0)}}function g(p,o,n){var j=p.childNodes.length;var h=p.dom.append("li","controls_contents_chapter",j);var m=h.dom.append("span","controls_contents_chapterTitle",j,{html:o.title});m.style.paddingLeft=n+"em";var l=function(){f.reader.skipToChapter(o.src);f.reader.hideControl(c)};Monocle.Events.listenForTap(h,l,"controls_contents_chapter_active");if(o.children){for(var k=0;k<o.children.length;++k){g(p,o.children[k],n+1)}}}c.createControlElements=e;return c};Monocle.Controls.Magnifier=function(b){var d={constructor:Monocle.Controls.Magnifier};var c=d.constants=d.constructor;var g=d.properties={buttons:[],magnified:false};function a(){g.reader=b}function f(i){var h=i.dom.make("div","controls_magnifier_button");h.smallA=h.dom.append("span","controls_magnifier_a",{text:"A"});h.largeA=h.dom.append("span","controls_magnifier_A",{text:"A"});g.buttons.push(h);Monocle.Events.listenForTap(h,e);return h}function e(h){var k;g.magnified=!g.magnified;if(g.magnified){k=[0.3,1];g.reader.formatting.setFontScale(c.MAGNIFICATION,true)}else{k=[1,0.3];g.reader.formatting.setFontScale(null,true)}for(var j=0;j<g.buttons.length;j++){g.buttons[j].smallA.style.opacity=k[0];g.buttons[j].largeA.style.opacity=k[1]}}d.createControlElements=f;a();return d};Monocle.Controls.Magnifier.MAGNIFICATION=1.2;Monocle.Controls.Panel=function(){var d={constructor:Monocle.Controls.Panel};var i=d.constants=d.constructor;var c=d.properties={evtCallbacks:{}};function g(k){c.div=k.dom.make("div",i.CLS.panel);c.div.dom.setStyles(i.DEFAULT_STYLES);Monocle.Events.listenForContact(c.div,{start:b,move:e,end:h,cancel:o},{useCapture:false});return c.div}function a(k){c.direction=k}function f(k){c.evtCallbacks=k}function m(){c.evtCallbacks={}}function b(k){c.contact=true;k.m.offsetX+=c.div.offsetLeft;k.m.offsetY+=c.div.offsetTop;l();j("start",k)}function e(k){if(!c.contact){return}j("move",k)}function h(k){if(!c.contact){return}Monocle.Events.deafenForContact(c.div,c.listeners);n();c.contact=false;j("end",k)}function o(k){if(!c.contact){return}Monocle.Events.deafenForContact(c.div,c.listeners);n();c.contact=false;j("cancel",k)}function j(p,k){if(c.evtCallbacks[p]){c.evtCallbacks[p](c.direction,k.m.offsetX,k.m.offsetY,d)}k.preventDefault()}function l(){if(c.expanded){return}c.div.dom.addClass(i.CLS.expanded);c.expanded=true}function n(k){if(!c.expanded){return}c.div.dom.removeClass(i.CLS.expanded);c.expanded=false}d.createControlElements=g;d.listenTo=f;d.deafen=m;d.expand=l;d.contract=n;d.setDirection=a;return d};Monocle.Controls.Panel.CLS={panel:"panel",expanded:"controls_panel_expanded"};Monocle.Controls.Panel.DEFAULT_STYLES={position:"absolute",height:"100%"};Monocle.Controls.PlaceSaver=function(m){var b={constructor:Monocle.Controls.PlaceSaver};var d=b.constants=b.constructor;var a=b.properties={};function e(){c(m)}function j(k){a.reader=k;a.reader.listen("monocle:turn",h)}function c(k){a.bkTitle=k.toLowerCase().replace(/[^a-z0-9]/g,"");a.prefix=d.COOKIE_NAMESPACE+a.bkTitle+"."}function l(n,o,r){var k="";if(r){var q=new Date();q.setTime(q.getTime()+(r*24*60*60*1000));k="; expires="+q.toGMTString()}var p="; path=/";document.cookie=a.prefix+n+"="+o+k+p;return o}function g(k){if(!document.cookie){return null}var n=new RegExp(a.prefix+k+"=(.+?)(;|$)");var o=document.cookie.match(n);if(o){return o[1]}else{return null}}function h(){var k=a.reader.getPlace();l("component",encodeURIComponent(k.componentId()),d.COOKIE_EXPIRES_IN_DAYS);l("percent",k.percentageThrough(),d.COOKIE_EXPIRES_IN_DAYS)}function f(){var k={componentId:g("component"),percent:g("percent")};if(k.componentId&&k.percent){k.componentId=decodeURIComponent(k.componentId);k.percent=parseFloat(k.percent);return k}else{return null}}function i(){var k=f();if(k){a.reader.moveTo(k)}}b.assignToReader=j;b.savedPlace=f;b.restorePlace=i;e();return b};Monocle.Controls.PlaceSaver.COOKIE_NAMESPACE="monocle.controls.placesaver.";Monocle.Controls.PlaceSaver.COOKIE_EXPIRES_IN_DAYS=7;Monocle.Controls.Scrubber=function(g){var b={constructor:Monocle.Controls.Scrubber};var d=b.constants=b.constructor;var a=b.properties={};function e(){a.reader=g;a.reader.listen("monocle:turn",f);f()}function i(k,o){if(!a.componentIds){a.componentIds=a.reader.getBook().properties.componentIds;a.componentWidth=100/a.componentIds.length}var m=(k/o.offsetWidth)*100;var l=a.componentIds[Math.floor(m/a.componentWidth)];var n=((m%a.componentWidth)/a.componentWidth);return{componentId:l,percentageThrough:n}}function j(l,n){if(!a.componentIds){a.componentIds=a.reader.getBook().properties.componentIds;a.componentWidth=100/a.componentIds.length}var k=a.componentIds.indexOf(l.componentId());var m=a.componentWidth*k;m+=l.percentageThrough()*a.componentWidth;return Math.round((m/100)*n.offsetWidth)}function f(){if(a.hidden||!a.reader.dom.find(d.CLS.container)){return}var l=a.reader.getPlace();var k=j(l,a.reader.dom.find(d.CLS.container));var n,m=0;for(var m=0,n;n=a.reader.dom.find(d.CLS.needle,m);++m){h(n,k-n.offsetWidth/2);a.reader.dom.find(d.CLS.trail,m).style.width=k+"px"}}function h(l,k){var m=a.reader.dom.find(d.CLS.container);k=Math.min(m.offsetWidth-l.offsetWidth,k);k=Math.max(k,0);Monocle.Styles.setX(l,k)}function c(q){var s=q.dom.make("div",d.CLS.container);var k=s.dom.append("div",d.CLS.track);var r=s.dom.append("div",d.CLS.trail);var m=s.dom.append("div",d.CLS.needle);var p=s.dom.append("div",d.CLS.bubble);var n,t;var o=function(z,w){z.preventDefault();w=(typeof w=="number")?w:z.m.registrantX;var y=i(w,s);h(m,w-m.offsetWidth/2);var A=a.reader.getBook();var v=A.chaptersForComponent(y.componentId);var C=a.componentIds.indexOf(y.componentId);var D=v[Math.floor(v.length*y.percentageThrough)];if(C>-1&&A.properties.components[C]){var B=Monocle.Place.FromPercentageThrough(A.properties.components[C],y.percentageThrough);D=B.chapterInfo()||D}if(D){p.innerHTML=D.title}h(p,w-p.offsetWidth/2);a.lastX=w;return y};var l=function(w){var v=o(w,a.lastX);a.reader.moveTo({percent:v.percentageThrough,componentId:v.componentId});Monocle.Events.deafenForContact(s,n);Monocle.Events.deafenForContact(document.body,t);p.style.display="none"};var u=function(v){p.style.display="block";o(v);n=Monocle.Events.listenForContact(s,{move:o});t=Monocle.Events.listenForContact(document.body,{end:l})};Monocle.Events.listenForContact(s,{start:u});return s}b.createControlElements=c;b.updateNeedles=f;e();return b};Monocle.Controls.Scrubber.CLS={container:"controls_scrubber_container",track:"controls_scrubber_track",needle:"controls_scrubber_needle",trail:"controls_scrubber_trail",bubble:"controls_scrubber_bubble"};Monocle.Controls.Spinner=function(h){var c={constructor:Monocle.Controls.Spinner};var g=c.constants=c.constructor;var b=c.properties={reader:h,divs:[],spinCount:0,repeaters:{},showForPages:[]};function f(k){var j=k.dom.make("div","controls_spinner_anim");b.divs.push(j);return j}function e(j,l){var k=j;b.reader.listen(j,function(m){a(k,m)});b.reader.listen(l,function(m){i(k,m)})}function d(){e("monocle:componentloading","monocle:componentloaded");e("monocle:componentchanging","monocle:componentchange");e("monocle:resizing","monocle:resize");e("monocle:jumping","monocle:jump");e("monocle:recalculating","monocle:recalculated")}function a(m,l){m=m||g.GENERIC_LABEL;b.repeaters[m]=true;b.reader.showControl(c);var o=l&&l.m&&l.m.page?l.m.page:null;if(!o){b.global=true}for(var n=0;n<b.divs.length;++n){var j=b.divs[n].parentNode.parentNode;if(o==j){b.showForPages.push(o)}var k=b.global||b.showForPages.indexOf(o)>=0;b.divs[n].style.display=k?"block":"none"}}function i(m,k){m=m||g.GENERIC_LABEL;b.repeaters[m]=false;for(var j in b.repeaters){if(b.repeaters[j]){return}}b.global=false;b.showForPages=[];b.reader.hideControl(c)}c.createControlElements=f;c.listenForUsualDelays=d;c.spin=a;c.spun=i;return c};Monocle.Controls.Spinner.GENERIC_LABEL="generic";Monocle.Controls.Stencil=function(a,f){var r={constructor:Monocle.Controls.Stencil};var t=r.constants=r.constructor;var o=r.properties={reader:a,behaviors:[],components:{},masks:[]};function l(p){f=f||t.DEFAULT_BEHAVIORS;for(var k=0,A=f.length;k<A;++k){u(f[k])}o.container=p.dom.make("div",t.CLS.container);o.reader.listen("monocle:turning",i);o.reader.listen("monocle:turn:cancel",x);o.reader.listen("monocle:turn",g);o.reader.listen("monocle:stylesheetchange",g);o.reader.listen("monocle:resize",g);g();return o.container}function u(p){var k=new p(r);if(typeof k.findElements!="function"){console.warn('Missing "findElements" method for behavior: %o',k)}if(typeof k.fitMask!="function"){console.warn('Missing "fitMask" method for behavior: %o',k)}o.behaviors.push(k)}function g(){var p=o.reader.visiblePages();if(!p||!p.length){return}var A=p[0];var k=v(A);if(!k){return}o.components[k]=null;z(A);h()}function i(){o.container.style.display="none"}function x(){o.container.style.display="block"}function q(){while(o.container.childNodes.length){o.container.removeChild(o.container.lastChild)}}function h(){var A=o.reader.visiblePages()[0];var k=v(A);if(!o.components[k]){return}c(A);q();if(!o.disabled){x();var p=o.components[k];if(p&&p.length){s(A,p)}}}function z(D){var B=v(D);if(!o.components[B]){o.components[B]=[]}else{return}var J=D.m.activeFrame.contentDocument;var F=e(D);for(var I=0,H=o.behaviors.length;I<H;++I){var p=o.behaviors[I];var A=p.findElements(J);for(var G=0;G<A.length;++G){var C=A[G];if(C.getClientRects){var k=C.getClientRects();for(var E=0;E<k.length;E++){o.components[B].push({element:C,behavior:p,left:Math.ceil(k[E].left+F.l),top:Math.ceil(k[E].top),width:Math.floor(k[E].width),height:Math.floor(k[E].height)})}}}}return o.components[B]}function s(A,p){var F=e(A);var C=[];for(var B=0;B<p.length;++B){if(y(p[B],F.l,F.l+F.w)){C.push(p[B])}}for(B=0;B<C.length;++B){var E=C[B];var D={left:E.left-F.l,top:E.top,width:E.width,height:E.height};var k=b(E.element,E.behavior);k.dom.setStyles({display:"block",left:D.left+"px",top:D.top+"px",width:D.width+"px",height:D.height+"px",position:"absolute"});k.stencilRect=D}}function e(k){return{l:k.m.offset||0,w:k.m.dimensions.properties.width}}function y(A,k,p){return A.left>=k&&A.left<p}function v(k){k=k||o.reader.visiblePages()[0];if(!k.m.activeFrame.m.component){return}return k.m.activeFrame.m.component.properties.id}function c(k){cmpt=k.m.activeFrame.parentNode;o.container.dom.setStyles({left:cmpt.offsetLeft+"px",top:cmpt.offsetTop+"px"})}function b(p,A){var k=o.container.dom.append(A.maskTagName||"div",t.CLS.mask);Monocle.Events.listenForContact(k,{start:function(){o.reader.dispatchEvent("monocle:magic:halt")},move:function(B){B.preventDefault()},end:function(){o.reader.dispatchEvent("monocle:magic:init")}});A.fitMask(p,k);return k}function n(){var k=t.CLS.highlights;if(o.container.dom.hasClass(k)){o.container.dom.removeClass(k)}else{o.container.dom.addClass(k)}}function d(){o.disabled=true;h()}function j(){o.disabled=false;h()}function m(p,k){if(typeof k.filterElement=="function"){return k.filterElement(p)}return p}function w(A,k,p){if(typeof p.maskAssigned=="function"){return p.maskAssigned(A,k)}return false}r.createControlElements=l;r.addBehavior=u;r.draw=h;r.update=g;r.toggleHighlights=n;return r};Monocle.Controls.Stencil.CLS={container:"controls_stencil_container",mask:"controls_stencil_mask",highlights:"controls_stencil_highlighted"};Monocle.Controls.Stencil.Links=function(c){var b={constructor:Monocle.Controls.Stencil.Links};b.maskTagName="a";b.findElements=function(d){return d.querySelectorAll("a[href]")};b.fitMask=function(f,d){var e=a(f);if(e.internal){d.setAttribute("href",'javascript:"Skip to chapter"');Monocle.Events.listen(d,"click",function(g){c.properties.reader.skipToChapter(e.internal);g.preventDefault()})}else{d.setAttribute("href",e.external);d.setAttribute("target","_blank");f.setAttribute("target","_blank")}};function a(k){var g=k.href;if(!k.getAttribute("target")){var d=g.match(/([^#]*)(#.*)?$/);var l=d[1];var f=d[2]||"";var e=c.properties.reader.getBook().properties.componentIds;for(var h=0,j=e.length;h<j;++h){if(l.substr(0-e[h].length)==e[h]){return{internal:e[h]+f}}}}return{external:g}}return b};Monocle.Controls.Stencil.DEFAULT_BEHAVIORS=[Monocle.Controls.Stencil.Links];