function max(x, y) {
	// Check for undefined.  If both undefined, doesn't matter which is returned
	if (!x)  return y;
	if (!y)  return x;

	if (x > y)
		return x;
	return y;
}

function min(x, y) {
	// Check for undefined.  If both undefined, doesn't matter which is returned
	if (!x)  return y;
	if (!x)  return y;
	if (!y)  return x;

	if (x < y)
		return x;
	return y;
}

//function showObj(obj) { obj.style.display = 'inline'; }
//function hideObj(obj) { obj.style.display = 'none'; }
function showObj(obj, show) {
	if (show)
		obj.style.visibility = 'visible';
	else {
		obj.style.visibility = 'hidden';
	}
}

function fadeImpl(obj, end, delta, delay, n) {
//	alert('fadeImpl(' + end + ', ' + delta + ', ' + delay + ', ' + n + ')');
	var opacity = 1; // in case property doesn't exist
	if (obj.style.opacity < 1)
		opacity = parseFloat(obj.style.opacity);

	var opacity2 = opacity + delta;
//	alert('opacity: ' + (typeof opacity) + ', opacity2: ' + (typeof opacity2));
//	alert('opacity: ' + opacity + ', opacity2: ' + opacity2);
	obj.style.opacity = opacity2;
        // @#$! Internet Explorer...
        if (opacity2 == 0)
        	opacity2 = .01;
        obj.style.filter = "alpha(opacity=" + Math.round(opacity2 * 100) + ")";

//	alert('new opacity: ' + obj.style.opacity);
	n--;
	if (n > 0) {
		var func = function() { fadeImpl(obj, end, delta, delay, n); }
		setTimeout(func, delay);
	} else {
		obj.style.opacity = end;
	}
}
function fade(obj, targetOpacity, fadeTime) {  // fadeTime is in msec
	var frameDelay = 33; // msec
	var steps = Math.floor(fadeTime / frameDelay);
	var startOpacity = 1; // in case property doesn't exist
	if (obj.style.opacity < 1)
		startOpacity = parseFloat(obj.style.opacity);

	fadeImpl(obj, targetOpacity, (targetOpacity - startOpacity) / steps,
			 frameDelay, steps);
}

function addEventCallback(obj, eventStr, callback)
{
	if (obj.attachEvent) // @#$! IE
		obj.attachEvent(eventStr, callback);
	else
		obj.addEventListener(eventStr, callback, false);
}

function toggleImage(id) {
    var el = document.getElementById(id);
	// With images it seems that you have to use 'inline' instead of ''
    el.style.display = (el.style.display == 'inline' ? 'none' : 'inline' );
}

// ---------- From http://www.dustindiaz.com/top-ten-javascript/ ------------
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

