var counties = new Array(
	"tooele",
	"carbon",
	"washington",
	"grand",
	"uintah",
	"saltlake",
	"emery",
	"wasatch",
	"sanpete",
	"juab",
	"millard",
	"summit",
	"wasatch",
	"weber",
	"sevier",
	"pt",
	"davis",
	"piute",
	"sanjuan",
	"boxelder",
	"beaver",
	"kane",
	"cache",
	"duchesne",
	"utah",
	"morgan",
	"rich",
	"garfield",
	"iron", 
	"wayne",
	"daggett"
);

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);
			btn.onmouseover = function() { show(this.id.replace(/btn_/, "popup_")); }
			btn.onmouseout = function() { hide(this.id.replace(/btn_/, "popup_")); }
			popup.onmouseover = btn.onmouseover;
			popup.onmouseout = btn.onmouseout;
		}
	}
	window.onbeforeunload = cleanup;
}
