//
// ColorRollover.js
//
// Copyright 2000, 2003 by Anthony Howe.  All rights reserved.
//

//
// new ColorRollover(bgOn, bgOff)
// new ColorRollover(bgOn, bgOff, bgClick)
// new ColorRollover(fgOn, bgOn, fgOff, bgOff)
// new ColorRollover(fgOn, bgOn, fgOff, bgOff, fgClick, bgClick)
//
function ColorRollover(fgOn, bgOn, fgOff, bgOff, fgClick, bgClick)
{
	this.fgChange = true;

	switch (arguments.length) {
	case 2:
		this.fgChange = false;
		bgClick = fgOn;
		bgOff = bgOn;
		bgOn = fgOn;
		break;
	case 3:
		this.fgChange = false;
		bgClick = fgOff;
		bgOff = bgOn;
		bgOn = fgOn;
		break;
	case 4:
		fgClick = fgOn;
		bgClick = bgOn;
		break;
	case 6:
		break;
	default:
		return;
	}

	this.fgOn = fgOn;
	this.bgOn = bgOn;
	this.fgOff = fgOff;
	this.bgOff = bgOff;
	this.fgClick = fgClick;
	this.bgClick = bgClick;
	this.active = null;
}

//
// ColorRollover.set(el, fg, bg)
//
// Intended for internal use to set the fg/bg colours of a node,
// typically a <TD> and if necessary a child <A> tag. The reason
// for this is that IE6 does not support CSS "color: inherit;",
// so we fake it. Mozilla and Opera work fine.
//
function ColorRollover_set(el, fg, bg)
{
	if (el.childNodes.length == 1 && el.firstChild.nodeName == 'A') {
		el.firstChild.style.color = fg;
		el.firstChild.style.backgroundColor = bg;
	}

	el.style.color = fg;
	el.style.backgroundColor = bg;
}

//
// ColorRollover.on(id)
//
function ColorRollover_on(id)
{
	var el, fg, bg;
	
	if ((el = document.getElementById(id)) != null) {
		if (id == this.active) {
			if (this.fgChange)
				fg = this.fgClick;
			else
				fg = el.style.color;
			bg = this.bgClick;
		} else {
			if (this.fgChange)
				fg = this.fgOn;
			else
				fg = el.style.color;
			bg = this.bgOn;
		}

		this.set(el, fg, bg);
	}

	return true;
}

//
// ColorRollover.off(id)
//
function ColorRollover_off(id)
{
	var el, fg, bg;
	
	if ((el = document.getElementById(id)) != null) {
		if (id == this.active) {
			if (this.fgChange)
				fg = this.fgClick;
			else
				fg = el.style.color;
			bg = this.bgClick;
		} else {
			if (this.fgChange)
				fg = this.fgOff;
			else
				fg = el.style.color;
			bg = this.bgOff;
		}

		this.set(el, fg, bg);
	}

	return true;
}

//
// ColorRollover.toggle(id)
//
function ColorRollover_toggle(id)
{
	var el;
	
	if ((el = document.getElementById(id)) != null)
		this.set(el, el.style.backgroundColor, el.style.color);

	return true;
}

//
// ColorRollover.click(id)
//
function ColorRollover_click(id)
{
	var was = this.active;
	this.active = id;
	this.off(was);
	this.on(id);

	return true;
}

new ColorRollover();
ColorRollover.version = '1.3';
ColorRollover.author = 'achowe@snert.com';

ColorRollover.prototype.on = ColorRollover_on;
ColorRollover.prototype.off = ColorRollover_off;
ColorRollover.prototype.click = ColorRollover_click;
ColorRollover.prototype.toggle = ColorRollover_toggle;
ColorRollover.prototype.set = ColorRollover_set;

