/**
 * pega a posição do objeto
 */
var getPosition = function (o) {
	var x=0, y=0;
	while(o != null) {
		x += parseFloat(o.offsetLeft);
		y += parseFloat(o.offsetTop);
		o = o.offsetParent;
	}
	return {x:x, y:y};
}

/**
 * pega a posição do mouse
 */
var getMousePosition = function (e) {
	var ie = document.all ? true : false;
	var x=0; y=0;
	if(ie) {
		x = event.clientX;
		y = event.clientY;
	} else {
		x = e.clientX;
		y = e.clientY;
	}
	return {x:x, y:y};
}

/**
 * altera a posição do objeto
 */
var setPosition = function (o, x, y) {
	o.style.left = x +'px';
	o.style.top = y + 'px';
}

/**
 * pega o tamanho do objeto
 */
var getSize = function(o) {
	return {width:o.offsetWidth, height:o.offsetHeight};
}

/**
 * testa se um objeto colidiu com o outro
 */
var hitTest = function (o1, o2) {
	var d1 = getSize(o1);
	var d2 = getSize(o2);
	var p1 = getPosition(o1);
	var p2 = getPosition(o2);
	if(p1.x + d1.width >= p2.x && p1.x <= p2.x + d2.width) {
		if(p1.y + d1.height >= p2.y && p1.y <= p2.y + d2.height) {
			return true;
		}
	}
	return false;
}

var setSize = function(o, x, y) {
	o.style.width=x+'px';
	o.style.height=y+'px';
}

/**
 * adiciona um evento a um objeto
 */
function addEvent(c, evt, cb) {
	if(c.addEventListener) c.addEventListener(evt, cb, true);
	if(c.attachEvent) c.attachEvent('on'+evt, cb);
}

/**
 * pega o valor de um atributo pelo nome
 */
function getAttributeValue(node, id) {
	for(var i=0; i<node.attributes.length; i++) {
		if(node.attributes.item(i).nodeName == id) {
			return node.attributes.item(i).nodeValue;
		}
	}
	return null;
}

function setVisible(o, v) {
	o.style.visibility = v ? 'visible':'hidden';
	o.style.display = v ? '' : 'none';
}

function $(id) {
	return document.getElementById(id);
}