$(document).ready(function(){
  $.ajax({
    url: "topic/feed.rss",
    async: true,
    cache: false,
    dataType: "xml",
    success: function(xml){
			  //変数の初期化
			  var list = "";
				var count = 0;
			  //Feedの処理
				list = '<ul>';
      $(xml).find('item').each(function(i){
				var category = $(this).find('category').text();
				
				if (category == 'トップページ') {
					var title = $(this).find('title').text();
					var url = $(this).find('link').text();
					var pubDate = $(this).find('pubDate').text();
					var strdate = createDateString(pubDate);
					list += '<li>';
					list += '<span>■</span>';
					list += strdate + '<br />';
					if (url) {
						list += '<a href="'+url+'">'+title+'</a>';
					} else {
						list += title;
					}
					list += '</li>';
					count ++;
				}
				
        if (count == 5) {
          return false;
        }
				
      });
			  list += '</ul>';
				$('#feed').append(list);
    }
  });
});

//日付の表示方法を変更
function createDateString(publishedDate){
  var pdate = new Date(publishedDate);
  var pday = pdate.getDate();
  var pmonth = pdate.getMonth() + 1;
  var pyear = pdate.getFullYear();
  var phour = pdate.getHours();
  var pminute = pdate.getMinutes();
  var psecond = pdate.getSeconds(); 
  //var strdate = pyear + "年" + pmonth + "月" + pday + "日" + phour + "時" + pminute + "分" + psecond + "秒";
  var strdate = pyear + "/" + pmonth + "/" + pday ;
  return strdate;
}

