// -----------------------------------------------------------------------------
//
//	Google AJAX Feed API.js
//
// -----------------------------------------------------------------------------


// 記事の数
var ENTRY_LIMIT = 3;
// Feedするブログのパス
var RSS_Path = "http://feedblog.ameba.jp/rss/ameblo/kappou-nabesan/rss20.xml";


//
function readFeed( result ) {
	
	if( !result.error ) { 
		
		var content;
		var content_date;
		var year;
		var month;
		var day;
		var dt;
		var dd;
		var link;
		
		// rootノード：ID:feed
		var root = document.getElementById( "feed" );
		
		
		// dl要素を生成する
		var dl = document.createElement( "dl" );
		root.appendChild( dl );
		
		
		// 記事を生成する
		for( var i = 0; i < ENTRY_LIMIT; i++ ) {
			
			// 記事データを取得
			content = result.feed.entries[i];
			
			// 広告のフィルタ
			if( content.title.search( /PR/ ) == 0 ) {
				ENTRY_LIMIT++;
				continue;
			}
			
			// 日付に関する処理
			content_date = new Date( content.publishedDate );
			
			year = content_date.getYear();
			if( !( navigator.appName == "Microsoft Internet Explorer") ) { // IE以外のブラウザ
				year += 1900;
			}
			
			month = ( content_date.getMonth() + 1 );
			month = ( month < 10 )? "0" + month: month;
			
			day = content_date.getDate();
			day = ( day < 10 )? "0" + day: day;
			
			// dt要素を生成
			dt = document.createElement( "dt" );
			dt.innerHTML = year + "." + month + "." + day;
			dl.appendChild( dt );
			
			
			// タイトルに関する処理
			
			// aタグの生成
			link = document.createElement( "a" );
			link.setAttribute( "href",  content.link );
			link.setAttribute( "target", "_blank" );
			link.appendChild( document.createTextNode( content.title ) );
			
			// ddタグの追加
			dd = document.createElement( "dd" );
			dd.appendChild( link );
			dl.appendChild( dd );
		}
	}
	else {	// 例外処理
		root.appendChild( document.createTextNode( "ERROR" ) );
	}
}


google.load( "feeds", "1" );


//
function initialize() {
	
	// 表示させるブログ(RSSなど)
	var feed = new google.feeds.Feed( RSS_Path );
	
	// 表示させる記事の数を指定(最大10件まで：2009/3/18現在)
	feed.setNumEntries( 10 );
	
	feed.load( readFeed );
}


google.setOnLoadCallback( initialize );


// END
