/*
Get feed
Author : Yoshihiro Noda
http://www.f-deal.jp
*/

$(function(){
        $.ajax({
            url: '/blog/rss.xml',
            async: true,
            cache: false,
            dataType: "xml",
            success: function(xml){
				var feedEntries = 6;
                $(xml).find('item').each(function(i){
                    if ( i == feedEntries ) {
                        return false;
                    }
                    var strTitle = $(this).find('title').text();
                    var strUrl = $(this).find('link').text();
                    var strDate = $(this).find('pubDate').text();
                    strDate = createDateString(strDate);
					$('#news').append('<dt class=\"rss_item\">'+strDate+'</dt><dd><a href="'+strUrl+'">'+strTitle+'<\/a></\dd>');
                });
                //idがlist-01にあるliをolで括る
                $('#news dt, #news dd').wrapAll('<dl id=\"newslist\"><\/dl>');
            },
            //エラー表示
            error: function(xml){
                $('#news').append('<p>RSS読み込みエラー<\/p>');
            }
        });
        //月表示を数字表示に変換する
		var createDateString = function (publishedDate){
			var pubdate = new Date(publishedDate);
			var pday = pubdate.getDate();
			var pmonth = pubdate.getMonth() + 1;
			if(pmonth < 10) pmonth = "0" + pmonth;
			if(pday < 10) pday = "0" + pday;
			var pyear = pubdate.getFullYear();
			var strDate = pyear + "/" + pmonth + "/" + pday + "日";
			return strDate;
		};
});

