
re = new RollcallEngine();

function RollcallEngine() {
	//browser brand and version flags
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
    this.ns6=(this.dom && parseInt(this.ver) >= 6) ?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5);
	
	//functionality flags
	this.useOverState = true;
	this.useOnState = true;
	
	//registration object reference
	this.RollImages = new Object();
	
	this.lastImage = "";
}

RollcallEngine.prototype.register = function(obj) {
	if ((obj.name == "") && (obj.id != "")) {
		obj.name = obj.id;						 
	}
	
	if ((obj.name != "") && (typeof(this.RollImages[obj.name]) == "undefined")) {
		lastSlash = obj.src.lastIndexOf("/");
		if(lastSlash < 0) lastSlash = 0;
	
		lastDot = obj.src.lastIndexOf(".");
		if(lastDot <0) lastDot = obj.src.length;
		
		imgLoc = (lastSlash > 0) ? obj.src.substring(0, lastSlash + 1) : new String("");
		baseName = obj.src.substring(lastSlash + 1, lastDot);
		ext = obj.src.substring(lastDot, obj.src.length);

		//if underscore extensions (_off, _over, _on) are used in source path, make sure it is omitted from other image paths
		offIndex = baseName.lastIndexOf("_off.");
		if(offIndex != -1) baseName = baseName.substring(0, offIndex);

		overIndex = (baseName + ".").lastIndexOf("_over.");
		if(overIndex != -1) baseName = baseName.substring(0, overIndex);
		
		onIndex = (baseName + ".").lastIndexOf("_on.");
		if(onIndex != -1) baseName = baseName.substring(0, onIndex);
		
		this.RollImages[obj.name] = new Object();
		
		this.RollImages[obj.name].ref = obj;
		
		this.RollImages[obj.name].off = new Image();
		this.RollImages[obj.name].off.src = obj.src;


		if (this.useOverState){
			this.RollImages[obj.name].over = new Image();
			this.RollImages[obj.name].over.src = imgLoc + baseName + "_over" + ext;
		}
		
		if (this.useOnState) {
			this.RollImages[obj.name].on = new Image();
			this.RollImages[obj.name].on.src = imgLoc + baseName + "_on" + ext;
		}
	}
}

RollcallEngine.prototype.reRegister = function(name) {
	delete (this.RollImages[name]);
	
	this.register(this.getReference(name));
}

RollcallEngine.prototype.getReference = function(name) {
	return (this.dom)? document.getElementById(name) : (this.ie4)? document.all[name] : (this.ns4)?  document[name] : false; 
}

RollcallEngine.prototype.setOff = function(name) {
	if ((typeof(this.RollImages[name]) != "undefined")) {
		this.RollImages[name].ref.src = this.RollImages[name].off.src;
		
		this.lastImage = "";
	}
}

RollcallEngine.prototype.setOver = function(name) {
	if ((typeof(this.RollImages[name]) != "undefined") && this.useOverState) {
		this.RollImages[name].ref.src = this.RollImages[name].over.src;
		this.lastImage = name;
	}
}

RollcallEngine.prototype.setOn = function(name) {
	if ((typeof(this.RollImages[name]) != "undefined") && this.useOnState) {
		this.RollImages[name].ref.src = this.RollImages[name].on.src;
		
		this.lastImage = name;
	}
}

RollcallEngine.prototype.setSrc = function(name,newSrc) {
	if (typeof(this.RollImages[name]) != "undefined") {
		this.RollImages[name].ref.src = newSrc;
	}
}
