function ImageLoader(urlLoadingImage, urlNoImage, timeout, tries, instanceName) {

	this.loadingImg = new Image();
	this.loadingImg.src = urlLoadingImage;
	this.noImg = new Image();
	this.noImg.src = urlNoImage;
	
	this.imgToLoad = new Image();

	this.timeout = timeout;
	this.tries = tries;
	this.currentTry = 0;

	this.targetImg = null;
	this.imgToLoad = new Image();
	this.urlToLoad = "";
	
	this.fitIn = true;
	this.fitInX = 220;
	this.fitInY = 165;

	this.instanceName = instanceName;
	
	this.checkIfLoaded = function(obj) {
		this.currentTry++;
		if(this.imgToLoad.complete == true) {
			if(this.fitIn) {
				if(this.imgToLoad.height > this.imgToLoad.width) {
					if(this.imgToLoad.height > this.fitInY) {
						this.targetImg.height = this.fitInY;
					}
				} else {
					if(this.imgToLoad.width > this.fitInX) this.targetImg.width = this.fitInX;
				}
			}
			this.targetImg.src = this.imgToLoad.src;
			window.clearTimeout();
		} else {
			window.setTimeout(this.instanceName+".checkIfLoaded()", this.timeout);
		}
	}
	this.load = function(target, url) {
		this.currentTry = 0;
		this.targetImg = target;
		this.targetImg.src = this.loadingImg.src;
		this.urlToLoad = url;
		this.imgToLoad.src = this.urlToLoad;
		window.setTimeout(this.instanceName+".checkIfLoaded()", this.timeout);
	}
}
var imageloader = new ImageLoader("/styles/img/loading.gif", "/styles/img/noImg.gif", 300, 4,"imageloader");

