var Asset={javascript:function(source,properties){if(!properties){properties={}}var script=new Element("script",{src:source,type:"text/javascript"}),doc=properties.document||document,load=properties.onload||properties.onLoad;delete properties.onload;delete properties.onLoad;delete properties.document;if(load){if(typeof script.onreadystatechange!="undefined"){script.addEvent("readystatechange",function(){if(["loaded","complete"].contains(this.readyState)){load.call(this)}})}else{script.addEvent("load",load)}}return script.set(properties).inject(doc.head)},css:function(source,properties){if(!properties){properties={}}var link=new Element("link",{rel:"stylesheet",media:"screen",type:"text/css",href:source});var load=properties.onload||properties.onLoad,doc=properties.document||document;delete properties.onload;delete properties.onLoad;delete properties.document;if(load){link.addEvent("load",load)}return link.set(properties).inject(doc.head)},image:function(source,properties){if(!properties){properties={}}var image=new Image(),element=document.id(image)||new Element("img");["load","abort","error"].each(function(name){var type="on"+name,cap="on"+name.capitalize(),event=properties[type]||properties[cap]||function(){};delete properties[cap];delete properties[type];image[type]=function(){if(!image){return}if(!element.parentNode){element.width=image.width;element.height=image.height}image=image.onload=image.onabort=image.onerror=null;event.delay(1,element,element);element.fireEvent(name,element,1)}});image.src=element.src=source;if(image&&image.complete){image.onload.delay(1)}return element.set(properties)},images:function(sources,options){sources=Array.from(sources);var fn=function(){},counter=0;options=Object.merge({onComplete:fn,onProgress:fn,onError:fn,properties:{}},options);return new Elements(sources.map(function(source,index){return Asset.image(source,Object.append(options.properties,{onload:function(){counter++;options.onProgress.call(this,counter,index,source);if(counter==sources.length){options.onComplete()}},onerror:function(){counter++;options.onError.call(this,counter,index,source);if(counter==sources.length){options.onComplete()}}}))}))}};