var geo_list_cache = {};
var geo_current_list = null;

function set_list_county(type, el_link)
{
	var mode = null;
	if(typeof el_link == "string") {
		mode = "reload";
		//var type = el_link.replace(/^(haltagare|leverantorer)-([\w_]+)$/, "$1");
		var page = el_link.replace(/^([\w_]+)$/, "$1");
		var uri = page + ".html";
		//if(!el_link.match(/^([\w_]+)$/)) {
		//	$("#members > ul").tabs("select", "l" + type);
		//	return false;
		//}
	}
	else {
		mode = "click";
		var uri = el_link.href.replace(/^(.*)#.*/, "$1");
		var page = uri.match(/.+\/([\w_]+)\.html(#.*)?$/) ? uri.replace(/.+\/([\w_]+)\.html(#.*)?$/, "$1") : null;
	}

	//$("#members > ul").tabs("select", "l" + type);

	var cache_id = (page ? (page) : "");

	geo_current_list = cache_id;

	if(geo_list_cache[cache_id]) {
		$("#lmember div.companylist").replaceWith(geo_list_cache[cache_id]);
		// Set location to internal link
		window.location.hash = "#" + cache_id;
	}
	else {
		$("#lmember div.companylist").replaceWith("<div class=\"companylist\"><img src=\"../_gfx/loader.gif\" alt=\"Laddar...\"/></p>");

		$.get(uri, { ajax: 'list', type: type }, function(data, status) {
			var list = data; //$("div.companylist", data);
			geo_list_cache[cache_id] = list;
			$("#lmember div.companylist").replaceWith(list);
			// Set location to internal link
			window.location.hash = "#" + cache_id;
		}, 'html');
	}

	return false;
}


// Used on indivual members' pages
function geo_draw_map()
{
	$("<div id='contact-geo-map'><img src='../_gfx/sverigekarta.png' alt='' usemap='#countymap' /></div>").insertBefore("#contact-geo h3");
	$("#contact-geo-map img[usemap]").maphilight({stroke: false, fillColor: "3399ff", fade: false, alwaysOn: true});
	$("map#countymap area").css({cursor: 'default'}).bind("click", function(){ return false; });
	$("map#countymap area").tooltip({ delay: 0, track: false, positionLeft: true, showURL: false });
}

