//
// Rollover.js
//
// Copyright 2000, 2001 by Anthony Howe.  All rights reserved.
//

// Master array and index of rollover images.  This array and index
// must be in the window's context in order to perform a pre-load of
// the images.  Doing it within the class itself does not load the
// images until they are first displayed, which is undesirable.
//
var Rollover_images = new Array();
var Rollover_index = 0;

//
// new Rollover(prefix_on, prefix_off, suffix_on, suffix_off, image, ...)
//
function Rollover(prefix_on, prefix_off, suffix_on, suffix_off)
{
	if (arguments.length < 5)
		return;
	
	this.activeIndex = null;
	this.image = null;		
	this.img = new Array();
	
	for (var i = 4; i < arguments.length; ++i) {
		Rollover_images[Rollover_index] = new Image(80, 29);
		Rollover_images[Rollover_index].src = prefix_off + arguments[i] + suffix_off;
		this.img[arguments[i]+'-off'] = Rollover_images[Rollover_index++];

		Rollover_images[Rollover_index] = new Image(80, 29);
		Rollover_images[Rollover_index].src = prefix_on + arguments[i] + suffix_on;
		this.img[arguments[i]+'-on'] = Rollover_images[Rollover_index++];
	}	
}

//
// Rollover.on(image-name)
//
function Rollover_on(img)
{
	if (img != null && img != '') {
		eval("document."+img+".src = this.img['"+img+"-on'].src");
	}
	return true;
}

//
// Rollover.off(image-name)
//
function Rollover_off(img)
{
	if (img != null && img != '' && img != this.activeIndex) {
		eval("document."+img+".src = this.img['"+img+"-off'].src");
	}
	return true;
}

//
// Rollover.click(image-name, index)
//
function Rollover_click(img)
{
	var was = this.activeIndex;
	this.activeIndex = img;
	this.off(was);
	this.on(this.image = img);
	return true;
}


new Rollover();
Rollover.version = '1.0';
Rollover.author = 'achowe@snert.com';

Rollover.prototype.on = Rollover_on;
Rollover.prototype.off = Rollover_off;
Rollover.prototype.click = Rollover_click;
