$(function(){
  $.ajax({
    url: const_feed_url,
    async: true,
    cache: false,
    dataType:"xml",
    success: function(xml){
      $(xml).find('item').each(function(i){
        if ( i >= const_feed_max_count ) {
          return false;
        }
        //var title = $(this).find('title').text();
        var description = $(this).find('description').text();
        //var url = $(this).find('link').text();
        var date = new Date($(this).find('pubDate').text())
        //日付を整形
        var strDate = formatDate(date);
        var freshMsg = '';
        if(isFresh(date)) {
          freshMsg = const_feed_fresh_msg;
        }
        //id='feedList'のul(ol?)タグに要素を追加
        $('#feedList').append('<li class="list"><div class="newsDate">'+strDate+freshMsg+'</div><div class="newsDescription">'+description+'</div></li>');
      });
    }
  });
});

//投稿日時を表示用に整形する
function formatDate(date){
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var date = date.getDate();
  if ( month < 10 ) { month = "0" + month; }
  if ( date < 10 ) { date = "0" + date; }
  return year + '.' + month + '.' + date;
}

//新しい投稿か否かを判定する
function isFresh(date){
  //現在時刻(クライアント)
  //TODO タイムゾーン？
  var currentDate = new Date();
  return (currentDate.getTime() < date.getTime() + const_feed_fresh_term);
}

