function merge(j,d){var i;typeof d==="undefined"&&(d={});for(i in j)j.hasOwnProperty(i)&&!(i in d)&&(d[i]=j[i]);return d}var ComicBookException={INVALID_PAGE:"invalid page",INVALID_PAGE_TYPE:"invalid page type",UNDEFINED_CONTROL:"undefined control",INVALID_ZOOM_MODE:"invalid zoom mode",INVALID_NAVIGATION_EVENT:"invalid navigation event"}; function ComicBook(j,d,i){function m(){var a=window.innerHeight+1;p===!1&&(p=$(document.createElement("div")).attr("id","cb-width-shiv").css({width:"100%",position:"absolute",top:0,zIndex:"-1000"}),$("body").append(p));p.height(a);return p.innerWidth()}function x(){var a=t();a!==c&&l.indexOf(a)>-1&&(c=a,ComicBook.prototype.draw())}function t(){var a=parseInt(location.hash.substring(1),10)-1||0;if(a<0)a=location.hash=0;return a}function s(){f=document.getElementById(y);u=f.getContext("2d");v===!1&& (ComicBook.prototype.renderControls(),v=!0);f.addEventListener("click",ComicBook.prototype.navigation,!1);window.addEventListener("keydown",ComicBook.prototype.navigation,!1);window.addEventListener("hashchange",x,!1)}var y=j;this.srcs=d;var b=merge({displayMode:"double",zoomMode:"fitWidth",manga:!1,enhance:{},keyboard:{next:78,previous:80,toolbar:84,toggleLayout:76}},i),w=d.length,q=[],f,u,l=[],n=1,r=!1,v=!1,o=!1,p=!1,j=t(),c=j / "+d.length)),color:$(document.createElement("div")).attr("id", "cb-color").addClass("cb-control").append("").append($("
").slider({value:0,step:10,min:-1E3,max:1E3,change:function(a,b){ComicBook.prototype.enhance.brightness({brightness:b.value})}})).append("").append($("
").slider({value:0,step:0.001,min:0,max:1,change:function(a,b){ComicBook.prototype.enhance.brightness({contrast:b.value})}})).append("").append($("
").slider({value:0, step:0.001,min:0,max:1,change:function(a,b){ComicBook.prototype.enhance.sharpen({amount:b.value})}})).append($(document.createElement("div")).addClass("cb-option").append(" ").append("")),navigation:{left:$(document.createElement("div")).addClass("cb-control cb-navigate cb-always-on left").click(function(){b.manga==!1?ComicBook.prototype.drawPrevPage():ComicBook.prototype.drawNextPage()}), right:$(document.createElement("div")).addClass("cb-control cb-navigate cb-always-on right").click(function(){b.manga==!1?ComicBook.prototype.drawNextPage():ComicBook.prototype.drawPrevPage()})},loadingOverlay:$(document.createElement("div")).attr("id","cb-loading-overlay").addClass("cb-control")};ComicBook.prototype.renderControls=function(){$(f).before(this.getControl("loadingOverlay")).before(this.getControl("status")).after(this.getControl("toolbar").hide()).after(this.getControl("navigation").left).after(this.getControl("navigation").right).after(this.getControl("color").hide()); $(".cb-menu-button").click(function(){$(this).toggleClass("active")});$("#cb-desaturate").click(function(){$(this).is(":checked")?ComicBook.prototype.enhance.desaturate():ComicBook.prototype.enhance.resaturate()});$("#cb-reset").click(function(){$("#cb-brightness").slider("value",0);$("#cb-contrast").slider("value",0);$("#cb-saturation").slider("value",0);$("#cb-sharpen").slider("value",0);$("#cb-desaturate").attr("checked",!1);ComicBook.prototype.enhance.reset()})};ComicBook.prototype.getControl= function(a){if(typeof this.control[a]==="undefined")throw ComicBookException.UNDEFINED_CONTROL+" "+a;return this.control[a]};ComicBook.prototype.showControl=function(a){this.getControl(a).show().addClass("open")};ComicBook.prototype.hideControl=function(a){this.getControl(a).removeClass("open").hide()};ComicBook.prototype.toggleControl=function(a){this.getControl(a).toggle().toggleClass("open")};ComicBook.prototype.toggleToolbar=function(){$("#cb-toolbar").is(":visible")?$(".cb-control").not(".cb-always-on").hide(): $("#cb-toolbar, .cb-control.open").show()};ComicBook.prototype.toggleLayout=function(){b.displayMode==="double"?($("#cb-toolbar .cb-layout").removeClass("double"),b.displayMode="single"):($("#cb-toolbar .cb-layout").removeClass("single"),b.displayMode="double");$("#cb-toolbar .cb-layout").addClass(b.displayMode);ComicBook.prototype.drawPage()};ComicBook.prototype.getPage=function(a){if(a<0||a>d.length-1)throw ComicBookException.INVALID_PAGE+" "+a;if(typeof q[a]==="object")return q[a];else o=a,this.showControl("loadingOverlay")}; ComicBook.prototype.draw=function(){s();$(".cb-control.cb-navigate").outerHeight(window.innerHeight);$("#cb-toolbar").outerWidth(m());$("#cb-loading-overlay").outerWidth(m()).height(window.innerHeight);q.length!==w?this.preload():this.drawPage()};ComicBook.prototype.zoom=function(a){b.zoomMode="manual";n=a;typeof this.getPage(c)==="object"&&this.drawPage()};ComicBook.prototype.preload=function(){function a(e){var g=new Image;g.src=d[e];g.onload=function(){q[e]=this;l.push(e);$("#cb-progress-bar").progressbar("value", Math.floor(l.length/w*100));var g=b.displayMode==="double"&&c3&&h>-1?(f.push(h),h--,e=0):(f.push(d),d++),e++;for(;h>-1;)f.push(h), h--;a(f[0])})(e,d.length-1)};ComicBook.prototype.pageLoaded=function(a){return typeof l[a-1]!=="undefined"};ComicBook.prototype.drawPage=function(a){if(typeof a==="number"&&a0&&(c=a-1,!this.pageLoaded(a))){this.showControl("loadingOverlay");return}c<0&&(c=0);var e,h=0,j=0,k=ComicBook.prototype.getPage(c),a=!1;b.displayMode==="double"&&ck.height||a.width>a.height)&&b.displayMode==="double")b.displayMode="single";b.displayMode==="double"&&(g+=typeof a==="object"?a.width:g);switch(b.zoomMode){case "manual":document.body.style.overflowX="auto";e=b.displayMode==="double"?n*2:n;break;case "fitWidth":document.body.style.overflowX="hidden";n=e=m()>g?(m()-g)/m()+1:m()/g;break;default:throw ComicBookException.INVALID_ZOOM_MODE+" "+b.zoomMode;}var g=k.width*e,i=k.height*e;e=b.zoomMode==="manual"? k.width*n:g;var l=b.zoomMode==="manual"?k.height*n:i,i=l;f.width=ga.height;c>0&&(c-=b.displayMode==="single"||r?1:2,this.drawPage())};ComicBook.prototype.enhance={reset:function(a){a?delete b.enhance[a]:b.enhance={};ComicBook.prototype.drawPage()},brightness:function(a,c){c!==!1&&this.reset("brightness");var d=merge({brightness:0,contrast:0},a);b.enhance.brightness=d;Pixastic.process(f,"brightness",{brightness:d.brightness, contrast:d.contrast,legacy:!0});s()},desaturate:function(){b.enhance.desaturate={};Pixastic.process(f,"desaturate",{average:!1});s()},resaturate:function(){delete b.enhance.desaturate;ComicBook.prototype.drawPage()},sharpen:function(a){this.desharpen();a=merge({amount:0},a);b.enhance.sharpen=a;Pixastic.process(f,"sharpen",{amount:a.amount});s()},desharpen:function(){delete b.enhance.sharpen;ComicBook.prototype.drawPage()}};ComicBook.prototype.navigation=function(a){if($("#cb-loading-overlay").is(":visible"))return!1; var c=!1;switch(a.type){case "click":ComicBook.prototype.toggleToolbar();break;case "keydown":a.keyCode===b.keyboard.previous&&(c="left");a.keyCode===b.keyboard.next&&(c="right");a.keyCode===b.keyboard.toolbar&&ComicBook.prototype.toggleToolbar();a.keyCode===b.keyboard.toggleLayout&&ComicBook.prototype.toggleLayout();break;default:throw ComicBookException.INVALID_NAVIGATION_EVENT+" "+a.type;}if(c)return a.stopPropagation(),b.manga?(c==="left"&&ComicBook.prototype.drawNextPage(),c==="right"&&ComicBook.prototype.drawPrevPage()): (c==="left"&&ComicBook.prototype.drawPrevPage(),c==="right"&&ComicBook.prototype.drawNextPage()),!1}};