
/**
 * Caches images for preloading, particularly for image link rollovers
 *
 * @param	imgs (Array) - image file names minus state and file extension
 * @param	dir	(String) - images directory as relative or absolute path
 * @param	ext	(String) - file extension for images
 */
function cacheImages(imgs, dir, ext) {
	for (var i=0; i<imgs.length; i++){
		var img = imgs[i];
		if (img.indexOf('btn') > -1){
			eval(img + "_off =  new Image");
			eval(img + "_off.src = \'" + dir + "/" + img + "_off." + ext + "\'");
			eval(img + "_ovr =  new Image");
			eval(img + "_ovr.src = \'" + dir + "/" + img + "_ovr." + ext + "\'");
		} else {
			eval(img + " = new Image");
			eval(img + ".src = \'"+ dir + img + "." + ext + "\'");
		}
	}
}

/**
 * Opens a popup window
 *
 * @param	url (String) - name of image
 * @param	name	(String) - name of image
 * @param	width	(String) - name of image
 * @param	height	(String) - name of image
 * @param	options (String) - name of image
 */
function openWindow( url, name, width, height, options){
	if (!name) name = "_default";
	if (!width) width = 640;
	if (!height) height = 420;
	if (!options) options = "scrollbars=yes,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes";
	window.open( url, name, " width=" + width + ", height=" + height + ", " + options );
}

/**
 * Handles rollover event on an image link
 *
 * @param	imgName	(String) - name of image
 */
function imgOn(imgName) {
	document[imgName].src = eval(imgName + "_ovr.src");
}

/**
 * Handles rolloff event on an image link
 *
 * @param	imgName	(String) - name of image
 */
function imgOff(imgName) {
	document[imgName].src = eval(imgName + "_off.src");
}

/**
 * Cross browser method for obtaining a DOM element by it's element id
 *
 * @param	elmtID	(String) - id of element to obtain
 * @return	elmt	(HTML element) [returns null if not found]
 */
function getElement(elmtID) {
	return document.getElementById(elmtID);
}

/**
 * Gets the height of an html element
 *
 * @param	elmt	(HTML element) - element to get height of
 * @return	height	(Number)
 */
function getElmtHeight(elmt) {
	var height = null;
	if (elmt.offsetHeight) {
		height = elmt.offsetHeight;
	}                            
	else if (elmt.style.pixelHeight) {
		height = elmt.style.pixelHeight;
	}
	return height;
}

/**
 * Gets the width and height of the page
 *
 * @param	elmt	(HTML element) - element to get height of
 * @return	height	(Number)
 */
function getPageSizeWithScroll() {
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

/**
 * Returns object with the left and top amount of scrolling for the window
 *
 * @return	scroll	(Object) - object with X and Y properties
 */
function getScrolling() {
	var scroll = {x:0, y:0};
	if (window.scrollY) {
		scroll.x = window.scrollX;
		scroll.y = window.scrollY;
	} else if (document.body.parentNode.scrollTop) {
		scroll.x = document.body.parentNode.scrollLeft;
		scroll.y = document.body.parentNode.scrollTop;
	} else if (document.body.scrollTop) {
		scroll.x = document.body.scrollLeft;
		scroll.y = document.body.scrollTop;
	}
	return scroll;
}

/**
 * Returns object with the left and top offset for the body content
 *
 * @return	offset	(Object) - object with X and Y properties
 * @see		Prototype -> Position
 * @see		Prototype -> Ajax
 */
function getContentOffset() {
	var offset = {x:0, y:0};
	if (Position.page) {
		offset.x = Position.page(getElement("sheet"))[0];
		offset.y = Position.page(getElement("sheet"))[1];
	}
	return offset;
}

/**
 * Toggles the display style property of an element
 *
 * @param	elmtID	(String) - id of element to toggle display
 */
function toggleDisplay(elmtID) {
	var elmt = getElement(elmtID);
	if (!elmt) return false;
	if (elmt.style.display == "none") {
		elmt.style.display = "block";
	} else {
		elmt.style.display = "none";
	}
	return false;
}