Loader=Class.create();Loader.prototype={initialize:function(c,d,b,a){this.list=c||[];this.size=c.length;this.onSuccess=d||new Function;this.onLoad=b||new Function;this.options=Object.extend({delim:"::",interval:100},(a||{}));this.rules=[{regexp:/\.js$/,factory:this.JsLoader},{regexp:/\.(?:png|jpe?g|gif)$/,factory:this.ImageLoader}]},run:function(){this.list=this.list.map(function(a){var b=this.rules.find(function(c){return a.match(c.regexp)!=null});return b?new b.factory(a,this.options):null}.bind(this)).compact();this.check()},check:function(){var a=this.size-this.list.length;this.list=this.list.reject(function(d){var c=d.isLoaded();if(c){++a;var b=Math.min(100,Math.ceil((a/this.size)*100));this.onLoad(d.path,b,a,this.size)}return c}.bind(this));if(this.list.length==0){this.onSuccess()}else{setTimeout(this.check.bind(this),this.options.interval)}},JsLoader:function(item,options){var tmp=item.split(options.delim);var path=tmp.pop();var prop=tmp.pop()||"window";var script=document.createElement("script");script.src=path;(document.getElementsByTagName("head").item(0)||document.body).appendChild(script);this.path=path;this.isLoaded=function(){try{return eval("typeof "+prop)!="undefined"}catch(e){}return false}},ImageLoader:function(b){var a=new Image();a.src=b;this.path=b;this.isLoaded=function(){return a.complete}}};
