$(document).ready(function(){

  if (typeof(media_domain)=='undefined') { media_domain = ''; }
  if (typeof(subdir)=='undefined') { subdir = ''; }
 
  var index_base_url = media_domain+'/static/images/mi/third_party/accuweather/indices/';

  if (typeof(override_image_dir)!='undefined') { index_base_url = media_domain + override_image_dir; }

  $.ajax({
	type: "GET",
	url: "/static/accuweather/" + subdir + "current.xml",
	dataType: "xml",
	success: function(xml) {

	var UVIndex =     $(xml).find('currentconditions').find('uvindex').text(); 
	var UVImageURL =  index_base_url+'everything_else/'+UVIndex+'.jpg';

	$("#healthIndex #indexTitle1").html('UV Index');
	$("#healthIndex #indexImage1").html('<img src="'+UVImageURL+'" />');

	// Replace zipcode in links with proper one
	var zipcode = $(xml).find('zipcode').text();
	var location = $(xml).find('local').find('city').text()+', '+$(xml).find('local').find('state').text();

	var href = $("#healthIndex #indexProfile").attr('href');
	$("#healthIndex #indexProfile").attr('href',href.replace(/zipcode=\d*/, "zipcode="+zipcode));
	$("#healthIndex #indexProfile").append(location);
    }
  });

  $.ajax({
	type: "GET",
	url: "/static/accuweather/" + subdir + "pollen.xml",
	dataType: "xml",
	success: function(xml) {

	var AQIndex =     $(xml).find('airandpollen').find('airquality').text(); 
	var AQImageURL =  index_base_url+'air_quality/'+AQIndex+'.jpg';
	$("#healthIndex #indexTitle2").html('Air Quality Index');
	$("#healthIndex #indexImage2").html('<img src="'+AQImageURL+'" />');

  var WeedIndex =     $(xml).find('airandpollen').find('overall').text(); 
	var WeedImageURL =  index_base_url+'pollen/'+WeedIndex+'.jpg';
	$("#healthIndex #indexTitle3").html('Pollen Index');
	$("#healthIndex #indexImage3").html('<img src="'+WeedImageURL+'" />');

    }
  });

});

