/**
 * @author www.designbyflare.com
 */

var wardData;
var ni_ageAtDeath = '79.0';
var ni_mortalityRatio = '100%';
var ni_relativePoverty = '30.2%';
var ni_longTermIllness = '20.4%';
var ni_goodHealth = '70%';
	
$(document).ready(function() {

	// Set default stats on page load
	niStats();
	
	// Retrieve the ward xml data 
  $.ajax({
    type: "GET",
    url: "areas.xml",
    dataType: "xml",
    success: storeData
  });
	
	 // Area tooltip
	
	 $('#m_wards area').each(function()
   {
      $(this).qtip(
      {
         content: $(this).attr('alt'),
  			 position: { target: 'mouse' },
         style: {       	
      			padding: 5,
      			background: '#7A0D01',
      			color: '#ffffff',					
						textAlign: 'center',
      			border: {
         			width: 2,
         			radius: 2,
         			color: '#392020'
      			},
					  tip: true
         }
      });
   });
	 
	$('#m_wards area').click(function() {
		var wardName = $(this).attr('alt');
				
		$('#wardName').text(wardName);
				
		// Find data for selected ward 
		$(wardData).find("ward[name='"+wardName+"']").each(function(){
			$('#Pct_trust_neighbours').text($(this).attr("Pct_trust_neighbours")); 		 				
			$('#Pct_smoke').text($(this).attr("Pct_smoke"));
			$('#DSR_adm_alcohol').text($(this).attr("DSR_adm_alcohol"));
			$('#Pct_child_vaccination').text($(this).attr("Pct_child_vaccination"));
			$('#Rate_suicide').text($(this).attr("Rate_suicide"));
			$('#Rate_adm_psych_hosp').text($(this).attr("Rate_adm_psych_hosp"));
			$('#Life_expectancy_Male').text($(this).attr("Life_expectancy_Male"));
			$('#Life_expectancy_Female').text($(this).attr("Life_expectancy_Female"));
			$('#Rate_infant_mortality').text($(this).attr("Rate_infant_mortality"));
			$('#PYLL').text($(this).attr("PYLL"));
  	});											
	});
 
	
});




// Sets the default NI stats
function niStats() {
//$('#wardName').text('Choose a region');
	
}

// Store the retrieved data in a local variable
function storeData(xml) {
	wardData = xml;
}