function Comic(a,k,d,j,g){var h=this,f=h.audio=document.createElement("audio"),b=h.canvas=document.createElement("canvas");b.width=a;b.height=k;b.style.display="none";document.body.appendChild(b);h.ctx=b.getContext("2d");h.sprites=g;h.loading=d;h.percentLoaded=document.createElement("strong");if(h.loading){h.percentLoaded.innerHTML="0%";var c=document.createElement("div");c.style.fontSize="2em";h.loading.appendChild(c);c.appendChild(h.percentLoaded);c.appendChild(document.createTextNode(" loaded."))}h.toLoad=1;h.totalToLoad=1;f.addEventListener("canplaythrough",function(){h.toLoad--;h.maybePlay()},false);f.src=j;f.autobuffer=true;document.body.appendChild(f);for(var e=0;e<g.length;e++){if(!g[e].isLoaded){h.toLoad++;g[e].whenLoaded=function(){h.toLoad--;h.maybePlay()}}h.totalToLoad++;if(g[e].greet){g[e].greet(h)}}}Comic.prototype={shouldPlay:false,play:function(){var a=this;a.shouldPlay=false;var b=location.host!=location.hostname;if(a.toLoad){a.shouldPlay=true;return}a.audio.addEventListener("timeupdate",function(){a.ctx.clearRect(0,0,a.canvas.width,a.canvas.height);for(var c=0;c<a.sprites.length;c++){a.sprites[c].renderFrame(a.canvas,a.ctx,this.currentTime)}if(b){document.title=this.currentTime}},false);a.audio.play();if(a.loading&&a.loading.parentNode){a.loading.parentNode.removeChild(a.loading)}a.canvas.style.display=""},maybePlay:function(){var a=this;a.percentLoaded.innerHTML=Math.floor((a.totalToLoad-a.toLoad)/a.totalToLoad*1000)/10+"%";if(a.toLoad){return}a.whenLoaded();if(a.shouldPlay){a.play()}},whenLoaded:function(){}};Comic.Text=function(g,f,c,i,b,h,a,d){var e=this;e.x=g;e.y=f;e.color=c;e.size=i;e.font=b;e.text=h;e.start=a;e.end=d};Comic.Text.prototype={isLoaded:true,renderFrame:function(c,b,g){var e=this,f="";if((!isNaN(e.start)&&e.start>g)||(!isNaN(e.end)&&e.end<g)){return}b.font=e.size+"px "+e.font;b.fillStyle=e.color;for(var d=0;d<e.text.length;d++){if(e.text[d].start>g){continue}if(e.text[d].end<g){f+=e.text[d].text;continue}f+=e.text[d].text.substr(0,Math.ceil((g-e.text[d].start)/(e.text[d].end-e.text[d].start)*e.text[d].text.length))}var a=f.split("\n");for(var d=0;d<a.length;d++){b.fillText(a[d],e.x,e.y+e.size*(d+1))}}};Comic.Text2=function(h,g,d,c,i,b,e){var f=this;f.x=h;f.y=g;f.color=d;f.font=c;f.text=i;f.start=b;f.end=e;var a=document.createElement("div");a.style.font=c;f.height=parseInt(document.defaultView.getComputedStyle(a,null).lineHeight)};Comic.Text2.prototype={isLoaded:true,renderFrame:function(c,b,g){var e=this,f="";if((!isNaN(e.start)&&e.start>g)||(!isNaN(e.end)&&e.end<g)){return}b.font=e.font;b.fillStyle=e.color;for(var d=0;d<e.text.length;d++){if(Math.min(e.text[d].start,e.text[d].end)>g){continue}if((e.text[d].start<=e.text[d].end&&e.text[d].end<g)||(e.text[d].start>e.text[d].end&&e.text[d].end>g)){f+=e.text[d].text;continue}f+=e.text[d].text.substr(0,(e.text[d].start<=e.text[d].end?Math.ceil:Math.floor)((g-e.text[d].start)/(e.text[d].end-e.text[d].start)*e.text[d].text.length))}var a=f.split("\n");for(var d=0;d<a.length;d++){b.fillText(a[d],e.x,e.y+e.height*(d+1))}}};Comic.Sprite=function(e,a,f,b){var d=this,c=d.image=new Image;c.addEventListener("load",function(){d.isLoaded=true;d.whenLoaded();d.cropWidth=d.width=this.width;d.cropHeight=d.height=this.height},false);c.src=e;if(!a){a=[]}d.commands=a;d.start=f;d.end=b};Comic.Sprite.prototype={isLoaded:false,lastRender:-5,x:0,y:0,width:0,height:0,cropX:0,cropY:0,cropWidth:0,cropHeight:0,alpha:1,rotation:0,move:function(f,c,d){var e=this;if(f==1){e.x=d[0];e.y=d[1];return}var b=c?d[0]-(d[0]-e.x)/(1-c):e.x,a=c?d[1]-(d[1]-e.y)/(1-c):e.y;e.x=b+(d[0]*f-b*f);e.y=a+(d[1]*f-a*f)},resize:function(f,c,d){var e=this;if(f==1){e.width=d[0];e.height=d[1];return}var b=c?d[0]-(d[0]-e.width)/(1-c):e.width,a=c?d[1]-(d[1]-e.height)/(1-c):e.height;e.width=b+(d[0]*f-b*f);e.height=a+(d[1]*f-a*f)},crop:function(h,e,f){var g=this;if(h==1){g.cropX=f[0];g.cropY=f[1];g.cropWidth=f[2];g.cropHeight=f[3];return}var d=e?f[0]-(f[0]-g.cropX)/(1-e):g.cropX,c=e?f[1]-(f[1]-g.cropY)/(1-e):g.cropY,b=e?f[2]-(f[2]-g.cropWidth)/(1-e):g.cropWidth,a=e?f[3]-(f[3]-g.cropHeight)/(1-e):g.cropHeight;g.cropX=d+(f[0]*h-d*h);g.cropY=c+(f[1]*h-c*h);g.cropWidth=b+(f[2]*h-b*h);g.cropHeight=a+(f[3]*h-a*h)},opacity:function(e,a,b){var c=this;if(e==1){c.alpha=b;return}var d=a?b-(b-c.alpha)/(1-a):c.alpha;c.alpha=d+(b*e-d*e)},rotate:function(e,a,b){var c=this;b=b*Math.PI/180;if(e==1){c.rotation=b;return}var d=a?b-(b-c.rotation)/(1-a):c.rotation;c.rotation=d+(b*e-d*e)},loop:function(e,a,c){for(var d=Math.floor(a*c.cmd.length*c.repeats),b=Math.floor(e*c.cmd.length*c.repeats)+1;d<b;d++){this[c.cmd[d%c.cmd.length].type](e*c.cmd.length*c.repeats-d,a*c.cmd.length*c.repeats-d,c.cmd[d%c.cmd.length].args)}},renderFrame:function(b,j,f){var e=this,h=+e.lastRender;if((!isNaN(e.start)&&e.start>f)||(!isNaN(e.end)&&e.end<f)){return}e.lastRender=f;for(var d=0;d<e.commands.length;d++){if(e.commands[d].start>f||e.commands[d].end<h){continue}var c=e.commands[d],a=c.start,g=c.end-a;e[c.type](g?Math.min((f-a)/g,1):1,g?Math.max((h-a)/g,0):0,c.args)}j.save();j.globalAlpha=e.alpha;if(e.rotation){j.translate(e.x+e.width/2,e.y+e.height/2);j.rotate(e.rotation);j.translate(-e.x-e.width/2,-e.y-e.height/2)}j.drawImage(e.image,e.cropX,e.cropY,e.cropWidth,e.cropHeight,e.x,e.y,e.width,e.height);j.restore()},whenLoaded:function(){}};Comic.EasterEgg=function(e,b,d,a){var c=this;c.start=e;c.end=b;c.box=d;if(a.toLoad){a.whenLoaded=function(){c.isLoaded=true;c.whenLoaded()}}else{c.isLoaded=true}c.comic=a};Comic.EasterEgg.prototype={whenLoaded:function(){},isLoaded:false,mouseX:-1,mouseY:-1,played:false,greet:function(b){var a=this;b.canvas.addEventListener("mousemove",function(c){a.mouseX=c.clientX-b.canvas.offsetLeft;a.mouseY=c.clientY-b.canvas.offsetTop;if(c.egg||a.played){return}if(a.mouseX>=a.box[0]&&a.mouseY>=a.box[1]&&a.mouseX<=a.box[2]&&a.mouseY<=a.box[3]&&a.start<=b.audio.currentTime&&a.end>=b.audio.currentTime){b.canvas.style.cursor="pointer";c.egg=true}else{b.canvas.style.cursor="default"}},false);b.canvas.addEventListener("mouseout",function(c){a.mouseX=-1;a.mouseY=-1;b.canvas.style.cursor="default"},false);b.canvas.addEventListener("click",function(c){if(!a.played&&!c.egg&&a.mouseX>=a.box[0]&&a.mouseY>=a.box[1]&&a.mouseX<=a.box[2]&&a.mouseY<=a.box[3]&&a.start<=b.audio.currentTime&&a.end>=b.audio.currentTime){c.egg=true;b.audio.pause();b.canvas.style.display="none";a.comic.play();a.played=true}},false);a.comic.audio.addEventListener("ended",function(){a.comic.canvas.style.display="none";b.canvas.style.display="";if(b.audio.currentTime<b.audio.duration){b.audio.play()}},false);a.master=b},renderFrame:function(b,a,d){var c=this;if(b.egg==d||(!c.played&&c.mouseX>=c.box[0]&&c.mouseY>=c.box[1]&&c.mouseX<=c.box[2]&&c.mouseY<=c.box[3]&&c.start<=d&&c.end>=d)){b.egg=d;c.master.canvas.style.cursor="pointer"}else{c.master.canvas.style.cursor="default"}}};Comic.HoverEgg=function(e,b,d,a){var c=this;c.start=e;c.end=b;c.box=d;if(a.toLoad){a.whenLoaded=function(){c.comic.play();c.comic.audio.pause();c.comic.canvas.style.display="none";c.isLoaded=true;c.whenLoaded()}}else{c.isLoaded=true}c.comic=a};Comic.HoverEgg.prototype={whenLoaded:function(){},isLoaded:false,mouseX:-1,mouseY:-1,greet:function(b){var a=this;b.canvas.addEventListener("mousemove",function(c){a.mouseX=c.clientX-b.canvas.offsetLeft;a.mouseY=c.clientY-b.canvas.offsetTop;if(!c.egg&&a.mouseX>=a.box[0]&&a.mouseY>=a.box[1]&&a.mouseX<=a.box[2]&&a.mouseY<=a.box[3]&&a.start<=b.audio.currentTime&&a.end>=b.audio.currentTime){b.audio.pause();b.canvas.style.display="none";a.comic.canvas.style.display="";a.comic.audio.play();c.egg=true}},false);a.comic.canvas.addEventListener("mousemove",function(c){if(a.comic.audio.paused){return}a.mouseX=c.clientX-a.comic.canvas.offsetLeft;a.mouseY=c.clientY-a.comic.canvas.offsetTop;if(a.mouseX<a.box[0]||a.mouseY<a.box[1]||a.mouseX>a.box[2]||a.mouseY>a.box[3]){a.comic.audio.currentTime=0;a.comic.audio.pause();a.comic.canvas.style.display="none";b.canvas.style.display="";if(!b.audio.ended){b.audio.play()}}},false);a.comic.canvas.addEventListener("mouseout",function(){if(a.comic.audio.paused){return}a.comic.audio.currentTime=0;a.comic.audio.pause();a.comic.canvas.style.display="none";b.canvas.style.display="";if(!b.audio.ended){b.audio.play()}},false);a.master=b},renderFrame:function(){}};Comic.Random=function(c,d){var b=this;b.time=c;b.choices=d;for(var a=0;a<b.choices.length;a++){if(!b.choices[a].isLoaded){b.toLoad++;b.choices[a].whenLoaded=function(){b.toLoad--;if(!b.toLoad){b.isLoaded=true;b.whenLoaded()}}}}if(!b.toLoad){b.isLoaded=true}};Comic.Random.prototype={oldTime:-1,isLoaded:false,toLoad:0,whenLoaded:function(){},chosen:null,renderFrame:function(b,a,d){var c=this;if(c.oldTime>d){c.oldTime=-1}if(!c.chosen||(c.time>=d&&c.oldTime<d)){c.chosen=c.choices[Math.floor(Math.random()*c.choices.length)]}c.chosen.renderFrame(b,a,d);c.oldTime=d},greet:function(c){var b=this;for(var a=0;a<b.choices.length;a++){if(b.choices[a].greet){b.choices[a].greet(c)}}}};Comic.Script=function(c,a){var b=this;b.time=c;b.script=a};Comic.Script.prototype={played:false,isLoaded:true,renderFrame:function(b,a,d){var c=this;if(!c.played&&d>c.time){c.script(c.master);c.played=true}},greet:function(a){this.master=a}}
