var imageQueue = {

	images: [],
	loaded: [],
	loading: false,
	onComplete: null,

	load: function(imageArray)
	{
		for(var i = 0, l = imageArray.length; i < l; i++)
		{
			var src = imageArray[i];
			if(jQuery.inArray(src, this.images) == -1)
			{
				this.images.push(src);
				this.loaded.push(false);
			}
		}

		if(!this.loading)
			this._loadImage();
	},

	onFinish: function(callback)
	{
		this.onComplete = callback;

		if(!this.loading)
			this._loadImage();
	},

	_loadImage: function()
	{
		this.loading = true;

		for(var i = 0, l = this.loaded.length; i < l; i++)
			if(!this.loaded[i])
				break;

		if(i != l)
		{
			var img = new Image();
			var that = this;

			$(img).load(function()
			{
				that.loaded[i] = true;
				that.images[i] = img;	// replace image URL with an actual image

				that._loadImage();
			})
			.attr("src", this.images[i]);
		}
		else
		{
			this.loading = false;

			if(this.onComplete)
				this.onComplete();
		}
	}
};