
imgUtil = {
	
	load: function(arg, path) {
		if (!path) path = '';
		if (typeof arg == 'string') {
			var img = new Image();
			img.src = path + arg;
			return img;
		}
		else if (typeof arg == 'object' && typeof arg.length == 'number') {
			// if arg is an array replace all contained strings by an Image-Object
			for (var i = 0; i < arg.length; i++) {
				arg[i] = this.load(path + arg[i]);
			}
			return arg;
		}
		else return arg;
	}

	, setImageSrc: function(img, newImg) {
		if (typeof img == 'string') img = document.images[img];
		if (img) {
			if (typeof newImg == 'string') img.src = newImg;
			else if (typeof newImg == 'object') img.src = newImg.src;
		};
	}
};

Rollover = function(target, normal, over) {
	this.target = target;
	if (typeof this.target == 'object') {
		this.preload
		this.activate()
	}
	this.normal = normal;
	this.over = over;
	
	this.preload();
	
	Rollover.all[Rollover.all.length] = this;
}
Rollover.all = [];
Rollover.prototype.setOver = function() { imgUtil.setImageSrc(this.target, this.over) }
Rollover.prototype.setNormal = function() { imgUtil.setImageSrc(this.target, this.normal) }
Rollover.prototype.preload = function() {
	this.normal = imgUtil.load(this.normal);
	this.over = imgUtil.load(this.over);
}
Rollover.prototype.activate = function() {
	if (this.active) return;
	
	if (typeof this.target == 'string') {
		var name = this.target;
		this.target = document.images[name];
		if (!this.target) alert('Image "' + name + '" not found!');
	}
	this.target.ro = this;
	this.target.onmouseover = Rollover.overFunc;
	this.target.onmouseout = Rollover.outFunc;
	this.active = true;
}
Rollover.overFunc = function() { this.ro.setOver(); }
Rollover.outFunc = function() { this.ro.setNormal(); }

// has to be called after the onload-event
Rollover.activateAll = function() {
	for (var i = 0; i < Rollover.all.length; i++) Rollover.all[i].activate();
}