var geo_list_cache = {};
var geo_current_list = { haltagare: null, leverantorer: 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(/^(haltagare|leverantorer)-([\w_]+)$/, "$2");
		var uri = page + ".html";
		if(!el_link.match(/^(haltagare|leverantorer)-([\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 = type + (page ? ("-" + page) : "");

	geo_current_list[type] = cache_id;

	if(geo_list_cache[cache_id]) {
		$("#l" + type + " div.companylist").replaceWith(geo_list_cache[cache_id]);
		// Set location to internal link
		window.location.hash = "#" + cache_id;
	}
	else {
		$("#l" + type + " 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;
			$("#l" + type + " div.companylist").replaceWith(list);
			// Set location to internal link
			window.location.hash = "#" + cache_id;
		}, 'html');
	}

	return false;
}

