if (document.getElementById) {

	window.onload = function() {
	
		initializeMenu("ccommsMenu", "ccommsActuator");
		initializeMenu("cwrMenu", "cwrActuator");
		initializeMenu("personMenu", "personActuator");

		forLinks();
		preloadMenuImages();
	}
}
//Preload menu bkgd images
//This only works properly in IE?!at least is a bit wierd...
function preloadMenuImages() {
	
	var these_images = new Array("/images/buttonroll.gif","/images/UL_bkgd1.gif","/images/UL_bkgd2.gif","/images/UL_bkgd3.gif")
	loadTheseImages(these_images);

}
function loadTheseImages(images_array){

	for (var i = 0; i < images_array.length; i++) {
		var one_image = new Image();
		one_image.src = images_array[i];
	}
}

//  Menu buttons
var currentMenu = null;

if (!document.getElementById) {
    document.getElementById = function() { return null; }
}

function initializeMenu(menuId, actuatorId) {
    
	var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;
  
    actuator.onclick = function() {
	
		if (currentMenu != null) {
		currentMenu.style.display = "none";
		}
        if (currentMenu != menu) {
            this.showMenu();
        }
        else {
            currentMenu.style.display = "none";
            currentMenu = null;
        }
        return false;
    }

    actuator.showMenu = function() {
        menu.style.display = "block";
        currentMenu = menu;
    }
}

/*for links: open in new window, ...*/
function forLinks() {

	//'a'-tag array
	var all_a_tags = document.getElementsByTagName("a");

//nested loops search through page for links meeting these criteria, set variables, and send to functions
	for (var tag = 0; tag < all_a_tags.length; tag++) {

		//new_win starts	
		var attr = all_a_tags[tag].getAttribute("title");
		
		if (attr != null) {
		
			var marker = attr.indexOf("(") + 1;
			var sub_attr = attr.substring(marker, attr.length - 1);
		}
				
		if (sub_attr == "opens in new window") {
	
			var new_win = all_a_tags[tag];
			var link_address = all_a_tags[tag].getAttribute("href");
			linkInNew(new_win, link_address);
		}	
	}
	//opens new windows
	function linkInNew(new_win, link_address)	{

		new_win.onclick = function() {
	
			//needs link_address variable
			var new_window = window.open(link_address,'external');
			new_window.focus();
			return false;
		}
	}
}
/*for links: function ENDS*/