// Functions for the navbar
// Copyright (god knows when) - 2008, Tom Lloyd
// Last edited 2008.09.21


/*
	Menu-moving functions
*/

function dropmenu(menu) {
	
	// Get the browser's version of where the layer is
	// (possibly with a 'px' stuck on the end)
	// (or possibly nothing at all)
	menuheight = document.getElementById("menu_"+dm).style.top;

	// Convert whatever the browser's thrown at me into a proper number
	menuheight = parseInt(menuheight);
	
	// Do the business
	if( menuheight < D_minheight ) {
		menuheight++;
		document.getElementById("menu_"+dm).style.top = menuheight + noPx;
		setTimeout( 'dropmenu(\''+menu+'\')', 1 );
	} else {
		setTimeout( 'openmenu(\''+menu+'\')', 200 );
	}
}

function openmenu(menu) {
	
	var theMenu = document.getElementById("menu_"+dm);
	
	// Get the browser's version of where the layer is
	// (possibly with a 'px' stuck on the end)
	// (or possibly nothing at all)
	menuwidth = theMenu.style.width;

	// Convert whatever the browser's thrown at me into a proper number
	menuwidth = parseInt(menuwidth);
	
	// Do the business
	if( menuwidth < theMenu.fullWidth ) {
		menuwidth++;
		theMenu.style.width = menuwidth + noPx;
		setTimeout( 'openmenu(\''+menu+'\')', 5 );
	}
}

function closemenu(menu) {
	// Get the browser's version of where the layer is
	// (possibly with a 'px' stuck on the end)
	// (or possibly nothing at all)
	menuwidth = document.getElementById("menu_"+menu).style.width;

	// Convert whatever the browser's thrown at me into a proper number
	menuwidth = parseInt(menuwidth);
	
	// Do the business
	if( menuwidth > D_minwidth ) {
		menuwidth--;
		document.getElementById("menu_"+menu).style.width = menuwidth + noPx;
		setTimeout( 'closemenu(\''+menu+'\')', 5 );
	} else {
		setTimeout( 'hoistmenu(\''+menu+'\')', 200 );
	}
}

function hoistmenu(menu) {
	
	var theMenu = document.getElementById("menu_"+menu);
	
	// Get the browser's version of where the layer is
	// (possibly with a 'px' stuck on the end)
	// (or possibly nothing at all)
	menuheight = theMenu.style.top;

	// Convert whatever the browser's thrown at me into a proper number
	menuheight = parseInt(menuheight);
	
	// Do the business
	if( menuheight > (0-theMenu.offsetHeight) ) {
		menuheight--;
		theMenu.style.top = menuheight + noPx;
		setTimeout( 'hoistmenu(\''+menu+'\')', 1 );
	}
}

// This function has slight bugs, but I like them, so they stay :)
var dm = ''; // No menus open to begin with
function navmenu(menu) {
	if( dm != menu ) { // Opening a new menu
		if( dm == '' ) { // No menu yet open
			dm = menu
			dropmenu(dm);
		} else {
			closemenu(dm);
			dm = menu;
			dropmenu(dm);
		}
	} else { // Closing the current menu
		closemenu(dm);
		dm = '';
	}
}


