re = new Object;
	re.setOn = function() {}
	re.setOff = function() {}
	re.setHitSrc = function() {}
	re.setHit = function() {}
	re.getSrc = function() {}
	re.setSrc = function() {}

function RolloverEngine(pat) {
	if (pat && pat != null) {
		this.pattern = (typeof pat == "string") ? new RegExp(pat) : pat;
	} else {
		this.pattern = null;
	}

	RolloverEngine.images = new ImageCollection();
	this.ready = false;
	this.findImages();
	this.ready = true;
				
	return this;
}

RolloverEngine.prototype.findImages = function(doc) {
	if (!doc) doc = window.document;

	if (doc.images.length > 0) {
		var img, a, b;
		for (a = 0; a < doc.images.length; a++) {
			img = doc.images[a];
			if (img.name) {
				if (this.pattern == null || this.pattern.test(img.name)) {
					this.loadImage(img);
				}
			}
		}
	}

	if (doc.layers && doc.layers != null) {
		if (doc.layers.length > 0) {
			for (b = 0; b < doc.layers.length; b++) {
				this.findImages(doc.layers[b].document);
			}
		}
	}
}

RolloverEngine.prototype.loadImage = function(img) {
	if (img && img != null && img.src) {
		lastSlash = img.src.lastIndexOf("/");
		if (lastSlash == -1) lastSlash = 0;	
		lastDot = img.src.lastIndexOf(".");
		if (lastDot == -1) lastDot = img.src.length;
	
		imgLoc = (lastSlash > 0) ? img.src.substring(0, lastSlash + 1) : new String("");
		baseName = img.src.substring(lastSlash + 1, lastDot);
		ext = img.src.substring(lastDot, img.src.length);
	
		// fix for old _off naming
		offIndex = baseName.lastIndexOf("_off");
		if (offIndex != -1) {
			baseName = baseName.substring(0, offIndex);
		}
		
		img.off = new Image();
		img.off.src = img.src;
		img.on = new Image();
		img.on.src = imgLoc + baseName + "_on" + ext;
		if (window.hitPage) {
			img.hit = new Image();
			img.hit.src = imgLoc + baseName + "_hit" + ext;
		}

		RolloverEngine.images.addImage(img);
	}
}

RolloverEngine.prototype.containsImage = function(strName) {
	return (strName && strName != null) ? (RolloverEngine.images[strName] && RolloverEngine.images[strName] != null) : false;
}

RolloverEngine.prototype.getImage = function(strName) {
	return (this.containsImage(strName)) ? RolloverEngine.images[strName] : null;
}

RolloverEngine.prototype.setOff = function(strName) {
	if (this.ready) {
		img = this.getImage(strName);
		if (img && img != null && !img.locked) img.src = img.off.src;
	}
}

RolloverEngine.prototype.setOn = function(strName) {
	if (this.ready) {
		img = this.getImage(strName);
		if (img && img != null && !img.locked) img.src = img.on.src;
	}
}

RolloverEngine.prototype.setHitSrc = function(strName) {
	if (this.ready) {
		img = this.getImage(strName);
		if (img && img != null && !img.locked) img.src = img.hit.src;
		this.lock(strName);
	}
}

RolloverEngine.prototype.setHit = function(strName) {
	if (this.ready) {
		if (this.isLocked(strName)) {
			this.setOff(strName);
			eval("document.myForm."+strName+".value = 'off'");
			this.unlock(strName);
		} else {
			img = this.getImage(strName);
			if (img && img != null && !img.locked) img.src = img.hit.src;
			eval("document.myForm."+strName+".value = 'on'");
			this.lock(strName);
		}
	}
}

RolloverEngine.prototype.setAllOff = function() {
	if (this.ready) {
		for (a = 0; a < RolloverEngine.images.countImages(); a++) {
			img = RolloverEngine.images.imageAt(a);
			if (!img.locked) img.src = img.off.src;
		}
	}
}

RolloverEngine.prototype.isOff = function(strName) {
	img = RolloverEngine.images[strName];
	return (img && img != null && img.src == img.off.src);
}

RolloverEngine.prototype.isOn = function(strName) {
	img = RolloverEngine.images[strName];
	return (img && img != null && img.src == img.on.src);
}

RolloverEngine.prototype.lock = function(strName) {
	img = RolloverEngine.images[strName];
	if (img && img != null) img.locked = true;
}

RolloverEngine.prototype.lockAll = function() {
	for (i = 0; i < RolloverEngine.images.countImages(); i++) {
		RolloverEngine.images.imageAt(i).locked = true;
	}
}

RolloverEngine.prototype.unlock = function(strName) {
	img = RolloverEngine.images[strName];
	if (img && img != null) img.locked = false;
}

RolloverEngine.prototype.unlockAll = function() {
	for (j = 0; j < RolloverEngine.images.countImages(); j++) {
		RolloverEngine.images.imageAt(j).locked = false;
	}
}

RolloverEngine.prototype.isLocked = function(strName) {
	img = RolloverEngine.images[strName];
	return (img && img != null && img.locked && img.locked == true);
}

RolloverEngine.prototype.setSrc = function(strName, path) {
	if (this.ready) {
		img = this.getImage(strName);
		if (img && img != null) {
			img.src = path;
		}
	}
}

RolloverEngine.prototype.getSrc = function(strName) {
	img = this.getImage(strName);
	return img.src;
}

RolloverEngine.prototype.toString = function() {
	return "[object RolloverEngine]";
}

function ImageCollection() {
	this.images = new Array();
}

ImageCollection.prototype.addImage = function(img) {
	if (img && img != null && img.name) {
		this.images[this.images.length++] = img;
		eval("this." + img.name + " = img;");
	}
}

ImageCollection.prototype.imageAt = function(index) {
	return (index >= 0 && index < this.images.length) ? this.images[index] : null;
}

ImageCollection.prototype.countImages = function() {
	return this.images.length;
}

ImageCollection.prototype.toString = function() {
	return "[object ImageCollection]";
}
