",handler:function(w){var lookaheadRegExp=new RegExp(this.lookahead,"mg");lookaheadRegExp.lastIndex=w.matchStart;var lookaheadMatch=lookaheadRegExp.exec(w.source);if(lookaheadMatch&&lookaheadMatch.index==w.matchStart){var e=insertElement(w.output,"span");e.innerHTML=lookaheadMatch[1];w.nextMatch=lookaheadMatch.index+lookaheadMatch[0].length}}},{name:"commentByBlock",match:"/%",lookahead:"/%((?:.|\\n)*?)%/",handler:function(w){var lookaheadRegExp=new RegExp(this.lookahead,"mg");lookaheadRegExp.lastIndex=w.matchStart;var lookaheadMatch=lookaheadRegExp.exec(w.source);if(lookaheadMatch&&lookaheadMatch.index==w.matchStart){w.nextMatch=lookaheadMatch.index+lookaheadMatch[0].length}}},{name:"boldByChar",match:"''",terminator:"''",element:"strong",handler:Wikifier.formatHelpers.charFormatHelper},{name:"strikeByChar",match:"==",terminator:"==",element:"strike",handler:Wikifier.formatHelpers.charFormatHelper},{name:"underlineByChar",match:"__",terminator:"__",element:"u",handler:Wikifier.formatHelpers.charFormatHelper},{name:"italicByChar",match:"//",terminator:"//",element:"em",handler:Wikifier.formatHelpers.charFormatHelper},{name:"subscriptByChar",match:"~~",terminator:"~~",element:"sub",handler:Wikifier.formatHelpers.charFormatHelper},{name:"superscriptByChar",match:"\\^\\^",terminator:"\\^\\^",element:"sup",handler:Wikifier.formatHelpers.charFormatHelper},{name:"monospacedByChar",match:"\\{\\{\\{",lookahead:"\\{\\{\\{((?:.|\\n)*?)\\}\\}\\}",handler:function(w){var lookaheadRegExp=new RegExp(this.lookahead,"mg");lookaheadRegExp.lastIndex=w.matchStart;var lookaheadMatch=lookaheadRegExp.exec(w.source);if(lookaheadMatch&&lookaheadMatch.index==w.matchStart){var e=insertElement(w.output,"code",null,null,lookaheadMatch[1]);w.nextMatch=lookaheadMatch.index+lookaheadMatch[0].length}}},(Wikifier.styleByCharFormatter={name:"styleByChar",match:"@@",terminator:"@@",lookahead:"(?:([^\\(@]+)\\(([^\\)\\|\\n]+)(?:\\):))|(?:([^\\.:@]+):([^;\\|\\n]+);)|(?:\\.([^;\\|\\n]+);)",handler:function(w){var e=insertElement(w.output,"span",null,null,null);var styles=Wikifier.formatHelpers.inlineCssHelper(w);if(styles.length==0){e.className="marked"}else{for(var t=0;t\\s]+))?)+\\s*|\\s*)\\/?)>",tagname:"<(\\w+)",voids:["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],tableElems:["table","thead","tbody","tfoot","th","tr","td","colgroup","col","caption","figcaption"],cleanupTables:function(e){var i,name,elems=[].slice.call(e.children);for(i=0;i";isvoid=(this.voids.indexOf(tn)!=-1);isstyle=tn=="style"||tn=="script";lookaheadRegExp=new RegExp(lookahead,"mg");lookaheadRegExp.lastIndex=a.matchStart;lookaheadMatch=lookaheadRegExp.exec(a.source);if(lookaheadMatch||isvoid){if(isstyle){e=document.createElement(tn);e.type="text/css";tmp=a.source.slice(a.nextMatch,lookaheadMatch.index);e.styleSheet?(e.styleSheet.cssText=tmp):(e.innerHTML=tmp);a.nextMatch=lookaheadMatch.index+lookaheadMatch[0].length}else{e=document.createElement(a.output.tagName);e.innerHTML=a.matchText;while(e.firstChild){e=e.firstChild}if(!isvoid){a.subWikify(e,lookahead)}}if(e.tagName.toLowerCase()=="table"){this.cleanupTables.call(this,e)}if(setter=e.getAttribute("data-setter")){setter=Wikifier.linkFormatter.makeCallback(setter)}if(passage=e.getAttribute("data-passage")){if(tn!="img"){addClickHandler(e,Wikifier.linkFunction(Wikifier.parsePassageTitle(passage),e,setter));if(tn=="area"||tn=="a"){e.setAttribute("href","javascript:;")}}else{Wikifier.imageFormatter.importedImage(e,passage)}}a.output.appendChild(e)}else{throwError(a.output,"HTML tag '"+tn+"' wasn't closed.",a.matchText)}}}}];Wikifier.charSpanFormatter={name:"char",match:"[^\n]",handler:function(a){insertElement(a.output,"span",null,"char",a.matchText).setAttribute("data-char",a.matchText==" "?"space":a.matchText=="\t"?"tab":a.matchText)}};Wikifier.parsePassageTitle=function(title){if(title&&!tale.has(title)){try{title=(internalEval(this.parse(title))||title)+""}catch(e){}}return title};Wikifier.linkFunction=function(title,el,callback){return function(){if(state.rewindTo){var passage=findPassageParent(el);if(passage&&passage.parentNode.lastChild!=passage){state.rewindTo(passage,true)}}state.display(title,el,null,callback)}};Wikifier.createInternalLink=function(place,title,callback,type){var tag=(type=="button"?"button":"a"),suffix=(type=="button"?"Button":"Link"),el=insertElement(place,tag);if(tale.has(title)){el.className="internal"+suffix;if(visited(title)){el.className+=" visited"+suffix}}else{el.className="broken"+suffix}addClickHandler(el,Wikifier.linkFunction(title,el,callback));if(place){place.appendChild(el)}return el};Wikifier.createExternalLink=function(place,url,callback,type){var tag=(type=="button"?"button":"a"),el=insertElement(place,tag);el.href=url;el.className="external"+(type=="button"?"Button":"Link");el.target="_blank";if(typeof callback=="function"){addClickHandler(el,callback)}if(place){place.appendChild(el)}return el};function visited(e){var ret=0,i=0;if(!state){return 0 }e=e||state.history[0].passage.title;if(arguments.length>1){for(ret=state.history.length;i1){for(i=arguments.length-1;i>=1;i--){ret=ret.concat(tags(arguments[i]))}}ret=ret.concat(tale.get(e).tags);return ret}function previous(){if(state&&state.history[1]){for(var d=1;d1){return"You are about to end this "+tale.identity()+"."}};var oldOnError=window.onerror||null,softErrorMessage="You may be able to continue playing, but some parts may not work properly.";window.onerror=function(msg,a,b,c,error){var s=(error&&(".\n\n"+error.stack.replace(/\([^\)]+\)/g,"")+"\n\n"))||(" ("+msg+").\n");alert("Sorry to interrupt, but this "+((tale&&tale.identity&&tale.identity())||"page")+"'s code has got itself in a mess"+s+softErrorMessage.slice(1));window.onerror=oldOnError;if(typeof window.onerror=="function"){window.onerror(msg,a,b,c,error)}};var $;function main(){$=window.$||function(a){return(typeof a=="string"?document.getElementById(a):a) };var imgs,scripts,macro,style,i,styleText="",passages=document.getElementById("passages");function sanityCheck(thing){var i,j,s="NOTE: The "+thing,checks={prerender:prerender,postrender:postrender,macros:macros};for(i in checks){if(Object.prototype.hasOwnProperty.call(checks,i)&&!sanityCheck[i]){if(!checks[i]||typeof checks[i]!="object"){alert(s+" seems to have corrupted the "+i+" object."+softErrorMessage);sanityCheck[i]=true;continue}if(i!="macros"){for(j in checks[i]){if(Object.prototype.hasOwnProperty.call(checks[i],j)&&typeof checks[i][j]!="function"){alert(s+" added a property '"+j+"' to "+i+", "+"which is a "+typeof checks[i][j]+", not a function."+softErrorMessage);sanityCheck[i]=true;break}}}}}if(!sanityCheck.display){if(History.prototype.display.length<4&&!~History.prototype.display.toString().indexOf("arguments")){alert(s+" contains a function that patches History.prototype.display, but takes the wrong number of arguments."+softErrorMessage)}sanityCheck.display=true}}if(!window.JSON||!document.querySelector){return(passages.innerHTML="This "+tale.identity()+" requires a newer web browser. Sorry.")}else{passages.innerHTML=""}tale=window.tale=new Tale();if(~document.documentElement.className.indexOf("lt-ie9")){imgs=tale.lookup("tags","Twine.image");for(i=0;i=32768){alert("NOTE: This "+tale.identity()+"'s HTML file contains embedded images that may be too large for this browser to display."+softErrorMessage);break}}}scripts=tale.lookup("tags","script");for(i=0;i-1){setTransitionCSS(i.text)}}}styleText=alterCSS(styleText);style.styleSheet?(style.styleSheet.cssText=styleText):(style.innerHTML=styleText);state.init()}setTimeout(function f(){var size,bar=document.getElementById("loadingbar"),store=document.getElementById("storeArea");if(!bar){return }if(store){size=store.getAttribute("data-size");if(store.children.length<=size&&!tale){bar.style.width=~~((store.children.length+1)/size*100)+"%"}else{bar.outerHTML="";return}}setTimeout(f,5)},5); var hasPushState=!!window.history&&(typeof window.history.pushState=="function")&&(function(a){try{a.setItem("test","1");a.removeItem("test");return true}catch(e){return false }}(window.sessionStorage));Tale.prototype.canBookmark=function(){return this.canUndo()&&!this.storysettings.lookup("hash")&&(this.storysettings.lookup("bookmark",true)||!hasPushState)};History.prototype.init=function(){var a=this;if(!this.restore()){if(tale.has("StoryInit")){new Wikifier(insertElement(null,"span"),tale.get("StoryInit").text)}this.display("Start",null)}if(!hasPushState){this.hash=window.location.hash;this.interval=window.setInterval(function(){a.watchHash()},250)}};hasPushState&&(History.prototype.pushState=function(replace,uri){window.history[replace?"replaceState":"pushState"]({id:this.id,length:this.history.length},document.title,uri)});History.prototype.display=function(title,source,type,callback){var i,e,q,bookmark,hash,c=tale.get(title),p=document.getElementById("passages");if(c==null){return }if(type!="back"){this.saveVariables(c,source,callback);hash=(tale.storysettings.lookup("hash")&&this.save())||"";if(hasPushState&&tale.canUndo()){try{sessionStorage.setItem("Twine.History"+this.id,JSON.stringify(decompile(this.history)));this.pushState(this.history.length<=2&&window.history.state=="",hash)}catch(e){alert("Your browser couldn't save the state of the "+tale.identity()+".\n"+"You may continue playing, but it will no longer be possible to undo moves from here on in.");tale.storysettings.undo="off"}}}this.hash=hash||this.save();e=c.render();if(type!="quietly"){if(hasTransition){for(i=0;i>/g,"");b=b.replace(/!.*?\n/g,"");b=b.replace(/[\[\]\/]/g,"");var a=b.split("\n");while(a.length&&a[0].length==0){a.shift()}var c="";if(a.length==0||a[0].length==0){c=this.title}else{c=a[0].substr(0,30)+"..."}return c};Passage.transitionCache="";Passage.prototype.setCSS=function(){var trans=false,text="",tags=this.tags||[],c=document.getElementById("tagCSS"),c2=document.getElementById("transitionCSS");if(c&&c.getAttribute("data-tags")!=tags.join(" ")){tale.forEachStylesheet(tags,function(passage){if(~passage.tags.indexOf("transition")){if(!Passage.transitionCache&&c2){Passage.transitionCache=c2.innerHTML}setTransitionCSS(passage.text);trans=true}else{text+=alterCSS(passage.text)}});if(!trans&&Passage.transitionCache&&c2){setTransitionCSS(Passage.transitionCache);trans=false;Passage.transitionCache=""}c.styleSheet?(c.styleSheet.cssText=text):(c.innerHTML=text);c.setAttribute("data-tags",tags.join(" "))}};var Interface={init:function(){var snapback=document.getElementById("snapback"),restart=document.getElementById("restart"),bookmark=document.getElementById("bookmark");main();if(!tale){return }if(snapback){if(!tale.lookup("tags","bookmark").length){snapback.parentNode.removeChild(snapback)}else{addClickHandler(snapback,Interface.showSnapback)}}if(bookmark&&(!tale.canBookmark()||!hasPushState)){bookmark.parentNode.removeChild(bookmark)}restart&&addClickHandler(restart,Interface.restart)},restart:function(){if(confirm("Are you sure you want to restart this "+tale.identity()+"?")){state.restart()}},showSnapback:function(a){Interface.hideAllMenus();Interface.buildSnapback();Interface.showMenu(a,document.getElementById("snapbackMenu"))},buildSnapback:function(){var b,c=false,menuelem=document.getElementById("snapbackMenu");while(menuelem.hasChildNodes()){menuelem.removeChild(menuelem.firstChild)}for(var a=state.history.length-1;a>=0;a--){if(state.history[a].passage&&state.history[a].passage.tags.indexOf("bookmark")!=-1){b=document.createElement("div");b.pos=a;addClickHandler(b,function(){return macros.back.onclick(true,this.pos)});b.innerHTML=state.history[a].passage.excerpt();menuelem.appendChild(b);c=true}}b=null;if(!c){b=document.createElement("div");b.innerHTML="No passages available";document.getElementById("snapbackMenu").appendChild(b)}},hideAllMenus:function(){document.getElementById("snapbackMenu").style.display="none"},showMenu:function(b,a){if(!b){b=window.event}var c={x:0,y:0};if(b.pageX||b.pageY){c.x=b.pageX;c.y=b.pageY}else{if(b.clientX||b.clientY){c.x=b.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;c.y=b.clientY+document.body.scrollTop+document.documentElement.scrollTop}}a.style.top=c.y+"px";a.style.left=c.x+"px";a.style.display="block";addClickHandler(document,Interface.hideAllMenus);b.cancelBubble=true;if(b.stopPropagation){b.stopPropagation()}}};window.onload=Interface.init;macros.back.onclick=function(back,steps){var title;if(back){if(tale.canUndo()){window.history.go(-steps);return}while(steps-->=0&&state.history.length>1){title=state.history[0].passage.title;state.history.shift()}state.loadLinkVars();state.saveVariables(tale.get(title));state.display(title,null,"back")}else{state.display(state.history[steps].passage.title)}};window.onpopstate=function(e){var title,hist,steps,i,s=e&&e.state;if(s&&s.id&&s.length!=null){hist=recompile(JSON.parse(sessionStorage.getItem("Twine.History"+s.id)));if(hist){steps=hist.length-s.length}}if(steps!=null){state.history=hist;while(steps-->=0&&state.history.length>1){title=state.history[0].passage.title;state.history.shift()}state.loadLinkVars();state.saveVariables(tale.get(title));state.display(title,null,"back")}}; testplay = ""; }());