
// ***** JAVASCRIPT HEAD CODE *****
// ***** Dan Efran's general-purpose conditional image system
// written 18 Jan 2000.  Based on code in Voodoo's Javascript Tutorial. (Thanks!)
// (my version is more generalized, stores names separately, has other improvements.)

myImageArrays = new Array();
myImageNames = new Array();

myImageCount = 0;

// find name in array
// ***
function itemNumber(item) {
	var i = myImageCount;
	while (i > 0) {
		i--;
		if (myImageNames[i] == item)
			return i; // found it
	} // while i > 0
	return -1; // not found
} // function itemNumber
// ---

// add conditional image (for rollovers etc.) to multi-array
// ***
function addImage(item, condition, source) {
	if (!document.images) return; // won't work without image objects

	var num = itemNumber(item);
	if (num < 0) { // item not in array yet
		myImageArrays[myImageCount] = new Array();
		myImageArrays[myImageCount][condition] = new Image;
		myImageArrays[myImageCount][condition].src = source;
		myImageNames[myImageCount] = item;
		myImageCount++;
	} // if not in array yet
	else { // item already in array, not necessarily for this condition
		myImageArrays[num][condition]=new Image;
		myImageArrays[num][condition].src = source;
		// image name doesn't change
	} // else item already in array

} // function addImage
// ---

// set an image (by name) to a specific condition (by number)
// (I propose: 0= neutral, 1=rollover, 2= clicking, 3=visited, etc.)
// note lack of bounds checking on condition. use with care.	
// ***
function setItem(item, condition) {
	if (!document.images) return; // won't work without image objects

	var num = itemNumber(item)	
	if (num < 0)
		return; // item not registered in array	
	document.images[item].src = myImageArrays[num][condition].src; 
} // function setItem
// ---

// like setItem, but sets all other registered items to condition 0
// note lack of bounds checking on condition. use with care.	
// ***
function setOnly(item, condition) {
	if (!document.images) return; // won't work without image objects

	var num = itemNumber(item);
	var i = myImageCount;
	
	if (num < 0)
		return; // item not registered in array	
	while (i > 0) {
		i--;
		if (i == num) // this one
			document.images[myImageNames[i]].src = myImageArrays[i][condition].src; // set
		else // not this one
			document.images[myImageNames[i]].src = myImageArrays[i][0].src; // reset to 0
	} // while i > 0
} // function setOnly
// ---

// use the conditional image functions defined above to implement
// rollovers for the martian naviglyph.
// for mouseOver, use setOnly(item, 1)
// for mouseOut, use setItem(item, 0)
// ***
function initMartianNaviglyph() {
	addImage('homeBtn', 0, "images/HomeBtn.gif"); // neutral
	addImage('homeBtn', 1, "images/HomeLit.gif"); // rollover
	addImage('prevTopicBtn', 0, "images/PrevTopicBtn.gif"); // neutral
	addImage('prevTopicBtn', 1, "images/PrevTopicLit.gif"); // rollover
	addImage('nextTopicBtn', 0, "images/NextTopicBtn.gif"); // neutral
	addImage('nextTopicBtn', 1, "images/NextTopicLit.gif"); // rollover
	addImage('prevPageBtn', 0, "images/PrevPageBtn.gif"); // neutral
	addImage('prevPageBtn', 1, "images/PrevPageLit.gif"); // rollover
	addImage('nextPageBtn', 0, "images/NextPageBtn.gif"); // neutral
	addImage('nextPageBtn', 1, "images/NextPageLit.gif"); // rollover	

} // function initMartianNaviglyph
// ---

// ***** MAIN CODE *****
initMartianNaviglyph();
