/**
 * Script containing common functions.
 */
//var ceCommon_Old=(window.onload) ? window.onload : function() {}
//window.onload = function() { ceCommon_Old(); ceCommon_init(); }

//{{{ Common.
/** Simple img swap. */
function ceImgSwap(imgId, imgUrl) {
	imgE = getElement(imgId);
	imgE.src = imgUrl;
}

/** Image preloader. */
function ceImgPreload() {
	for(imgCnt=0;imgCnt<arguments.length;imgCnt++) {
		var im = new Image();
		im.src = arguments[imgCnt];
	}
}
//}}}

//{{{ Document functions.
/**
 * Portable method for getting document element references.
 *
 * @param elementId the id of the desired element
 * @return the element reference or null if not found
 * @TODO make this portable
 */
function getElement(elementId) {
	var element = null;
	if(document.all)
		element = document.all[elementId];
	else
		element = document.getElementById(elementId);
	return element;
}

/**
 * Portable method for getting the width of an element.
 *
 * @param e the element reference of the desired element
 * @return the element width
 * @TODO make this portable
 */
function getElementWidth(e) {
		return e.offsetWidth;
}

/**
 * Portable method for getting the height of an element.
 *
 * @param e the element reference of the desired element
 * @return the element height
 * @TODO make this portable
 */
function getElementHeight(e) {
	return e.offsetHeight;
}

/**
 * Portable method for getting the x coordinate of an element.
 *
 * @param e the element reference of the desired element
 * @return the element x coordinate
 * @TODO make this portable
 */
function getElementX(e) {
	return calculateSumOffset(e, 'offsetLeft');
}

/**
 * Portable method for getting the y coordinate of an element.
 *
 * @param e the element reference of the desired element
 * @return the element y coordinate
 * @TODO make this portable
 */
function getElementY(e) {
	return calculateSumOffset(e, 'offsetTop');
}

/**
 * Calculate the sum offset.
 *
 * This function came from:
 * Top Nav bar script v2.1
 * 	- http://www.dynamicdrive.com/dynamicindex1/sm/index.htm
 *
 * Explanation and compatibility notes:
 * http://www.quirksmode.org/js/findpos.html
 */
function calculateSumOffset(e, offsetName) {
	var totalOffset = 0;
	var item = eval('e');
	do {
		totalOffset += eval('item.' + offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}
//}}}
