var isMozilla   = (navigator.appName.indexOf("Mozilla") != -1);
var isMicrosoft = (navigator.appName.indexOf("Microsoft") != -1);

var isMac = (navigator.appVersion.indexOf("Mac") != -1);
var isIEFive = (navigator.appVersion.indexOf("MSIE 5") != -1);

//alert(navigator.appVersion);

// common_onload runs all the functions necessary upon onload
//##############################################################################
function common_onload() {
	// register event handlers
	event_handlers();

	
	return true;
}

// this registers the page's event handlers
//##############################################################################
function event_handlers() {
	// register mouseover and mouseout handlers for all images
	var index; // local variable
	for (index = 0; index < document.images.length; index++) {
		document.images[index].onmouseover = image_mouseover;
		document.images[index].onmouseout  = image_mouseout;
	}
	for (index = 0; index < document.anchors.length; index++) {
		document.anchors[index].onmouseover = anchor_mouseover;
		document.anchors[index].onmouseout  = anchor_mouseout;
	}
	
	return true;
}

// specify how to handle an image mouseover
//##############################################################################
function image_mouseover(e) {
	event_image = new Image();
	
	if (isMicrosoft) {
		e = window.event;
		event_image = e.toElement;
		e.cancelbubble = true
	}
	else if (isMozilla) { event_image = e.target; }
	else { event_image = e.target; }
	
	// set the status bar with the image's alt text
	window.status = event_image.alt;
	
	// swap the image for rollover effect
	swap_image(event_image);
	
	return true;
}

// specify how to handle an image mouseout
//##############################################################################
function image_mouseout(e) {
	event_image = new Image();
	
	if (isMicrosoft) {
		e = window.event;
		event_image = e.fromElement;
		e.cancelbubble = true
	}
	else if (isMozilla) { event_image = e.target; }
	else { event_image = e.target; }
	
	// set the status bar with the image's alt text
	window.status = "";
	
	// swap the image to end rollover effect
	swap_image(event_image);
	
	return true;
}

// specify how to handle an anchor mouseover
//##############################################################################
function anchor_mouseover(e) {
//	event_anchor = new Anchor();

	if (isMicrosoft) {
		e = window.event;
		event_anchor = e.toElement;
		e.cancelbubble = true
	}
	else if (isMozilla) {
		event_anchor = e.target;
	}
	else { event_anchor = e.target; }

	// set the status bar with the anchor's title text
	window.status = event_anchor.title;
	
	return true;
}

// specify how to handle an anchor mouseout
//##############################################################################
function anchor_mouseout(e) {
//	event_anchor = new Anchor();
	
	if (isMicrosoft) {
		e = window.event;
		event_anchor = e.fromElement;
		e.cancelbubble = true
	}
	else if (isMozilla) {
		event_anchor = e.target;
	}
	else { event_anchor = e.target; }
	
	// reset the status bar
	window.status = "";
	
	return true;
}

// swap an image with the next indexed image, if the next is specified with alt="---"
//##############################################################################
function swap_image(display_image) {
	// create an image object and set it to buffer an image while swapping
	buffer_image = new Image();
	buffer_image.src = display_image.src;
	
	// determine the document.images[] index
	var index = get_image_index(display_image); // local variable
	
	// if a corresponding hidden image exists, then get the hidden image object
	if (index >= 0) {
		hidden_image = new Image();
		// First, look to see...
		// if the hidden swap image exists with the same id + "_swap", then set it as the hidden image object
//		if (!(display_image.id === undefined)) { // this line is not compatible with IE pre-5.5 (5.2.2 is the latest IE version for Mac)
		if (typeof display_image.id != "undefined") {
			var hidden_index = image_id_to_index(display_image.id + "_swap");
			if (hidden_index >= 0) {
				hidden_image = document.images[hidden_index];
			}
		}
		// Second, look to see...
		// if a hidden swap image exists as the next indexed image, then set it as the hidden image object
		else if (((index + 1) < document.images.length) && (document.images[index + 1].alt == "---")) {
			hidden_image = document.images[index + 1];
		}
	}
	
	// if the hidden image exists, then swap the image
	if (hidden_image.src != "" && hidden_image.src != null) {
		// change the displayed image to the hidden image
		display_image.src = hidden_image.src;
		
		// change the hidden image to the recently displayed image held in buffer
		hidden_image.src = buffer_image.src;
	}
	
	return true;
}

// determine the index, given the image object
//##############################################################################
function get_image_index(this_image) {
	// loop through all document images to find a match to the passed image object
	var image_index; // local variable
	for (image_index = 0; image_index < document.images.length; image_index++) {
		// if there is a match, then return the index number
		if (document.images[image_index] == this_image) {
			return image_index;
		}
	}
	
	// if image object is not in document, then return -1 (failure)
	return -1;
}

// determine the index, given the image id (needed to replace IE's buggy eval())
//##############################################################################
function image_id_to_index(image_id) {
	// loop through all document images to find a match to the passed image id
	var image_index; // local variable
	for (image_index = 0; image_index < document.images.length; image_index++) {
		// if there is a match, then return the index number
		if (document.images[image_index].id == image_id) {
			return image_index;
		}
	}
	
	// if image id is not in document, then return -1 (failure)
	return -1;
}

//##############################################################################

