﻿jQuery(document).ready(function ($) {
  $('#weather-data .loader').fadeIn();
  $.ajax({
    type: "GET",
    url: '/scripts/rss.ashx?url=http://www.weatheroffice.gc.ca/rss/city/on-118_e.xml',
    dataType: "xml",
    success: function (xml) {
      $(xml).find('item').each(function () {
        var $item = $(this);
        var title = $item.find('title').text();
        if (title.toLowerCase().substr(0, 7) == 'current') {
          var description = $item.find('description').text().replace(/<(?:.|\s)*?>/g, '');
          var cond = /condition\:(.*)/gi.exec(description)[1];
          var temp = /temperature\:(.*)/gi.exec(description)[1];
          var html = '';
          html += cond + '<br />';
          html += '<span>' + temp + '</span>';
          $('#weather-data').fadeOut(function () {
            $(this).html(html).fadeIn();
          });
          return false;
        }
      });
    }
  });
});
