/* ----------------------------------
preloader.js
---------------------------------- */

var Loader = function(list, completeHandler, progressHandler)
{
	var imgsum = list.length;
	var imgList = [];
	var count = 0;
	var onLoading = function(num)
	{
		count++;
		imgList[num].onload = null;
		imgList[num] = null;
		if(progressHandler) progressHandler(Math.round(count / imgsum * 100));
		if(count >= imgsum) if(completeHandler) completeHandler.apply();
	}
	
	this.load = function()
	{
		if(!document.images) return;
		for(var i = 0; i < list.length; i++)
		{
			imgList[i] = new Image();
			imgList[i].num = i;
			imgList[i].onload = function()
			{
				onLoading(this.num);
			};
			imgList[i].src = list[i];
		}
	}
}
