$(function(){
	var url = ["feed.atom","/blog/feed?feed=atom"];//RSSファイル名
	var feed=[];
	var max_info = 4;
	$.each(url,function(){
		$.ajax({
			url: this,
			async: true,
			cache: false,
			dataType: ($.browser.msie) ? "text" : "xml",
			success: function(data){
				var xml;
				if (typeof data == "string") {
					xml = new ActiveXObject("Microsoft.XMLDOM");
					xml.async = true;
					xml.loadXML(data);
				} else {
					xml = data;
				}
				if(xml.length==0) return;
				$('entry',xml).each(function(){
					feed.push({t: $('title',this).text(),l: $('link',this).attr('href'),d: dateParse($('published',this).text())-0});
				});
				feed.sort(function(a,b){return b.d-a.d});
				$('.info dl').html(buildNews(feed));
			}
		});
	});
	function dateParse(str){
		var strdate = str.split('\+')[0].replace('T',' ').replace('-','\/').replace('-','\/');
		return Date.parse(strdate);
	}
	function buildNews(news){
		news = news.slice(0,max_info);
		var newsStr = '';
		$.each(news,function(){
			if(this.l.length){
				newsStr += expDate(this.d)+'<dd><a href="'+this.l+'">'+this.t+'</a></dd>';
			}else{
				newsStr += expDate(this.d)+'<dd>'+this.t+'</dd>';
			}
		});
		return newsStr;
	}
	function expDate(tStamp){
		var pDate = new Date(tStamp);
		var pYear = pDate.getFullYear();
		var pMonth = pDate.getMonth()+1;
		var pDay = pDate.getDate();
		return '<dt><time datetime="'+pYear+'-'+pMonth+'-'+pDay+'">'+pYear+'.'+pMonth+'.'+pDay+'</time></dt>';
	}
});
