JS-ImgPreloader

function imgsPreload(images){
	var _images = [], _loadedImages = 0;
	var _onAllLoaded = function(){};
	var _onAllLoadedCheck = function(){
	_loadedImages++;
	if(_loadedImages == _images.length){
		_onAllLoaded(_images);
		}
	}
	var images =(typeof images!=”object”)? [images] : images;
	for (var i=0; i < images.length; i++){
		_images[i] = new Image();
		_images[i].src = images[i];
		_images[i].onload = function(){
		_onAllLoadedCheck();
		}
		_images[i].onerror = function(){
		_onAllLoadedCheck();
		console.log(‘Error : Loading image’);
		}
	}
	return{ // call back on done();
		done:function(f){
			_onAllLoaded = f;
		}	
	}
}

//preload one images:
imgsPreload(['http://s18.postimg.org/ei6ztt7q1/BUMAY13_01_A_small.jpg']).done(function(para1){
	alert(para1.length);
	alert(para1[0].src + ” ” + para1[0].width);
});