google.load("feeds", "1");

// Our callback function, for when a feed is loaded.
function feedLoaded(result) {
	if (!result.error) {
		// Grab the container we will put the results into
		var container = document.getElementById("twitter-feed");
		container.innerHTML = '';
		
		// Loop through the feeds, putting the titles onto the page.
		// Check out the result object for a list of properties returned in each entry.
		// http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON
		for (var i = 0; i < result.feed.entries.length; i++) {
			var entry = result.feed.entries[i];

			var li = document.createElement("li");
			var a = document.createElement("a");
			var img = document.createElement("img");
			var span = document.createElement("span");
			//アイコン

			li.appendChild(img);
			var users = ["masa","yu","kaho"];
			var count = 0;
			for (var j=0; j < users.length; j++) {
				if (entry.title.search(users[j]) ==15 ) {
					var user = users[j];
					count ++;
				} 
			};
			if (count == 0) var user = "di";
			li.getElementsByTagName("img")[0].setAttribute("src", "/share/imgs/twitter_" + user + ".png");
			li.getElementsByTagName("img")[0].setAttribute("alt", "Di_" + user);
			var MyEntryTitle = entry.title.replace("dimprovement: ", '' );
			
			//パーマリンク
			li.appendChild(a);
			li.getElementsByTagName("a")[0].setAttribute("href",entry.link);
			
			//タイトル
			li.getElementsByTagName("a")[0].appendChild(document.createTextNode(MyEntryTitle));
			
			//日付
			var d = new Date(entry.publishedDate);
			function addZero(t) {
				if (parseFloat(t) < 10){
					t = "0" + t;
				}
				return t;
			}
			var diplayHours = addZero(d.getHours());
			var diplayMinutes = addZero(d.getMinutes());
			var diplaySeconds = addZero(d.getSeconds());

			var date = " " + (d.getFullYear()) + "年" + (d.getMonth()+1) + "月" + d.getDate() + "日 " + diplayHours + ":" + diplayMinutes + ":" + diplaySeconds;
			li.appendChild(span);
			li.getElementsByTagName("span")[0].appendChild(document.createTextNode(date));
			
			//ulに挿入
			container.appendChild(li);
    }
  }
}



function OnLoad() {
  // Create a feed instance that will grab Digg's feed.
  var feed = new google.feeds.Feed("http://twitter.com/statuses/user_timeline/23751534.rss");

  feed.includeHistoricalEntries(); // tell the API we want to have old entries too
  feed.setNumEntries(20); // we want a maximum of 50 entries, if they exist

  // Calling load sends the request off.  It requires a callback function.
  feed.load(feedLoaded);
}

google.setOnLoadCallback(OnLoad);