/////////////////////////////////////////////////////////////////////////
//
// DynImage Object Constructor
//
// Developed by Matt Holford -- matt@brokeland.com
//
// Last update: 03/2002
//
// Note that to addDiv with NN < 5, pass the div names in ascending order;
// i.e., start with the name of the div that actually contains the image,
// and move outward from there.
//
/////////////////////////////////////////////////////////////////////////

// First determine whether we're using DynLayer browser detect ("is"
// object) or my own
if (typeof(is) == "object") {
	isIE = is.ie;
	isNN4 = is.ns4;
	isNN6 = is.ns6;
}

function DynImage(name, path, suffix) {
	// Give me the name, minus "Img"
	name_parts = name.split ("Img");
	this.name = name_parts[0];
	
	// Now assign the rest of the variables/functions.
	this.on_img			= new Image();
	this.on_img.src		= path + "/" + this.name + "_on." + suffix;
	this.off_img 		= new Image();
	this.off_img.src	= path + "/" + this.name + "_off." + suffix;
	//this.hi_img 		= new Image();
	//this.hi_img.src		= path + "/" + this.name + "_hi." + suffix;
	this.turnOn 		= rollOn;
	this.turnOff 		= rollOff;
	this.turnHi			= highLight;
	this.hasDiv			= false;
	this.div			= "";
	this.selected		= false;
	this.addDiv			= identifyDiv;
	// Write a handle for the image -- this can be revised in identifyDiv (addDiv)
	this.handle = "document." + this.name + "Img";
}

function identifyDiv() {
	var evalPhrase = "";
	if (arguments.length == 0) {
		// Can't work under these conditions; I'm leaving
		alert("addDiv/identifyDiv: 0 arguments passed for " + this.name);
		return false;
	}	
	// We might be passed more than one argument here.  This is only important to NN < 5
	if (isIE) this.handle = eval("document.all['" + arguments [0] + "'].document." + this.name + "Img");
	else if (isNN4) {
		// Loop through the arguments **BACKWARDS** to construct the proper name
		evalPhrase = "document.";
		for (var i = arguments.length - 1; i >= 0 ; i--) {
			evalPhrase += "layers['" + arguments[i] + "'].document.";
		}
		evalPhrase += this.name + "Img";
		this.handle = eval(evalPhrase);
	}
}

function rollOn() {
	if (!this.selected) {
		if (typeof(this.handle) != "object") this.handle = eval(this.handle);
		this.handle.src = this.on_img.src;
	}
}

function rollOff() {
	if (!this.selected) {
		if (typeof(this.handle) != "object") this.handle = eval(this.handle);
		if (!this.selected) this.handle.src = this.off_img.src;
	}
}

function highLight() {
	if (typeof(this.handle) != "object") this.handle = eval(this.handle);
	this.handle.src = this.hi_img.src;
}

