// JavaScript Document
//Positioning functions

function findObjPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function getCursorPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

function findCursorPosInsideObj(e, obj){
	var objPos = findObjPos(obj);
	var cursorPos = getCursorPosition(e);
	var final = {x:0, y:0};
	final.x=cursorPos.x-objPos[0];
	final.y=cursorPos.y-objPos[1];
	if (navigator.appName == "Microsoft Internet Explorer"){final.x = final.x+12;};
	return final;
}

function positionAbsoluteLayer(e, elem, parentElem, offsetX, offsetY){
	var theLayer = document.getElementById(elem);
	var thePos = getCursorPosition(e);
	if (parent!=null){
		var offset = findObjPos(document.getElementById(parentElem));
		thePos.x = thePos.x-offset[0];
		thePos.y = thePos.y-offset[1];
	}
	if (offsetX != null){thePos.x = thePos.x+offsetX;};
	if (offsetY != null){thePos.y = thePos.y+offsetY;};
	theLayer.style.top=thePos.y+'px';
	theLayer.style.left=thePos.x+'px';
}