/*
sets object obj position according to event ev in such a way, that it is will be on visible page area
Works:
-IE/6.0
-Opera/7.0
Works after fix:
-Mozilla (Gecko)/1.2+
Not works:
-Mozilla (Geck0)/1.0-
*/
function posObjByEvent (obj, ev) {
scrlTop = document.body.scrollTop;
scrlLeft = document.body.scrollLeft;
evTop = ev.clientY;
evLeft = ev.clientX;
wndHeight = document.body.clientHeight;
wndWidth = document.body.clientWidth;
//objHeight = obj.clientHeight; // don't work in Gecko, eg returns allways 0
objHeight = obj.offsetHeight; // hotfix for Gecko
//objWidth = obj.clientWidth; // don't work in Gecko, eg returns allways 0
objWidth = obj.offsetWidth; // hotfix for Gecko
if (evTop - objHeight / 2 < 0) {
objTop = evTop + scrlTop;
} else if (evTop + objHeight / 2 > wndHeight) {
objTop = evTop + scrlTop - objHeight;
} else {
objTop = evTop + scrlTop - objHeight / 2;
}
obj.style.top = objTop;
if (evLeft - objWidth / 2 < 0) {
objLeft = evLeft + scrlLeft;
} else if (evLeft + objWidth / 2 > wndWidth) {
objLeft = evLeft + scrlLeft - objWidth;
} else {
objLeft = evLeft + scrlLeft - objWidth / 2;
}
obj.style.left = objLeft;
return false;
}