"use strict";

function ImageLoader() {
	this.images = {};
	this.totalImages = 0;
	this.loadedImages = 0;
	this.names = [];
}
ImageLoader.prototype.load = function(name, path) {
	// only load an image once
	if (this.names.indexOf(name) > -1) {
		return;
	}
	this.names.push(name);

	this.totalImages++;

	var img = new Image();
	var self = this;
	img.addEventListener("load", function() {
		self.loadedImages++;
		self.images[name] = img;
	});
	img.addEventListener("error", function() {
		console.error("Error loading image " + path);
	});
	img.src = path;
};
ImageLoader.prototype.allLoaded = function() {
	return this.totalImages === this.loadedImages;
};
ImageLoader.prototype.get = function(name) {
	var img = this.images[name];
	if (img === undefined) {
		console.error("Unknown image: " + name);
	}
	return img;
};

module.exports = ImageLoader;

@@ -12,118 +12,895 @@
 %22;%0A%0A
-function ImageLoader() %7B%0A%09this.images = %7B%7D;%0A%09this.totalImages = 0;%0A%09this.loadedImages = 0;%0A%09this.names = %5B%5D;%0A%7D
+/**%0A * Loads %7B@link external:image%7Ds and lets you know when they're all available. This is typically handled for you by %7B@link Game%7D.%0A * @constructor%0A */%0Afunction ImageLoader() %7B%0A%09/**%0A%09 * The key-value object that stores named %7B@link external:image%7Ds%0A%09 * @member %7Bobject%7D%0A%09 * @private%0A%09 */%0A%09this.images = %7B%7D;%0A%09/**%0A%09 * The total number of images to be loaded.%0A%09 * @member %7Bnumber%7D%0A%09 * @private%0A%09 */%0A%09this.totalImages = 0;%0A%09/**%0A%09 * The number of images that have loaded completely.%0A%09 * @member %7Bnumber%7D%0A%09 * @private%0A%09 */%0A%09this.loadedImages = 0;%0A%09/**%0A%09 * The names of all the images that were requested to be loaded.%0A%09 * @member %7BArray%7D%0A%09 * @private%0A%09 */%0A%09this.names = %5B%5D;%0A%7D%0A/**%0A * Load an %7B@link external:image%7D.%0A * @param %7Bstring%7D name The name you want to use when you %7B@link ImageLoader#get%7D the %7B@link external:image%7D%0A * @param %7Bstring%7D path The path of the %7B@link external:image%7D.%0A */
 %0AIma
@@ -1327,24 +1327,106 @@
  = path;%0A%7D;%0A
+/**%0A * Test if all %7B@link external:image%7Ds have loaded.%0A * @returns %7Bboolean%7D%0A */%0A
 ImageLoader.
@@ -1511,16 +1511,183 @@
 ges;%0A%7D;%0A
+/**%0A * Retrieve a loaded %7B@link external:image%7D.%0A * @param %7Bstring%7D name The name given to the image during %7B@link ImageLoader#load%7D.%0A * @returns %7Bexternal:image%7D%0A */%0A
 ImageLoa

Add ImageLoader docs.