/*
 * Parchment
 * Built: 2010-04-29
 *
 * Copyright (c) 2003-2010 The Parchment Contributors
 * Licenced under the GPL v2
 * http://code.google.com/p/parchment
 */
$.ajaxSetup({cache:true,dataType:"text",ifModified:location.protocol!=="file:"});var parchment={options:{default_story:"stories/troll.z5.js",lib_path:"lib/",page_title:1,proxy_url:"http://zcode.appspot.com/proxy/"},lib:{}};
/*
 * Simple JavaScript Inheritance
 * http://ejohn.org/blog/simple-javascript-inheritance/
 *
 * By John Resig
 * Released into the public domain?
 *
 * Inspired by base2 and Prototype
 */
(function(){var a=false,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.Class=function(){};Class.extend=function(g){var f=this.prototype;a=true;var e=new this();a=false;for(var d in g){e[d]=typeof g[d]=="function"&&typeof f[d]=="function"&&b.test(g[d])?(function(h,i){return function(){var k=this._super;this._super=f[h];var j=i.apply(this,arguments);this._super=k;return j}})(d,g[d]):g[d]}function c(){if(!a&&this.init){this.init.apply(this,arguments)}}c.prototype=e;c.constructor=c;c.extend=arguments.callee;return c}})();
/*
 * Interchange File Format library
 *
 * Copyright (c) 2003-2009 The Gnusto Contributors
 * Licenced under the GPL v2
 * http://github.com/curiousdannii/gnusto
 */
