// activate the district on the map
function actDistrict(a) {
	
	var m = document.getElementById("map-nm");
	var p = (a) * 172;
	
	// reposition the map image to highlight the proper district
	m.style.backgroundPosition = (p > 0) ? "0 -"+p+"px" : "0 0";	
	
	var md = document.getElementById("map-details");
	var dist = __DISTRICTS__[a];
	var cont = (dist.name != "") ? "<h3>" + dist.name + "</h3>": "";
	cont += (dist.blurb != "") ? "<p>" + dist.blurb + "</p>": "";
	cont += (dist.image != "") ? "<div class='iya-image'><img src='" + dist.image + "' /></div>": "";
	
	md.innerHTML = cont;
	
	// load local content
	if (a > 0) actDistrictInfo(a);
	
	return false;
}

// shows selected district info
function actDistrictInfo(a) {
	var content = document.getElementById("in_your_area-content");
	content.innerHTML = "<p style='margin-top: 20px; text-align: center'><img src='/images/preloader.gif' title='Loading...' /></p>";
	
	loadDistrictInfo(a);
	
	return false;
}


function
loadDistrictInfo(a) {
	var url = "/templates/found_locally.cfm?district=" + a;
	var cbDistrictInfo = {
		success: function(o) {
			var content = document.getElementById("in_your_area-content");
			content.innerHTML = o.responseText;
			runScripts(content);
		},
		failure: function(o) {
			var content = document.getElementById("in_your_area-content");
			content.innerHTML = "Failed to load content.  Please try again later.";
		}
	};
	var transaction = YAHOO.util.Connect.asyncRequest('GET', url, cbDistrictInfo, null);
	
	return false;
}

function makeLink(a) {
	return (a) ? "<a href='" + a.url + "' title='View " + a.label + "'>" + a.label + "</a>": "none";
}

// clears district info
function deactDistrictInfo() {
	document.getElementById("districtinfo").innerHTML = "";
	return false;
}

(function() {
	YAHOO.util.Event.onDOMReady(function () {
		actDistrict(0);	
	});
})();


