var counties = new Array(
	"BYU",
	"CSU",
	"WSU",
	"WRCA",
	"UofU"
);

function show(elem_id)
{	
	var elem = document.getElementById(elem_id); 
	if( elem ) { show_element(elem); }
}

function hide(elem_id)
{	
	var elem = document.getElementById(elem_id); 
	if( elem ) { hide_element(elem); }
}

function hide_element(element) { if( element && element.style ) { element.style.display = "none"; } }
function show_element(element) { if( element && element.style ) { element.style.display = "block"; } }

function cleanup()
{
	for( i in counties ) 
	{
		var popup = document.getElementById("popup_" + counties[i]); 
		if( popup ) { hide_element(popup); }
	}
}

function init_county_map()
{
	for( i in counties ) 
	{
		var popup_name = "popup_" + counties[i];
		var btn_name = "btn_" +  counties[i];
		
		var popup = document.getElementById(popup_name); 
		var btn = document.getElementById(btn_name); 
		if( btn && popup )
		{
			hide_element(popup);
			
			// Save any previous mouseover and mouseout functions, if any, to call before 
			// popup code.
			btn.lastmouseover = btn.onmouseover;
			btn.lastmouseout = btn.onmouseout;
			
			btn.onmouseover = function() { if(this.lastmouseover) { this.lastmouseover(); } show(this.id.replace(/btn_/, "popup_")); }
			btn.onmouseout = function() { if(this.lastmouseout) {this.lastmouseout(); } hide(this.id.replace(/btn_/, "popup_")); }
			popup.onmouseover = btn.onmouseover;
			popup.onmouseout = btn.onmouseout;
		}
	}
	window.onbeforeunload = cleanup;
}