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