
function RolloverEngine(pat){
	if(pat && pat != null)
		this.pattern = (typeof pat == "string") ? new RegExp(pat) : pat;
	else 
		this.pattern = null;		
	this.rollovers = new ImageCollection();
	this.ready = false;
	if(this.dummyRe == 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.over = new Image();
		img.over.src = imgLoc + baseName + "_over" + ext;
		img.on = new Image();
		img.on.src = imgLoc + baseName + "_on" + ext;	
			//alert(img.on.src)		
		this.rollovers.addImage(img);
	}
}

RolloverEngine.prototype.containsImage = function(strName){
	return (strName && strName != null) ? (this.rollovers[strName] && this.rollovers[strName] != null) : false;
}

RolloverEngine.prototype.getImage = function(strName){
	return (this.containsImage(strName)) ? this.rollovers[strName] : null;
}

RolloverEngine.prototype.setOff = function(strName){	
		img = this.getImage(strName);
		if(img && img != null && this.ready) img.src = img.off.src;
}

RolloverEngine.prototype.setOver = function(strName){
	img = this.getImage(strName);
	if(img && img != null && this.ready) img.src = img.over.src;
}

RolloverEngine.prototype.setOn = function(strName){
		img = this.getImage(strName);
		if(img && img != null && this.ready) img.src = img.on.src;
}
RolloverEngine.prototype.setSrc = function(strName, path)
{		 img = this.getImage(strName);
		 if(img && img != null && this.ready) img.src = path;
}

function ImageCollection() {}

ImageCollection.prototype = new Array();

ImageCollection.prototype.addImage = function(img){
	if(img && img != null && img.name){
		this[this.length] = img;
		eval("this." + img.name + " = img;");
	}
}

ImageCollection.prototype.toString = function(){
	return "[object ImageCollection]";
}

RolloverEngine.prototype.dummyRe = false;

re = new RolloverEngine(true);