/***********************************************************************************
 * Class: CObject
 * Description:
 *   Object class
 *
 ***********************************************************************************/

	function CObject() {};
	
	// Static get method
	CObject.get = function(idOrObj) {
		if(typeof(idOrObj) == "object")
			return idOrObj;
		//if(typeof(idOrObj) != "string") //"object")
		//	return idOrObj;

		if(document.getElementById)
			return document.getElementById(idOrObj);
		else if(document.all)
			return document.all[idOrObj];
		else if(document.layers)
			return document.layers[idOrObj];
		return null;
	};

	// Move object to x, y
	CObject.moveTo = function(idOrObj, x, y, suffix) {
		var obj = CObject.get(idOrObj);
		if(!isNaN(x))
			obj.style.left = x + (suffix == null ? "px" : suffix);
		if(!isNaN(y))
			obj.style.top = y + (suffix == null ? "px" : suffix);
	};

	// Set width
	CObject.setWidth = function(idOrObj, width, suffix) {
		CObject.get(idOrObj).style.width = width + (suffix == null ? "px" : suffix);
	};

	// Set height
	CObject.setHeight = function(idOrObj, height, suffix) {
		CObject.get(idOrObj).style.height = height + (suffix == null ? "px" : suffix);
	};

	// Static class set method
	CObject.classSet = function(idOrObj, className) {
		var obj = CObject.get(idOrObj);
		if(obj.CObject_className == null)
			obj.CObject_className = obj.className;
		obj.className = className;
	};
	
	// Class restore method (if prev class name set)
	CObject.classRestore = function(idOrObj) {
		var obj = CObject.get(idOrObj);
		if(obj.CObject_className)
			CObject.classSet(obj, obj.CObject_className);
	};

	// Check if object has a class
	CObject.classCheck = function(idOrObj, className) {
		var obj = CObject.get(idOrObj);
		return ((" " + obj.className + " ").indexOf(" " + className + " ") >= 0);
	};
	
	// Static replace sub-class within object classes
	CObject.classReplace = function(idOrObj, from, to, appendIfAbsent) {
		var obj = CObject.get(idOrObj);

		var newClass = obj.className;
		
		// Find " from " and replace with " to "
		if(from != null && from != "") {
			newClass = (" " + newClass + " ").replace(" " + from + " ", " " + to + " ");
			newClass = newClass.substring(1, newClass.length - 1);
		}
		// Add if "from" class is absent?
		if(((from == null || from == "") || appendIfAbsent) && (" " + newClass + " ").indexOf(" " + to + " ") < 0)
			newClass = (newClass != "" ? newClass + " " : "") + to;
			
		// Set new class
		CObject.classSet(obj, newClass);
	};

	// Convert x-a to xA for ie
	CObject.stylePropGet = function(property) {
		return (document.all) ? property.replace(/-([a-z])/g, "\1") : property;
	}
	
	// Static get method
	CObject.getStyle = function(idOrObj, property) {
		var obj = CObject.get(idOrObj);
		
		if(obj && property != null) {
			var value = null;
			if(window.getComputedStyle)
				value = window.getComputedStyle(obj, null).getPropertyValue(property);
			else if(obj.currentStyle)
				value = eval('obj.currentStyle.' + property);

			if(value != null) {
				if((property == "width" || property == "height") && value.match(/(%|auto)/g))
					value = (property == "width") ? obj.offsetWidth : obj.offsetHeight;
				else if((property == "left" || property == "top") && value.match(/(%|auto)/g))
					value = (property == "left") ? obj.offsetLeft : obj.offsetTop;
				return (value+"").replace(/px/g, "");
			}
		}
		return (obj && obj.style) ? obj.style : null;
	};
	
	// Set style value
	CObject.setStyle = function(idOrObj, property, value, suffix) {
		var obj = CObject.get(idOrObj);
		if(obj.style.setProperty)
			obj.style.setProperty(property, value + (suffix == null ? "" : suffix), "");
		else
			obj.style[property] = value + (suffix == null ? "" : suffix);
	};

	// Is object displayed
	CObject.isDisplayed = function(idOrObj) {
		var display = CObject.getStyle(idOrObj, "display");
		return (display != "none");
	};
	// Static display method
	CObject.display = function(idOrObj, display) {
		var obj = CObject.get(idOrObj);
		if(obj.CObject_display == null)
			obj.CObject_display = CObject.getStyle(idOrObj, "display");
		CObject.getStyle(obj).display = display;
	};
	// Display restore method
	CObject.displayRestore = function(idOrObj) {
		var obj = CObject.get(idOrObj);
		if(obj.CObject_display != null)
			CObject.display(obj, obj.CObject_display); 
	};
	// Display none method
	CObject.displayNone = function(idOrObj) { CObject.display(idOrObj, "none"); };
	// Display block method
	CObject.displayBlock = function(idOrObj) { CObject.display(idOrObj, "block"); };
	// Display inline method
	CObject.displayInline = function(idOrObj) { CObject.display(idOrObj, "inline"); };

	// Is object visisble
	CObject.isVisible = function(idOrObj) {
		var visibility = CObject.getStyle(idOrObj, "visibility");
		return (visibility != "hidden");
	};
	// Static visibility method
	CObject.visibility = function(idOrObj, visibility) {
		var obj = CObject.get(idOrObj);
		if(obj.CObject_visibility == null)
			obj.CObject_visibility = CObject.get(idOrObj).visibility;
		CObject.getStyle(obj).visibility = visibility;
	};
	// Restore visibility
	CObject.restoreVisibility = function(idOrObj) {
		var obj = CObject.get(idOrObj);
		if(obj.CObject_display != null)
			CObject.visibility(obj, obj.CObject_visibility);
	};
	// Show method
	CObject.show = function(idOrObj) { CObject.visibility(idOrObj, "visible"); };
	// Hide method
	CObject.hide = function(idOrObj) { CObject.visibility(idOrObj, "hidden"); };

	// Get X position
	CObject.getPosX = function(obj) {
		var curleft = 0;
		if(obj.offsetParent) {
			while(obj.offsetParent) {
				curleft += obj.offsetLeft;/// 2;
				obj = obj.offsetParent;
			}
		}
		else if(obj.x)
			curleft += obj.x;
		return curleft;
	};
	
	// Get Y position
	CObject.getPosY = function(obj) {
		var curtop = 0;
		if(obj.offsetParent) {
			while(obj.offsetParent) {
				curtop += obj.offsetTop;
				obj = obj.offsetParent;
			}
		}
		else if(obj.y)
			curtop += obj.y;
		return curtop;
	};
		
	// Get object size
	CObject.getSize = function(idOrObj) {
		var obj = CObject.get(idOrObj);
		var size = new Object();

		size.width = CObject.getStyle(obj, "width");
		size.height = CObject.getStyle(obj, "height");

		return size;
	};
	