function imageList(onCompl,onComplListener)
{
	this.list=Array();
	this.onCompl=onCompl;
	this.onComplListener=onComplListener;
	this.hasStarted=false;
	this.errors=Array();
	
	this.getCount=function()
	{
		return this.list.length;
	}
	
	this.newImage=function()
	{
		var img=new Image();
		$(img).addEvent("load",this.onComplete.bind(this,this.list.length));
		$(img).addEvent("error",this.onError.bind(this,this.list.length));
		this.list[this.list.length]=img;
		this.errors[this.errors.length]=false;
		return img;
	}
	
	this.onError=function(ii)
	{
		this.errors[ii]=true;
		this.onComplete(ii);
	}
	
	this.onComplete=function(ii)
	{
		if(this.onComplListener) this.onComplListener(this.list[ii]);
		if(this.complete(ii)===true && this.hasStarted===false) 
		{
			this.hasStarted=true;
			setTimeout(this.onCompl,200);
		}
	}
	
	this.complete=function(isLoadedId)
	{
		for(var i=0;i<this.list.length;i++)
		{
			if(this.list[i].complete===false && this.errors[i]===false && isLoadedId!=i) 
			{
				return false;
			}
		}
		return true;
	}
}

//resize an image
function resize(x,y,xmax,ymax)
{
	var xr,yr;
	var prop=xmax/ymax;
	if(prop<1 || y/(x/xmax)>ymax) 
	{
		yr=ymax;
		xr=x/(y/ymax);
	}
	else
	{
		xr=xmax;
		yr=y/(x/xmax);
	}
	return {width: Math.round(xr),height: Math.round(yr)};
}
