/*******************************************************************
	Graphic Link Mouseover/Mouseout Handler Version 1.7
	
	©2004-7 A+R Media Studio
	http://www.AandRmediastudio.com
	
	written by Rudy Dominguez (rudy@AandRmediastudio.com)
	
	These scripts are free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
*******************************************************************/
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, useStyle) {
	if ((obj.name == "") && (obj.id != "")) {
		obj.name = obj.id;						 
	}

	if ((obj.name != "") && (typeof(this.RollImages[obj.name]) == "undefined")) {
		this.RollImages[obj.name] = new Object();
		
		this.RollImages[obj.name].ref = obj;
		
		this.RollImages[obj.name].className = obj.className;
		this.RollImages[obj.name].useStyle = useStyle;

		if (typeof(obj.src) != "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].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, useStyle) {
	delete (this.RollImages[name]);
	
	this.register((typeof(name) != "string")? name : this.getReference(name), useStyle);
}

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")) {
		if (this.RollImages[name].useStyle) {
			this.RollImages[name].ref.className = this.RollImages[name].className
		} else {
			this.RollImages[name].ref.src = this.RollImages[name].off.src;
		}
		
		this.lastImage = "";
	} else if  (typeof(name) != "undefined")  {
		name.className = name.className.split("On").join("").split("Over").join("");
	}
}

RollcallEngine.prototype.setOver = function(name, obj) {
	if ((typeof(this.RollImages[name]) != "undefined") && this.useOverState) {
		if (this.RollImages[name].useStyle) {
			this.RollImages[name].ref.className = this.RollImages[name].className.split("On").join("").split("Over").join("") + "Over";
		} else {
			this.RollImages[name].ref.src = this.RollImages[name].over.src;
		}
		
		this.lastImage = name;
	}
	
	if ((typeof(this.RollImages[obj]) != "undefined") && this.useOnState) {
		if (this.RollImages[obj].useStyle) {
			this.RollImages[obj].ref.className = this.RollImages[obj].className.split("On").join("").split("Over").join("") + "Over";
		} else {
			this.RollImages[obj].ref.src = this.RollImages[obj].on.src;
		}
		
		this.lastImage = name;
	} else if (typeof(obj) == "object") {
		this.reRegister(obj, true);
		this.setOn(obj.id);
	}
}

RollcallEngine.prototype.setOn = function(name, obj) {
	if ((typeof(this.RollImages[name]) != "undefined") && this.useOnState) {
		if (this.RollImages[name].useStyle) {
			this.RollImages[name].ref.className = this.RollImages[name].className.split("On").join("").split("Over").join("") + "On";
		} else {
			this.RollImages[name].ref.src = this.RollImages[name].on.src;
		}
		
		this.lastImage = name;
	} else if (typeof(name) == "object") {
		this.reRegister(name, true);
		this.setOn(name.id);
	} 
	
	if ((typeof(this.RollImages[obj]) != "undefined") && this.useOnState) {
		if (this.RollImages[obj].useStyle) {
			this.RollImages[obj].ref.className = this.RollImages[obj].className.split("On").join("").split("Over").join("") + "On";
		} else {
			this.RollImages[obj].ref.src = this.RollImages[obj].on.src;
		}
		
		this.lastImage = name;
	} else if (typeof(obj) == "object") {
		this.reRegister(obj, true);
		this.setOn(obj.id);
	}
}

RollcallEngine.prototype.setSrc = function(name,newSrc) {
	if (typeof(this.RollImages[name]) != "undefined") {
		this.RollImages[name].ref.src = newSrc;
	}
}
