currMenu = 0; // used to remember the menu that's on
menuTimeout = 0; // menu timeout
timeoutPeriod = 1000;//time out period in milliseconds


// Temporary variables to hold mouse x-y pos.s
mouseX = 0
mouseY = 0

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
  if (is_ie4up) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX
    mouseY = e.pageY
  }
}

// Set-up to use getMouseXY function onMouseMove
if (is_nav4up && !is_gecko) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;

// starts the clearing of the menu process
function startClear(layer) {
	clearTimeout(menuTimeout);
	str = eval('\"timedClear(\'' + layer + '\')\"');
	menuTimeout = setTimeout(str, timeoutPeriod);
	
}

// checks if the mouse is within the menu, will close it if it isn't
function timedClear(layer) {
	l = getLeft(layer);
	t = getTop(layer);
	r = getWidth(layer);
	r += l;
	b = getHeight(layer);
	b += t;
	
	
	if (mouseX < l) {
		hideLayer(layer);
		return false;
	}	
	if (mouseY < t) {
		hideLayer(layer);
		return false;
	}	
	if (mouseX > r) {
		hideLayer(layer);
		return false;
	}	
	if (mouseY > b) {
		hideLayer(layer);
		return false;
	}
	
	str = eval('\"timedClear(\'' + layer + '\')\"');
	menuTimeout = setTimeout(str, timeoutPeriod);
	return false;
}


// pixel value for left edge of layer
function getLeft(layer) {

  if (is_nav4up && !is_gecko) {
    return document.layers[layer].left;
  } else if (is_ie4) {
  	return parseInt (document.all[layer].style.left);
  } else {
  	id = document.getElementById(layer);
    return parseInt (id.style.left);
  }
}


// pixel value for top edge of layer
function getTop(layer) {

  if (is_nav4up && !is_gecko) {
    return document.layers[layer].top;
  } else if (is_ie4) {
  	return parseInt (document.all[layer].style.top);
  } else {
  	id = document.getElementById(layer);
    return parseInt (id.style.top);
  }
}


// pixel value for width of layer
function getWidth(layer) {

  if (is_nav4up && !is_gecko) {
    return document.layers[layer].clip.width;
  } else if (is_ie4) {
  	return document.all[layer].offsetWidth;
  } else {
  	id = document.getElementById(layer);
  	w = id.offsetWidth;
    return w;
  }
}


// pixel value for height of layer
function getHeight(layer) {

  if (is_nav4up && !is_gecko) {
    return document.layers[layer].clip.height;
  } else if (is_ie4) {
  	return document.all[layer].offsetHeight;
  } else {
  	id = document.getElementById(layer);
  	h = id.offsetHeight;
    return h;
  }
}



// pixel value for left of image
function getImageXfromLeft(imgID) {
 if (is_nav4up && !is_gecko) {
  	xPos =  eval("document."+imgID+".x");
  	return xPos;
  } else if (is_ie4) {
    id = document.all[imgID];
    return getRealLeft(id);
  } else {
  	id = document.getElementById(imgID);
  	return getRealLeft(id);
  }
}


// pixel value for top of image
function getImageYfromTop(imgID) {
  if (is_nav4up && !is_gecko) {
  	yPos =  eval("document."+imgID+".y");
  	yPos += eval("document."+imgID+".height");
  	return yPos;
  } else if (is_ie4) {
    id = document.all[imgID];
    return getRealTop(id);
  } else {
  	id = document.getElementById(imgID);
  	return getRealTop(id);
  }
}



// IE + GECKO pixel value for left of image
function getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}


// IE + GECKO pixel value for top of image
function getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
  	yPos += eval(imgElem).height;
	return yPos;
}



// moves position of layer
function moveLayerTo(layer, x, y) {

  if (is_nav4up && !is_gecko) {
  	document.layers[layer].moveTo(x, y);
  } else if (is_ie4) {
  	document.all[layer].style.left = x;
  	document.all[layer].style.top = y;
  } else {
  	id = document.getElementById(layer);
    id.style.left = x;
    id.style.top  = y;
  }
}



// move position of layer handler
function positionLayer(layer,imgID){
	x = getImageXfromLeft(imgID);
	y = getImageYfromTop(imgID);
	moveLayerTo(layer, x, y);
	if (is_nav4up && !is_gecko) {
		visi = document.layers[layer].visibility;
	} else if (is_ie4) {
  		visi = document.all[layer].style.visibility;
	} else {
		visi = document.getElementById(layer).style.visibility;
	}

	if (visi == "hidden" || visi == "hide") showLayer(layer)
	else hideLayer(layer)
}



function rollover(layer,imgID) {

	if (currMenu != 0) {
		x = getImageXfromLeft(imgID);
		y = getImageYfromTop(imgID);
		moveLayerTo(layer, x, y);
		
		if (is_nav4up && !is_gecko) {
			visi = document.layers[layer].visibility;
		} else if (is_ie4) {
  			visi = document.all[layer].style.visibility;
		} else {
			visi = document.getElementById(layer).style.visibility;
		}
	
		if (visi == "hidden" || visi == "hide") {
			showLayer(layer)
		} else if (layer != currMenu) {
			hideLayer(layer)
		}
	}

}




// hides a layer
function hideLayer(layer) {
  currMenu = 0;
  if (is_nav4up && !is_gecko) {
  	document.layers[layer].visibility = "hidden";
  } else if (is_ie4) {
  	document.all[layer].style.visibility = "hidden";
  } else {
  	document.getElementById(layer).style.visibility = "hidden";
  }
}


// shows a layer
function showLayer(layer) {
  clearTimeout(menuTimeout);// clears the menu clear timeout

  if (currMenu != 0) { // turn off the old menu layer
  	hideLayer(currMenu);
  	currMenu = layer;
  } else {
  	currMenu = layer;
  }

  if (is_nav4up && !is_gecko) {
  	document.layers[layer].visibility = "show";
  } else if (is_ie4) {
  	document.all[layer].style.visibility = "visible";
  } else {
  	document.getElementById(layer).style.visibility = "visible";
  }
}


