function removeCSSClass(elem, className) {
	elem.className = trim(elem.className.replace(className, ""));
}

function trim (str) {
  str = this != window? this : str;
  return str.replace(/^s+/, '').replace(/s+$/, '');
}

function addCSSClass(elem, className) {
	removeCSSClass(elem, className);
	elem.className = trim(elem.className + " " + className);
}

function mouseOver() {
    addCSSClass(this, "over");
}

function mouseOut() {
	removeCSSClass(this, "over");
}

function addRollOver(node) {
    node.onmouseover = mouseOver;
    node.onmouseout = mouseOut;
}

/*
 * This function highlights an image
 *
 * @param	image - the name of the image to be flipped
 * @param	dir - path to image dir (ex: "../images/nav/")
 * @param	imgName - optional, if name attribute is different from the image file name
 */
function over(image, dir, imgName) {
	if (document.images) {
		var img = (imgName) ? findObject(imgName) : findObject(image);
		// store reference to old image for the out function
		img.rsrc = img.src;
		img.src = dir + image + "_on.gif";
	}
}

/**
 * This function restores an image
 *
 * @param	image - the name of the image to be flopped
 * @param	imgName - optional, if name attribute is different from the image file name
 */
function out(image) {
	if (document.images) {
		var img = findObject(image);
		// set source to stored reference to the old image
		img.src = img.rsrc;
    }
}

// adapted from MM_findObj
function findObject(name, doc) {

	// get document, if it hasn't been passed
	if (!doc) doc = document;

	// declare object reference
	var obj = null;

	// check document and document.all collections
	if (!(obj = doc[name]) && doc.all) {
		obj = doc.all[name];
	}

	// check document.layers collection
	if (!obj && document.layers) {
		for (var i = 0; !obj && i < doc.layers.length; i++) {
			obj = findObject(name, doc.layers[i].document);
		}
	}

	if (!obj && doc.getElementById) {
		obj = doc.getElementById(name);
	}

	return obj;
}

/* Returns a random number between 0 and range (includingly) */
function pickRandom(range)
{
	if (Math.random)
		return Math.round(Math.random() * (range-1));
	else {
		var now = new Date();
		return (now.getTime() / 1000) % range;
	}
}

