// This script is reasonably profient until it gets to line 73, and then it gets
// inefficent. I need to look into those addLoadListener and attachEvent methods!

function teamGuide() 
{
	// Create some empty arrays to work with
	var preLoad = new Array();
	var hovers  = new Array();
	var areas   = new Array();
	var menu    = new Array();

	var src = "/img/team0.gif";
	var src2 = src;
	var stop = 0;
	
	for (var i = 1; i < 5; i++) 
	{
		
		var tmpSrc = "/img/team" + i + ".gif";
		
		// Populate the menu array
		if (!document.getElementById) return	
		menu[i] = document.getElementById("team" + i);
		
		// If the menu item is a <strong> element, use its id in the image reset src
		if (menu[i].nodeName == "STRONG")
		{
			src = tmpSrc;
			src2 = tmpSrc;
			stop = i;
		}
		else
		{			
			// It must be a link <a>, so...
			// Set the area href attribute to the same as its corresponding menu item 
			areas[i] = document.getElementById("area" + i);
			areas[i].href = menu[i].href;

			// Set up an image to swap to
			hovers[i] = tmpSrc;

			// Preload the image to be swapped
			preLoad[i] = new Image();
			preLoad[i].src = hovers[i];
		}
		
		// Set the area title attribute to the same as its corresponding menu item textNode
		areas[i] = document.getElementById("area" + i);
		if (menu[i].firstChild.nodeType == "3")
		{
			areas[i].title = menu[i].firstChild.nodeValue; 
		}
		
	}

	// Get wrapper div 
	var wrapper = document.getElementById("team-wrapper");

	// Create and insert a new image 
	if (!document.createElement) return	
	var img = document.createElement("img");

	if (!document.appendChild) return	
	wrapper.appendChild(img);

	// Set its attributes
	img.setAttribute("usemap","#team-map", 0); // third argument, '0', is to remove case-sensitivity for Explorer: won't work otherwise!
	img.setAttribute("alt", "Guide to the team image above");
	img.setAttribute("src",src);

	
	// Image swapping from image map areas 
	areas[1].onmouseover = function()
		{	if (stop != 1) {img.src = hovers[1];} }

	areas[2].onmouseover = function()
		{	if (stop != 2) {img.src = hovers[2];} }

	areas[3].onmouseover = function()
		{	if (stop != 3) {img.src = hovers[3];} }

	areas[4].onmouseover = function()
		{	if (stop != 4) {img.src = hovers[4];} }

	areas[1].onmouseout = function() 
		{	if (stop != 1) {img.src = src2;} }

	areas[2].onmouseout = function() 
		{	if (stop != 2) {img.src = src2;} }

	areas[3].onmouseout = function() 
		{	if (stop != 3) {img.src = src2;} }

	areas[4].onmouseout = function() 
		{	if (stop != 4) {img.src = src2;} }

	// Image swapping from menu links 
	menu[1].onmouseover = function()
		{	if (stop != 1) {img.src = hovers[1];} }

	menu[2].onmouseover = function()
		{	if (stop != 2) {img.src = hovers[2];} }

	menu[3].onmouseover = function()
		{	if (stop != 3) {img.src = hovers[3];} }

	menu[4].onmouseover = function()
		{	if (stop != 4) {img.src = hovers[4];} }

	menu[1].onmouseout = function() 
		{	if (stop != 1) {img.src = src2;} }

	menu[2].onmouseout = function() 
		{	if (stop != 2) {img.src = src2;} }

	menu[3].onmouseout = function() 
		{	if (stop != 3) {img.src = src2;} }

	menu[4].onmouseout = function() 
		{	if (stop != 4) {img.src = src2;} }

}

window.onload = teamGuide;