var currentNav = null;
var navFrom = null;
var mainNavTimeOut = null;
var subNavTimeOut = null;
var mac_y_offset = 10;

function setCurrent() {
	currentNav = null;
}

function hide(layerToShow,origin) {
	var layer = document.getElementById(layerToShow);
	layer.style.visibility = "hidden";	  
}



function getPageCoordinates (layer) {

	var x = 0; y = 0;

	var element = document.getElementById(layer);
		
	do {
		x += element.offsetLeft;
		y += element.offsetTop;		
	}
	while ((element = element.offsetParent));
	
	return {x: x, y: y};
}


function show(layerToShow,x,y,relativeLayer) {
	if (relativeLayer) {
//		alert ("x:" + getPageCoordinates(relativeLayer).x + " y:" + getPageCoordinates(relativeLayer).y);
		if (is_mac) { 
			y += mac_y_offset;
		}
		
		x += getPageCoordinates(relativeLayer).x;	
		y += getPageCoordinates(relativeLayer).y;	
	}
	var layer = document.getElementById(layerToShow);
	layer.style.visibility = "visible";	  
	if (x && y) { layer.style.left=x; layer.style.top=y }
}


function on_main_nav(layerToShow,x,y,relativeLayer) {
	clearTimeout(subNavTimeOut);	
	clearTimeout(mainNavTimeOut);
	show (layerToShow,x,y,relativeLayer);	
	if ((currentNav != null) && (currentNav != layerToShow)) {
		hide(currentNav);		
	}
	if ((navFrom != null) && (navFrom != layerToShow)) {
		hide(navFrom);
	}
	currentNav = layerToShow;
}

function off_main_nav(layerToShow) {
	mainNavTimeOut = setTimeout("hide('" + layerToShow + "','main'); currentNav = null", 200);
}

function on_fly_nav(layerToShow,x,y,relativeLayer) {
	show(layerToShow,x,y,relativeLayer);	
	clearTimeout(subNavTimeOut);	
	clearTimeout(mainNavTimeOut);
	navFrom = null;	
}

function off_fly_nav(layerToShow) {
	subNavTimeOut = setTimeout("hide('" + layerToShow + "')",200);
	currentNav = null;
	navFrom = layerToShow;
}


// popup
// there are 2 ways of calling the popup script.  
// type 1: <a href="popup.html" onClick="popup('pop','','300','800','','')" target="pop">
// 			this way, the user can hold shift when he clicks on a link to load into a new window
// tyep 2: <a href="javascript:popup('pop','popup.html','500','100')">
//			you can't load this into a new window.  But you can run this from another script.
// you can also just call it, in a very simple way. <a href="popup.html" onClick="popup('pop')" target="pop">
function popup(target,url,width,height,bars,resize) {
	if (!url)		{ url = '' }
	if (!width) 	{ width = '500' }	
	if (!height) 	{ height = '400' }	
	if (!bars) 		{ bars = 'yes' }	
	if (!resize) 	{ resize = 'yes' }	
	window.open(url,target,"width=" + width + ",height=" + height + ",status=yes,menubar=no,toolbar=no,scrollbars=" + bars + ",resizable=" + resize)
}
