function smartImage(id, filename, description, manager) {
	this.id = id;
	this.filename = filename;
	this.description = description;
	this.loadedimage = null;
	this.manager = manager;
}

smartImage.prototype.loaded = function() {return (this.loadedimage != null);}

smartImage.prototype.load = function() {
	if (this.loadedimage == null) {
	  this.loadedimage = new Image();
	  this.loadedimage.src = this.manager.getImagePath() + this.filename;
	  this.loadedimage.alt = this.description;
	}
}

smartImage.prototype.src = function() {this.load(); return this.loadedimage.src;}
smartImage.prototype.alt = function() {this.load(); return this.loadedimage.alt;}

function imageManager(imagePath) {
	this.imagePath = imagePath;
	this.imageIDIndex = [];
	this.imageArray = [];
	this.imageArrayInitiated = false;
	this.imageArrayLoaded = false;
	this.postLoadIdleDuration = 200;
	this.postLoadCountDown = this.postLoadIdleDuration;
	this.postLoadImageNo = 0;
}

imageManager.prototype.getImagePath = function() { return this.imagePath; }

imageManager.prototype.addSmartImage = function(id, filename, description, load) {
	var i = this.imageArray.length;
	this.imageIDIndex[id] = i;
	this.imageArray[i] = new smartImage(id, filename, description, this);
	if (load) this.imageArray[i].load(); 
}

imageManager.prototype.getSmartImageById = function(id) { return this.imageArray[this.imageIDIndex[id]]; }
imageManager.prototype.isInitiated = function() { return this.imageArrayInitiated; }
imageManager.prototype.isLoaded = function() { return this.imageArrayLoaded; }

imageManager.prototype.initTimer = function() {
	var locURL = location.href;	    
	this.imagePath = locURL.substr(0, locURL.lastIndexOf('/')) + this.imagePath.substr(this.imagePath.indexOf('/'));
	this.imageArrayInitiated = true;
}

imageManager.prototype.timerEvent = function(timeInterval) {
	if (!this.imageArrayLoaded) {
          this.postLoadCountDown -= timeInterval;
          if (this.postLoadCountDown <= 0) {
	    var loadno = -1;
	    for (var i in this.imageArray) {
	      if (!this.imageArray[i].loaded()) {
	        loadno = i;
	        i = this.imageArray.length;
	      }
	    }
	    if (loadno >= 0) {
	      this.imageArray[loadno].load();
	      this.postLoadCountDown = this.postLoadIdleDuration;
	    } else {
	      this.imageArrayLoaded = true;
	    }
	  }	  
	} 
}