jade.require("jade.Application");jade.ImagePreloader=function(B){jade.Object.call(this);
if(!jade.application.isLoaded()){jade.application.connect("load",this.handleAppLoad,this)
}else{this.ready=true}this.imageURLs={};this.imageObjects={};if(B){this.autoStart=false
}};jade.inherit(jade.ImagePreloader,jade.Object);jade.ImagePreloader.prototype.ready=false;
jade.ImagePreloader.prototype.imageURLs=null;jade.ImagePreloader.prototype.imageObjects=null;
jade.ImagePreloader.prototype.loading=false;jade.ImagePreloader.prototype.autoStart=true;
jade.ImagePreloader.prototype.handleAppLoad=function(){this.ready=true;if(this.autoStart){this.start()
}};jade.ImagePreloader.prototype.start=function(){var C,D;if(this.ready){for(C in this.imageURLs){D=this.imageURLs[C];
if(!D){this.loadImage(C)}}}else{this.autoStart=true}this.checkComplete()};jade.ImagePreloader.prototype.loadImage=function(B){if(this.imageObjects[B]){return false
}this.imageObjects[B]=document.createElement("img");this.imageObjects[B].jadeImagePreloader=this;
this.imageObjects[B].onload=this.handleImgLoad;this.imageObjects[B].onerror=this.handleImgError;
this.imageObjects[B].relativeURL=B;this.imageObjects[B].style.position="absolute";
this.imageObjects[B].style.visibility="hidden";this.imageObjects[B].style.width="1px";
this.imageObjects[B].style.height="1px";document.body.appendChild(this.imageObjects[B]);
this.imageObjects[B].src=B};jade.ImagePreloader.prototype.addImageURL=function(B){if(this.imageURLs[B]){return false
}if(this.imageURLs[B]===0){return true}this.imageURLs[B]=0;if(!this.loading){this.loading=true;
this.sendSignal("loading")}if(this.ready&&this.autoStart){this.loadImage(B)}return true
};jade.ImagePreloader.prototype.handleImgLoad=function(E,D){var F;if(this.jadeImagePreloader){return this.jadeImagePreloader.handleImgLoad(E?E:event,this)
}F=D.relativeURL;this.imageURLs[F]=1;document.body.removeChild(D);this.imageObjects[F]=null;
this.sendSignal("load",F);this.checkComplete()};jade.ImagePreloader.prototype.handleImgError=function(E,D){var F;
if(this.jadeImagePreloader){return this.jadeImagePreloader.handleImgError(E?E:event,this)
}F=D.relativeURL;this.imageURLs[F]=2;document.body.removeChild(D);this.imageObjects[F]=null;
this.sendSignal("error",F);this.checkComplete()};jade.ImagePreloader.prototype.checkComplete=function(){var B;
for(B in this.imageURLs){if(!this.imageURLs[B]){return false}}this.loading=false;
this.sendSignal("completed");return true};jade.ImagePreloader.prototype.setAutoStart=function(B){this.autoStart=B
};jade.ImagePreloader.prototype.cancelLoading=function(){var B;if(this.loading){for(B in this.imageObjects){if(this.imageObjects[B]){if(this.imageURLs[B]<2){this.imageURLs[B]=0
}this.imageObjects[B].onload=null;this.imageObjects[B].onerror=null;document.body.removeChild(this.imageObjects[B]);
this.imageObjects[B]=null}}this.imageObjects={};this.loading=false;this.sendSignal("canceled")
}};