// Initialises the navbar after the DOM is in place.
// Copyright 2008, Tom Lloyd
// Last edited 2008.09.21

// Make these two handy vars
var navbar = document.getElementById('navbar').getElementsByTagName('TR')[0];
var navboxes = navbar.getElementsByTagName('TD');

// Set up these menu parameters
var D_minwidth = 1; // How narrow should the menus refold to?
var D_minheight = navbar.offsetTop + navbar.offsetHeight + 1; // How low should the menus descend?

// Some browsers apparently need 'px' on the end of pixel sizes, some don't.  Sigh...
var noPx = document.childNodes ? 'px' : 0;

// Build an array of all the clickable nav links
var navlinks = new Array();
var biglist = document.getElementsByTagName('A');
for( var i in biglist ) {
	if( biglist[i].className == 'navbar' ) {
		navlinks[navlinks.length] = biglist[i];
	}
}

// Build an array of all the menus
var navmenus = new Array();
var biglist = document.getElementsByTagName('DIV');
for( var i in biglist ) {
	if( biglist[i].className == 'navmenu' ) {
		navmenus[navmenus.length] = biglist[i];
	}
}

// Move the menus to the correct locations
for( var i in navmenus ) {
	
	// Figure out which navbox relates to the menu we're currently dealing with
	var menuParent = document.getElementById( 'nav_' + navmenus[i].id.substring(5) ).parentNode
	
	// First set the menu's left-position to that of its parent navbox
	navmenus[i].style.left = menuParent.offsetParent.offsetLeft + menuParent.offsetLeft + noPx;
	
	// Store the original width and then shrink it down
	navmenus[i].fullWidth = navmenus[i].offsetWidth;
	navmenus[i].style.width = D_minwidth + noPx;
	
	// Hide the menu just out of sight, for minimal delay when it drops down
	navmenus[i].style.top = 0-navmenus[i].offsetHeight + noPx;
	
}


/*
	Image-swapping code
*/

function navpic(pic) {
	document.getElementById('navimg').src = '/navbar/' + pic + '.gif';
}

// Preload the navpics
var preload = new Array();
for( var i in navlinks ) {
	preload[i] = new Image();
	preload[i].src = '/navbar/' + navlinks[i].id.substring(4) + '.gif';
}


// I've kept this code because it looks pretty in Kate's syntax hilighting.
if( 0 ) {

// Preload the navpics
var navimgs = new Array(
	'blank_ym.gif',
	'home.gif',
	'pictaes.gif',
	'intel.gif',
	'os.gif',
	'contact.gif',
	'paper.gif',
	'intel_pyr.gif',
	'intel_circle.gif',
	'os_pyr.gif',
	'os_phpfinder.gif'
);
var preload = new Array(); 
for( var i=0; i<navimgs.length-1; i++ ) {
	preload[i] = new Image();
	preload[i].src = '/navbar/' + navimgs[i];
}}
