/* utility functions from PLOS*/

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function navInit() {
	var navContainer = dojo.byId("nav");

	for (var i=0; i<navContainer.childNodes.length; i++) {
		if (navContainer.childNodes[i].nodeName == "LI") {
			var navLi = navContainer.childNodes[i];
			navLi.onmouseover = function() {
				this.className = this.className.concat(" over");
			}

			navLi.onmouseout = function() {
				this.className = this.className.replace(/\sover/, "");
				this.className = this.className.replace(/over/, "");
			}
		}
	}
}


// load global functions

dojo.addOnLoad(navInit);

