var boroughs = {
	changeHighlightedBorough : function (region) {
		$('#map').removeClass();
		$('#map').addClass(''+region+'-hover');
	}
	
	, clearAll : function () {
		$('#map').removeClass();
	}	

	, getBoroughData : function (region) {
		$.ajax({
			  url      : '/how/boroughs/' + region
			, dataType : 'json'
			, success  : boroughs.updateBoroughData
		});		
	}
	, updateBoroughData : function (data,textStatus) {
		if(0 === data.boroughs.length) {
			return false;
		}
		
		$('#borough-stats').show();
		$('#map-profiler h3').show();
		
		$('#map-profiler h3').html(data.boroughs[0].title);
		
		$('#borough-area').html(data.boroughs[0].area);
		$('#borough-population').html(data.boroughs[0].population); 
		$('#borough-unemployment').html(data.boroughs[0].unemployment); 
		$('#borough-office-rent').html(data.boroughs[0].officerent); 
		$('#borough-industrial-rent').html(data.boroughs[0].industrialrent); 
		$('#borough-land-price').html(data.boroughs[0].landprice); 
		$('#borough-house-price').html(data.boroughs[0].houseprice); 
		$('#borough-weekly-earnings').html(data.boroughs[0].weeklyearnings); 
		
	}
};

$(function (e) {
	$('#borough-stats').hide();
	$('#map-profiler h3').hide();
	
	$('#map a').mouseover(function (e) {
		boroughs.changeHighlightedBorough(e.target.id);
	});
	
	$('#map a').mouseout(function (e) {
		boroughs.clearAll();
	});
	
	$('#map a').click(function (e) {
		e.preventDefault();
		boroughs.getBoroughData(e.target.id);
	});
});
