window.onresize = adjustLayout;

var sectionUrls = [ 'index.php', '', '', '', '', '', 'contact.php' ];
var isDropdown = [ false, true, true, true, true, true, false ];
var isLink = [ true, false, false, false, false, false, true ];
var menuOpen = [ false, false, false, false, false, false, false ];

var menuWidth;
var lastMenuWidth;

function adjustLayout() {
//	var pageWidth = getAvailWidth();
	document.getElementById('headerimg').src = "images/headersepia.jpg";
	var pageWidth = 775;
	var pageLeftPos = Math.max(Math.floor((getAvailWidth()-790)/2), 0);
	var leftPos = 0;
	
	var container = document.getElementById('container');
	document.getElementById('headerimg').style.left = leftPos + 'px';
	container.style.left = pageLeftPos + 'px';
//	container.style.minHeight = (getAvailHeight()-10) + 'px';	
	if( document.all ) {
//		container.style.height = (getAvailHeight()-10) + 'px';	
	}

	menuWidth = Math.floor((pageWidth-6)/7);
	lastMenuWidth = menuWidth + ((pageWidth - 6) % 7);

	for( var i=0 ; i<7 ; i++ ) {
		var menuButton = document.getElementById('buttondiv'+i);
		if( isDropdown[i] ) {
			var menuDiv = document.getElementById('menudiv'+i);
			var menuTable = document.getElementById('menutable'+i);
			menuDiv.style.left = (i*menuWidth+i+Math.max(0, leftPos)) + 'px';
		}
		
		menuButton.style.left = (i*menuWidth+i+Math.max(0, leftPos)) + 'px';
		
		if( i < 6 ) {
			menuButton.style.width = menuWidth + 'px';
			if( isDropdown[i] ) {
				menuTable.style.width = menuWidth + 'px'
			}
		} else {
			menuButton.style.width = lastMenuWidth + 'px';
			if( isDropdown[i] ) {
				menuTable.style.width = lastMenuWidth + 'px';
			}
		}
	}
}

function getAvailWidth() {
	var winWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winWidth = document.body.clientWidth;
	}
	return Math.max(winWidth, 622);
}
function getAvailHeight() {
	var winHeight = 0;
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		winHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winHeight = document.body.clientHeight;
	}
	return Math.max(winHeight, 0);
}

function overMe(obj, id) {
	menuOpen[id] = true;
/*	obj.style.backgroundColor = "#3a7fcc";*/
	obj.style.backgroundColor = "#AA0000";
	for( var i=0 ; i<7 ; i++ ) {
		if( isDropdown[i] && i != id ) {
			document.getElementById('menudiv'+i).style.visibility = 'hidden';
		}
	}
	if( isDropdown[id] && obj.id.indexOf("buttondiv") > -1 ) {
		var menu = document.getElementById('menudiv'+id);
//		document.getElementById('menutable'+id).style.width = menuWidth + 'px';
//		menu.style.left = id * menuWidth + id + Math.max(0, Math.floor((getAvailWidth()-775)/2)) + 'px';
		menu.style.visibility = 'visible';
	}
}


function outMe(obj, id) {
//	obj.style.backgroundColor = "#1c5596";
	obj.style.backgroundColor = "#660000";
	menuOpen[id] = false;
	if( isDropdown[id] ) {
		setTimeout("if(!menuOpen["+id+"]){document.getElementById('menudiv"+id+"').style.visibility='hidden';}", 500);
	}
}
function clickedMe(obj, id) {
	if( isLink[id] ) {
		window.location = sectionUrls[id];
	}
}


function goNow(url) {
	window.location = url;
}