/*
	Helper Functions

	class CSS
*/

function CSS() {}

CSS.getOffsetAbsoluteLeft = function(obj) {
	var x = 0;
	var dx = 0;
	while(obj) {
		if (obj) {
			dx = parseInt(obj.offsetLeft);
			if (!isNaN(dx)) x += dx;
			if (obj.style) {
				if ("absolute"==obj.style.position) return x;
			}
		}
		obj = obj.offsetParent;
	}
	return x;
}

CSS.getOffsetAbsoluteTop = function(obj) {
	var x = 0;
	var dx = 0;
	while(obj) {
		if (obj) {
			dx = parseInt(obj.offsetTop);
			if (!isNaN(dx)) x += dx;
			if (obj.style) {
				//if ("absolute"==obj.style.position) return x;
			}
		}
		obj = obj.offsetParent;
	}
	return x;
}

CSS.getWidth = function(obj) {
	return obj.offsetWidth;
}

CSS.getHeight = function(obj) {
	return obj.offsetHeight;
}

CSS.setVisible = function(obj, bVisible) {
	if (bVisible) {
//		obj.style.display = "inline";
		obj.style.visibility = "visible";
	} else {
		obj.style.visibility = "hidden";
	}
}

CSS.getVisible = function(obj) {
	return ("visible" == obj.style.visibility);
}

CSS.moveTo = function(obj, iX, iY) {
	//obj.style.pixelLeft = iX;
	//obj.style.pixelTop = iY;
	obj.style.left = iX;
	obj.style.top = iY;
}

CSS.setPositioningAbsolute = function(obj, bAbsolute) {
	if (bAbsolute) {
		obj.style.position = "absolute";
	} else {
		obj.style.position = "relative";
	}
}

CSS.setFloating = function(obj, bFloat) {
	if (bFloat) {
		obj.style.styleFloat = "left";
	} else {
		obj.style.styleFloat = "none";
	}
}

CSS.addEventListener = function(srcObj, eventName, objDest, objFuncDest) {
	if (srcObj.addEventListener) {
		var objFunc;
		if (objDest) {
			objFunc = function() {
									objFuncDest.apply(objDest);
								}
		} else {
			objFunc = function() {
									objFuncDest();
								}
		}
		srcObj.addEventListener(eventName, objFunc, false);
	} else {
		// ie needs to remember prev handler and uses handler-"chaining"
		var prevHandler = srcObj["on" + eventName];
		var objFunc;
		if (objDest) {
			objFunc = function() {
									objFuncDest.apply(objDest);
									if (prevHandler) prevHandler.apply(srcObj);
								}
		} else {
			objFunc = function() {
									objFuncDest();
									if (prevHandler) prevHandler.apply(srcObj);
								}
		}
		srcObj["on"+eventName] = objFunc;
	}
}

CSS.getElementById = function(strId) {
	return document.getElementById(strId);
}
