﻿function ImagePreloader(groups)
{
	this.Groups = groups;	
}

ImagePreloader.prototype.Preload = function()
{
	var group = null;
	var current = null;
	
	for(var i = 0; i < this.Groups.length; i++)
	{
		var group = this.Groups[i];
		
		if(group instanceof ImagePreloadGroup)
		{	
			for(var j = 0; j < group.Images.length; j++)
			{				
				group.Prefixes.unshift('');
				
				for(k = 0; k < group.Prefixes.length; k++)
				{
					eval(
						"var image" + (i.toString() + '_' + j.toString()) + " = new Image();" +
						"image" + (i.toString() + '_' + j.toString()) + ".src = '" + group.GetImage(j, group.Prefixes[k]) + "';"
					);					
				}
			}
		}		
	}	
}

function ImagePreloadGroup(rootPath, images, prefixes, extension)
{
	this.RootPath	= rootPath;
	this.Images		= images;
	this.Prefixes	= prefixes;
	this.Extension	= (typeof(extension) != 'undefined' ? extension : '.gif');
}

ImagePreloadGroup.prototype.GetImage = function(position, prefix)
{
	return this.RootPath + this.Images[position] + prefix + this.Extension;
}

//Array.prototype.ForEach = function(handler)
//{
//	for(var i = 0; i < this.length; i++)
//		handler(this[i]);
//}