/**
 * $Id: domutils.js 192 2006-07-20 21:08:21Z michi2 $
 */

/** @type Object */
var Node = Node ? Node : {};

/**
 *	A utility class that exists to combine common DOM algorithms and utilities
 *	into a single class as static methods and constants. This class is not 
 *	meant to be subclassed.
 *
 *	@constructor 
 */
function DomUtils() {}

/**
 *	@param Element target
 *	@returns void
 */
DomUtils.show = function (target) {
    target.style.display = "";
};

/**
 *	@param Element target
 *	@returns void
 */
DomUtils.hide = function (target) {
    target.style.display = "none";
};

/**
 *	@param Element target
 *	@returns boolean
 */
DomUtils.isShowing = function (target) {
    return target.style.display.toLowerCase() != "none";
};

/**
 *	Toggles <code>target</code>'s visibility.
 *	@param Element target
 *	@returns void
 */
DomUtils.toggle = function (target) {
    if (DomUtils.isShowing(target)) {
        DomUtils.hide(target);
    } else {
        DomUtils.show(target);
    }
};

/**
 *	@param Element target
 *	@param string type
 *	@param Function func
 *	@param boolean bubbles
 *	@returns void
 */
DomUtils.addEventListener = function (target,type,func,bubbles) {
	if (document.addEventListener) {
		target.addEventListener(type,func,bubbles);
	} else if (document.attachEvent) {
		target.attachEvent("on"+type,func,bubbles);
	} else {
		target["on"+type] = func;
	}
};

/**
 *	@param Element target
 *	@param string type
 *	@param Function func
 *	@param boolean bubbles
 *	@returns void
 */
DomUtils.removeEventListener = function (target,type,func,bubbles) {
	if (document.removeEventListener) {
		target.removeEventListener(type,func,bubbles);
	} else if (document.detachEvent) {
		target.detachEvent("on"+type,func,bubbles);
	} else {
		target["on"+type] = null;
	}
};

/**
 *	@returns number
 */
DomUtils.getX = function (node) {
    return parseInt(node.style.left);
};
		
/**
 *	@returns number
 */
DomUtils.getY = function (node) {
    return parseInt(node.style.top);
};
	
/**
 *	@returns number
 */
DomUtils.getWidth = function (node) {
	return parseInt(node.style.width);
};
		
/**
 *	@returns number
 */
DomUtils.getHeight = function (node) {
	return parseInt(node.style.height);
};
	
/**
 *	@returns void
 */
DomUtils.setX = function (node,x) {
	node.style.left = x + "px";
};
	
/**
 *	@returns void
 */
DomUtils.setY = function (node,y) {
	node.style.top = y + "px";
};

/**
 *	@returns void
 */
DomUtils.setWidth = function (node,width) {
	node.style.width = width + "px";
};
	
/**
 *	@returns void
 */
DomUtils.setHeight = function (node,height) {
	node.style.height = height + "px";
};

/**
 *	@constructor
 *	@param MouseEvent evt
 */
function Evt(evt) {
    this._evt 	 = evt ? evt : window.event;
    this._source = this._evt.target ?  this._evt.target : this._evt.srcElement;
    this._x = this._evt.pageX ? this._evt.pageX : this._evt.clientX;
    this._y = this._evt.pageY ? this._evt.pageY : this._evt.clientY;
}

/**
 *	@returns Element
 */
Evt.prototype.getSource = function () {
	return this._source;
};

/**
 *	@returns void
 */
Evt.prototype.consume = function () {
    if (this._evt.stopPropagation) {
        this._evt.stopPropagation();
        this._evt.preventDefault();
    }
    try {
        this._evt.cancelBubble = true;
        this._evt.returnValue  = false;
    } catch (e) { }
};

/**
 *	@returns number
 */
Evt.prototype.getX = function () {
	return this._x;
};

/**
 *	@returns number
 */
Evt.prototype.getY = function () {
	return this._y;
};
