
var isIE = navigator.appName.indexOf("Microsoft") != -1;
if (isIE) {
	try {
	  document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
}
	
String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/, "" );
}

/** find object on the page, by ID */
function bgGetElementById(id) {
	var elem = null;
	if (document.all) {
		elem = document.all[id];
	}
	else if (document.getElementById) {
		elem = document.getElementById(id);
	}
	return elem;
}

function removeCSSClass(elem, className) {
	elem.className = elem.className.replace(className, "").trim();
}

function addCSSClass(elem, className) {
	removeCSSClass(elem, className);
	elem.className = (elem.className + " " + className).trim();
}

function getRotatingSpotlight() {
    var photoCount = 4;
	var currentPhotoIndex = pickRandom(photoCount);

	for (i = 1; i < photoCount + 1; i++) {
		var spotlightId = "rotatingSpotlight" + (currentPhotoIndex + 1);
		if (i == (currentPhotoIndex + 1)) {
			document.getElementById(spotlightId).style.display="block";
		}
	}
}

function mouseOver() {
    addCSSClass(this, "over");
}

function mouseOut() {
	removeCSSClass(this, "over");
}

function addRollOver(node) {
    node.onmouseover = mouseOver;
    node.onmouseout = mouseOut;
}

function onMouseOverLoginUtilityNav(element) {
    if (document.all && document.getElementById) {
        addCSSClass(element, "over");
    }
}

function onMouseOutLoginUtilityNav(element) {
    if (document.all && document.getElementById) {
        removeCSSClass(element, "over");
    }
}

/*
 * 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;
	}
}
