////////////////////////////////////////////////////////////////////////////////
// Copyright 2006-2008 James Pike

function findPosX(obj) {
    //return obj.offsetLeft
    var curleft = 0
    if (obj.offsetParent) {
        while (1) {
            curleft += obj.offsetLeft
            if(!obj.offsetParent) break
            obj = obj.offsetParent
        }
    }
    else if (obj.x) {
        curleft += obj.x
    }

    return curleft
}

function findPosY(obj) {
    //return obj.offsetTop
    var curtop = 0
    if (obj.offsetParent) {
        while(1) {
            curtop += obj.offsetTop
            if(!obj.offsetParent) break
            obj = obj.offsetParent
        }
    }
    else if(obj.y) {
        curtop += obj.y
    }
    return curtop
}

// like findPosX but add border
function findInnerPosX(obj) {
    var x = findPosX(obj)
    // this doesn't work for some reason
    if (window.getComputedStyle) {
        alert(document.defaultView.getComputedStyle(obj, null).getPropertyValue('border-width'))
    }
    // x += obj.style.border
    return x
}

function findInnerPosY(obj) {
    var y = findPosY(obj)
    // y += obj.style.border
    return y
}

function niceMod(i, m) {
	if(i < 0){
		return (m - (-i)%m)%m;
	} else {
		return i%m;
	}
}