var linksTot = 7;
var nav1BG = 85;
var nav1Width1 = 132;
var nav1Width2 = 132;
var nav1Width3 = 132;
var nav1Width4 = 132;
var nav1Width5 = 132;
var nav1Width6 = 132;

function setup() {
	// FORCES OUTBOUND LINKS TO OPEN IN A NEW WINDOW UNLESS EXPLICITLY TOLD OTHERWISE (rel="self" in anchor)
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var URL = anchors[i].href;
		if (URL.search('amishpie')===-1 && URL.search('http')!==-1 && anchors[i].rel !== 'self') anchors[i].target = "_blank";
	}
	
	// Compares the width of the text in top links to the width of the background image that appears during hover. If the width of the text is less than that image, the text is given a margin to compensate, so the hover image appears centered with the text. Otherwise, it would appear flush right.
/*
	for (i=0 ; i<linksTot ; i++) {
		var linkWidth = document.getElementById('link'+(i+1)).childNodes[0].offsetWidth;
		if (linkWidth < nav1BG) {
			var result = (nav1BG-linkWidth)/2;
			result = result.toFixed(0);
			document.getElementById('link'+(i+1)).childNodes[0].style.marginRight = result + 'px';
		}
	}
*/
	
	// Compares the height of the middle and right colums (if they both exist) and makes sure they appear to be the same height. Also compares both columns to the left navigation to make sure they are both at least the height of that area.
	var diff = 11; // Differential between the amount of padding/border on the bottom of each object
	var diff2 = 25; // Phantom differential
	if (document.getElementById('nav2')) var compareBase = document.getElementById('nav2').offsetHeight;
	if (document.getElementById('middle')) var compareMe1 = document.getElementById('middle').offsetHeight;
	if (document.getElementById('right')) var compareMe2 = document.getElementById('right').offsetHeight;
	if (document.getElementById('middle2')) var compareMe3 = document.getElementById('middle2').offsetHeight;
	if (compareMe1 && (compareBase > compareMe1)) { 
		document.getElementById('middle').style.height = (compareBase) + 'px';
		var trigger1 = 1;
	}
	if (compareMe3 && (compareBase > compareMe3)) { 
		document.getElementById('middle2').style.height = (compareBase) + 'px';
		var trigger1 = 1;
	}
	if (compareMe2 && (compareBase > (compareMe2+11))) {
		document.getElementById('right').style.height = (compareBase+diff) + 'px';
		var trigger2 = 1;
	}
	if(compareMe1 && compareMe2 && (trigger1+trigger2!==2)) {
		if (compareMe1 > (compareMe2+diff)) {
			document.getElementById('right').style.height = (compareMe1-diff2) + 'px';
		} else if ( compareMe1 < (compareMe2+diff) ) {
			document.getElementById('middle').style.height = (compareMe2-diff-diff2) + 'px';
		}
	}
}

// Compares the width of the text in top links to the width of the background image that appears during hover. If the width of the text is more than that image, the image's background position is precisely calculated so it appears to be centered with the text. Otherwise, it would appear flush right.
function nav1Hover(foo) {
/*
	var linkWidth = document.getElementById('link'+foo).childNodes[0].offsetWidth;
	if (foo === 1) var nav1Width = nav1Width1;
	if (foo === 2) var nav1Width = nav1Width2;
	if (foo === 3) var nav1Width = nav1Width3;
	if (foo === 4) var nav1Width = nav1Width4;
	if (foo === 5) var nav1Width = nav1Width5;
	if (foo === 6) var nav1Width = nav1Width6;
	if ( linkWidth > nav1BG) {
		var result = ((linkWidth-nav1BG)/2)
		result = result.toFixed(0);
		result = parseFloat(nav1Width)-parseFloat(linkWidth)+parseFloat(result);
		result = result + 'px 0px';
		document.getElementById('link'+foo).style.backgroundPosition = result;
	}
*/
}

// This function activates contact scripts
function activate(brillig) {
	document.getElementById('config').name = "config";
	document.getElementById('config').value = brillig;
}

window.onload = setup;