(function(){function c(i,j){return i[j]<<24|i[j+1]<<16|i[j+2]<<8|i[j+3]}function d(i){return[(i>>24)&255,(i>>16)&255,(i>>8)&255,i&255]}function f(j,k){var i=String.fromCharCode;return i(j[k])+i(j[k+1])+i(j[k+2])+i(j[k+3])}function h(i){return[i.charCodeAt(0),i.charCodeAt(1),i.charCodeAt(2),i.charCodeAt(3)]}var b="FORM",g=Class.extend({init:function a(m){this.type="";this.chunks=[];if(m){if(f(m,0)!=b){throw new Error("Not an IFF file")}this.type=f(m,8);var k=12,j=m.length;while(k<j){var n=c(m,k+4);if(n<0||(n+k)>j){throw new Error("IFF: Chunk out of range")}this.chunks.push({type:f(m,k),offset:k,data:m.slice(k+8,k+8+n)});k+=8+n;if(n%2){k++}}}},write:function e(){var n=h(this.type);for(var o=0,k=this.chunks.length;o<k;o++){var m=this.chunks[o],p=m.data,j=p.length;n=n.concat(h(m.type),d(j),p);if(j%2){n.push(0)}}return h(b).concat(d(n.length),n)}});g.num_from=c;g.num_to_word=d;g.text_from=f;g.text_to_word=h;window.IFF=g})();
/*
(c) Copyrights 2007 - 2008

Original idea by by Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
 
jQuery Plugin by Tzury Bar Yochay 
tzury.by@gmail.com
http://evalinux.wordpress.com
http://facebook.com/profile.php?id=513676303

Project's sites: 
http://code.google.com/p/js-hotkeys/
http://github.com/tzuryby/hotkeys/tree/master

License: same as jQuery license. 
*/
(function(b){b.fn.__bind__=b.fn.bind;b.fn.__unbind__=b.fn.unbind;b.fn.__find__=b.fn.find;var a={version:"0.7.8",override:/keydown|keypress|keyup/g,triggersMap:{},specialKeys:{27:"esc",9:"tab",32:"space",13:"return",8:"backspace",145:"scroll",20:"capslock",144:"numlock",19:"pause",45:"insert",36:"home",46:"del",35:"end",33:"pageup",34:"pagedown",37:"left",38:"up",39:"right",40:"down",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12"},shiftNums:{"`":"~","1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")","-":"_","=":"+",";":":","'":'"',",":"<",".":">","/":"?","\\":"|"},newTrigger:function(e,d,f){var c={};c[e]={};c[e][d]={cb:f,disableInInput:false};return c}};if(b.browser.mozilla){a.specialKeys=b.extend(a.specialKeys,{96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9"})}b.fn.find=function(c){this.query=c;return b.fn.__find__.apply(this,arguments)};b.fn.unbind=function(h,e,g){if(b.isFunction(e)){g=e;e=null}if(e&&typeof e==="string"){var f=((this.prevObject&&this.prevObject.query)||(this[0].id&&this[0].id)||this[0]).toString();var d=h.split(" ");for(var c=0;c<d.length;c++){delete a.triggersMap[f][d[c]][e]}}return this.__unbind__(h,g)};b.fn.bind=function(j,f,k){var h=j.match(a.override);if(b.isFunction(f)||!h){return this.__bind__(j,f,k)}else{var n=null,i=b.trim(j.replace(a.override,""));if(i){n=this.__bind__(i,f,k)}if(typeof f==="string"){f={combi:f}}if(f.combi){for(var m=0;m<h.length;m++){var d=h[m];var g=f.combi.toLowerCase(),e=a.newTrigger(d,g,k),l=((this.prevObject&&this.prevObject.query)||(this[0].id&&this[0].id)||this[0]).toString();e[d][g].disableInInput=f.disableInInput;if(!a.triggersMap[l]){a.triggersMap[l]=e}else{if(!a.triggersMap[l][d]){a.triggersMap[l][d]=e[d]}}var c=a.triggersMap[l][d][g];if(!c){a.triggersMap[l][d][g]=[e[d][g]]}else{if(c.constructor!==Array){a.triggersMap[l][d][g]=[c]}else{a.triggersMap[l][d][g][c.length]=e[d][g]}}this.each(function(){var o=b(this);if(o.attr("hkId")&&o.attr("hkId")!==l){l=o.attr("hkId")+";"+l}o.attr("hkId",l)});n=this.__bind__(h.join(" "),f,a.handler)}}return n}};a.findElement=function(c){if(!b(c).attr("hkId")){if(b.browser.opera||b.browser.safari){while(!b(c).attr("hkId")&&c.parentNode){c=c.parentNode}}}return c};a.handler=function(e){var o=a.findElement(e.currentTarget),i=b(o),d=i.attr("hkId");if(d){d=d.split(";");var g=e.which,q=e.type,p=a.specialKeys[g],n=!p&&String.fromCharCode(g).toLowerCase(),h=e.shiftKey,c=e.ctrlKey,m=e.altKey||e.originalEvent.altKey,f=null;for(var r=0;r<d.length;r++){if(a.triggersMap[d[r]][q]){f=a.triggersMap[d[r]][q];break}}if(f){var j;if(!h&&!c&&!m){j=f[p]||(n&&f[n])}else{var l="";if(m){l+="alt+"}if(c){l+="ctrl+"}if(h){l+="shift+"}j=f[l+p];if(!j){if(n){j=f[l+n]||f[l+a.shiftNums[n]]||(l==="shift+"&&f[a.shiftNums[n]])}}}if(j){var s=false;for(var r=0;r<j.length;r++){if(j[r].disableInInput){var k=b(e.target);if(i.is("input")||i.is("textarea")||k.is("input")||k.is("textarea")){return true}}s=s||j[r].cb.apply(this,[e])}return s}}}};window.hotkeys=a;return b})(jQuery);function Querystring(a){this.params={};this.get=Querystring_get;if(a==null){}a=location.search.substring(1,location.search.length);if(a.length==0){return}a=a.replace(/\+/g," ");var c=a.split("&");for(var d=0;d<c.length;d++){var f=c[d].split("=");var b=unescape(f[0]);var e=(f.length==2)?unescape(f[1]):b;this.params[b]=e}}function Querystring_get(a,b){var c=this.params[a];return(c!=null)?c:b}
/*
 * Taken from "Remedial Javascript" by Douglas Crockford:
 * http://javascript.crockford.com/remedial.html
 */
function typeOf(b){var a=typeof b;if(a==="object"){if(b){if(typeof b.length==="number"&&!(b.propertyIsEnumerable("length"))&&typeof b.splice==="function"){a="array"}}else{a="null"}}return a}function isEmpty(c){var b,a;if(typeOf(c)==="object"){for(b in c){a=c[b];if(a!==undefined&&typeOf(a)!=="function"){return false}}}return true}String.prototype.entityify=function(){return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")};String.prototype.quote=function(){var e,b,a=this.length,d='"';for(b=0;b<a;b+=1){e=this.charAt(b);if(e>=" "){if(e==="\\"||e==='"'){d+="\\"}d+=e}else{switch(e){case"\b":d+="\\b";break;case"\f":d+="\\f";break;case"\n":d+="\\n";break;case"\r":d+="\\r";break;case"\t":d+="\\t";break;default:e=e.charCodeAt();d+="\\u00"+Math.floor(e/16).toString(16)+(e%16).toString(16)}}}return d+'"'};String.prototype.supplant=function(a){return this.replace(/{([^{}]*)}/g,function(d,c){var e=a[c];return typeof e==="string"||typeof e==="number"?e:d})};String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")};function FatalError(a){this.message=a;this.traceback=this._makeTraceback(arguments.callee);this.onError(this)}FatalError.prototype={onError:function(b){var a=b.message;if(typeof b.message=="string"){a=a.entityify()}$("#content").append('<div class="error">An error occurred:<br/><pre>'+a+"\n\n"+b.traceback+"</pre></div>")},_makeTraceback:function(a){var d="";var c=0;var b=100;while(a!=null&&c<b){var f=a.toString();if(!f){d="\n  (anonymous function)"+d}else{var g=f.match(/function (\w*)/);if(!g||!g[1]){d="\n  (anonymous function)"+d}else{d="\n  "+g[1]+d}}try{a=a.caller}catch(h){a=null}c++}if(c==b){d="..."+d}return"Traceback (most recent call last):\n"+d}};(function(e){function a(n,o){var o=o||[],m=0,k;for(k=n.length%8;m<k;++m){o.push(n.charCodeAt(m)&255)}for(k=n.length;m<k;){o.push(n.charCodeAt(m++)&255,n.charCodeAt(m++)&255,n.charCodeAt(m++)&255,n.charCodeAt(m++)&255,n.charCodeAt(m++)&255,n.charCodeAt(m++)&255,n.charCodeAt(m++)&255,n.charCodeAt(m++)&255)}return o}function i(p,o){var o=o||"",n=0,k,m=String.fromCharCode;for(k=p.length%8;n<k;++n){o+=m(p[n])}for(k=p.length;n<k;){o+=(m(p[n++])+m(p[n++])+m(p[n++])+m(p[n++])+m(p[n++])+m(p[n++])+m(p[n++])+m(p[n++]))}return o}if(e.atob){var c=function(l,k){return a(atob(l),k)},g=function(l,k){return btoa(i(l,k))}}else{var f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",b=(function(){var k=[],l=0;for(;l<f.length;l++){k[f.charAt(l)]=l}return k})(),c=function(q,o){var o=o||[],r,n,m,v,u,t,s,p=0,k=q.length;while(p<k){v=b[q.charAt(p++)];u=b[q.charAt(p++)];t=b[q.charAt(p++)];s=b[q.charAt(p++)];r=(v<<2)+(u>>4);n=((u&15)<<4)+(t>>2);m=((t&3)<<6)+s;o.push(r,n,m)}if(s==64){o.pop()}if(t==64){o.pop()}return o},g=function(q,o){var o=o||"",r,n,m,v,u,t,s,p=0,k=q.length;while(p<k){r=q[p++];n=q[p++];m=q[p++];v=r>>2;u=((r&3)<<4)+(n>>4);t=((n&15)<<2)+(m>>6);s=m&63;o+=(f.charAt(v)+f.charAt(u)+f.charAt(t)+f.charAt(s))}if(isNaN(n)){o=o.slice(0,-2)+"=="}else{if(isNaN(m)){o=o.slice(0,-1)+"="}}return o}}var j=jQuery.ajaxSettings.xhr(),h={binary:j.overrideMimeType!==undefined&&!$.browser.opera,cross_origin:j.withCredentials!==undefined};j=null;function d(o,r){var n=/^(file:|(\w+:)?\/\/[^\/?#]+)/,p;if($.isArray(o)){p=o[1];o=o[0]}var m=n.exec(location)[0],q=n.exec(o),k=q?q[0]:m,l={};if(k=="file:"&&(m!=k||(!h.binary&&!p))){throw"Can't load local files with this browser, sorry!"}if(o.slice(-3).toLowerCase()==".js"){e.processBase64Zcode=function(s){r(c(s));delete e.processBase64Zcode};$.getScript(o);return}if(h.binary&&m==k){l={beforeSend:function(s){s.overrideMimeType("text/plain; charset=x-user-defined")},success:function(s){r(a($.trim(s)))},url:o}}else{if(m==k&&p){l.url=p}else{l={data:{encode:"base64",url:o},dataType:"jsonp",url:parchment.options.proxy_url}}l.success=function(s){r(c($.trim(s)))}}l.error=function(s,t){throw new FatalError("Error loading story: "+t)};$.ajax(l)}e.file={text_to_array:a,array_to_text:i,base64_decode:c,base64_encode:g,download_to_array:d,support:h}})(window);(function(){window.gIsIphone=navigator.userAgent.match(/iPhone|iPod|iPad|Android/i);var b;var a="0";$(document).ready(function(){b=document.getElementById("top-window");a="0";var d=navigator.appVersion.match(/MSIE (\d+)\./);if(d&&+d[1]<7){b.style.position="absolute";var c=function(){b.style.top=1*(document.documentElement.scrollTop+1*a)+"px"};window.onscroll=c;window.onresize=c}})})();(function(e){var g=IFF.extend({init:function a(o,j){this.title=j;if(o[0]<9){this.filetype="ok story naked zcode";this._super();this.chunks.push({type:"ZCOD",data:o});this.zcode=o}else{if(IFF.text_from(o,0)=="FORM"){this._super(o);if(this.type=="IFRS"){for(var m=0,h=this.chunks.length;m<h;m++){var n=this.chunks[m].type;if(n=="ZCOD"&&!this.zcode){this.zcode=this.chunks[m].data}else{if(n=="IFmd"){this.metadata=file.array_to_text(this.chunks[m].data);var k=$(this.metadata);if(k){if($("title",k)){this.title=$("title",k).text()}if($("ifid",k)){this.ifid=$("ifid",k).text()}if($("release",k)){this.release=$("release",k).text()}}}}}if(this.zcode){this.filetype="ok story blorbed zcode"}else{this.filetype="error: no zcode in blorb"}}else{if(this.type=="IFZS"){this.filetype="error: trying to load a Quetzal savefile"}else{this.filetype="error unknown iff"}}}else{this.filetype="error unknown general"}}},load:function b(h){if(this.zcode){h.loadStory(this.zcode)}}}),d=Class.extend({add:function(h){this[h.ifid]=h;if(h.url){this.url[h.url]=h}},url:{}}),c=function(j,i){var k,l=1,o,h=parchment.options.lib_path,n=function(p){if($.isArray(p)){k=p}if(--l==0){o=setInterval(m,10)}},m=function(){if(i.loaded_zmachine||e.GnustoEngine&&e.Quetzal&&e.EngineRunner&&e.Console&&e.WebZui&&k){i.loaded_zmachine=true;clearInterval(o);$("#progress-text").html("Starting interpreter...");var u=typeof console!==undefined?function(){}:function(v){e.console.log(v)},r=new GnustoEngine(u),q=new WebZui(i,r,u),t=new EngineRunner(r,q,u),s=new g(k,storyName),p=location.hash;u("Story type: "+s.filetype);s.load(r);if(p&&p!="#"){r.loadSavedGame(file.base64_decode(p.slice(1)));u("Loading savefile")}t.run()}};if(!i.loaded_zmachine){l=3;$.getScript(h+"gnusto.min.js",n);$.getScript(h+"zmachine.min.js",n)}file.download_to_array(j,n)},f=Class.extend({load:function(n){var j=parchment.options,h=new Querystring(),l=h.get("story",j.default_story),i=$.isArray(l)?l[0]:l;this.url=i;storyName=i.slice(i.lastIndexOf("/")+1);storyName=storyName?storyName+" - Parchment":"Parchment";if(j.page_title){e.document.title=storyName}if(this.stories.url[i]){var k=this.stories.url[i]}else{$("#progress-text").html("Retrieving story file...");try{c(l,this)}catch(m){throw new FatalError(m)}}},stories:new d(),savefiles:{}});e.Library=f})(window);(function(a){var c=a.parchment;function b(){if(a.parchment_options){$.extend(c.options,parchment_options)}var d=new Library();c.library=d;d.load();if(location.href.slice(0,31)=="http://parchment.googlecode.com"){$.getScript("http://www.google-analytics.com/ga.js",function(){gat._getTracker("UA-7949545-1")._trackPageview()})}}$(b)})(window);
