// Specify the width of the top navigation menu
var topNav = 960;

// Site URL
domain = 'weaverville.com';

function menuSwitch(foo) {
	menuOff();
	var margin = 0;
	for (i=1 ; i<foo ; i++) {
		margin = parseFloat(margin) + document.getElementById('nav1_'+i).offsetWidth;
	}
	document.getElementById('submenu'+foo).style.display = 'block';
	if (document.getElementById('nav1_'+foo).offsetWidth > document.getElementById('submenu'+foo).offsetWidth) {
		var bigger = document.getElementById('nav1_'+foo).offsetWidth;
		var smaller = document.getElementById('submenu'+foo).offsetWidth;
		margin = parseFloat(margin) + parseFloat(((bigger-smaller)/2).toFixed(0));
	}
	var navsWidth = 0;
	var navItems;
	navItems = document.getElementsByTagName('li');
	for (i=0 ; i<navItems.length ; i++) {
		if (navItems[i].className === 'topnav') navsWidth = parseFloat(navsWidth) + parseFloat(navItems[i].offsetWidth);
	}
	margin = parseFloat(margin) + ((topNav-parseFloat(navsWidth))/2);
	document.getElementById('submenu'+foo).style.marginLeft = margin+'px';
}

function menuOff() {
	var submenus;
	submenus = document.getElementsByTagName('ul');
	for (i=0 ; i<submenus.length ; i++) {
		if (submenus[i].className === 'hidden') submenus[i].style.display = 'none';
	}
}

// Activate contact forms for browsers with JS enabled (activate inline otherwise)
function activate(brillig) {
	document.getElementById('config').name = "config";
	document.getElementById('config').value = brillig;
}

window.onload = setup;