$(document).ready(function() {
  function updateWeather() {
    $.ajax({
      type: "GET",
      url: "http://www.theoitavos.com/weatherxml.php",
      dataType: "xml",
      success: parseXml,
      oncomplete: setTimeout(updateWeather, 30000)
    });
  }
  function parseXml(xml) {
     var d = new Date();
     var utchours = d.getUTCHours();
     // check for daylight savings time, this can change year to year
     // but should be within a day or so, starts March 28, ends Oct 31
     var dstStart = new Date();
     dstStart.setFullYear(d.getYear(),2,28);
     var dstEnd = new Date();
     dstEnd.setFullYear(d.getYear(),9,31);
     if (d > dstStart && d < dstEnd) {
        // daylight savings time, may look funky at midnight
        utchours += 1;
     }
     var ampm = " AM";
     if (utchours > 12) {
        utchours -= 12;
        ampm = " PM";
     }

     var utcmins = d.getUTCMinutes();

     if (utcmins < 10) {
        utcmins = "0" + utcmins;
     }
     var curtime = utchours + ":" + utcmins + ampm + " ";
     var weathercode = $(xml).find("current_condition").find("weatherCode").text();
     var weatherimage = "<img src=\"images/weatherxml/weather_" + weathercode + ".png\"/> ";
     var temp = $(xml).find("current_condition").find("temp_C").text() + "&#186; C";
     $("#weather").html(curtime + weatherimage + temp);
  }

  updateWeather();

});

