// JavaScript Document

google.load("feeds", "1");
var entryArray = new Array();
var entryNum = 0;

function initialize() {


feedAdd("http://heraheto.com/blog/honbu/wp-rss2.php", 23);
feedAdd("http://feedblog.ameba.jp/rss/ameblo/chairman-room/rss20.xml", 22);
feedAdd("http://feedblog.ameba.jp/rss/ameblo/eikosha-staff/rss20.xml", 21);
feedAdd("http://feedblog.ameba.jp/rss/ameblo/eikosha-staff-ka-san/rss20.xml", 20);
feedAdd("http://sagamidenki.tenkomori.tv/index.xml", 19);
feedAdd("http://kasaiyoshida.tenkomori.tv/index.xml", 18);
feedAdd("http://charley.tenkomori.tv/index.xml", 17);
feedAdd("http://heraheto.com/blog/charley/wp-rss2.php", 16);
feedAdd("http://heraheto.com/blog/joyaoyama/wp-rss2.php", 15);
feedAdd("http://heraheto.com/blog/kasaiyoshida/wp-rss2.php", 14);
feedAdd("http://heraheto.com/blog/sagamidenki/wp-rss2.php", 13);
feedAdd("http://blog.goo.ne.jp/chairman-room/rss2.xml", 12);
feedAdd("http://heraheto.com/blog/colormony/wp-rss2.php", 11);
feedAdd("http://heraheto.com/blog/yosikyo/wp-rss2.php", 10);
feedAdd("http://kishimoto.tenkomori.tv/index.xml", 9);
feedAdd("http://heraheto.com/blog/ruhekitao/wp-rss2.php", 8);
feedAdd("http://heraheto.com/blog/kobunsha/wp-rss2.php", 7);
feedAdd("http://heraheto.com/blog/kankonsousai/wp-rss2.php", 6);
feedAdd("http://heraheto.com/blog/takahashi/wp-rss2.php", 5);
feedAdd("http://heraheto.com/blog/kayohayashi1950/", 4);
feedAdd("http://heraheto.com/http://fujiwaraseifuku.tenkomori.tv/index.xml", 3);
feedAdd("http://heraheto.com/blog/haradabungu/wp-rss2.php", 2);
feedAdd("http://feedblog.ameba.jp/rss/ameblo/nishimurasyoten/rss20.xml", 1);

}

function feedAdd(rssUrl, boolNum) {
var feed = new google.feeds.Feed(rssUrl);
feed.setNumEntries(3);//サイト1つあたりの取得するフィード数
feed.load(function(result) {
if (!result.error) {
for (var i = 0; i < result.feed.entries.length; i++) {
entryArray[entryNum] = result.feed.entries[i];
var date = new Date(result.feed.entries[i].publishedDate);
entryArray[entryNum].sortDate = ( date.getFullYear()*1000000 ) + ( (date.getMonth() + 1)*3600*32 ) + ( date.getDate()*3600 ) + ( date.getHours()*60 ) + date.getMinutes();
entryArray[entryNum].blogName = result.feed.title;
entryNum+=1;
}
}
if(boolNum==1){
feedOutput("feed", 15);//フィードの出力
}
});
}

function feedOutput(feedId, listNum){
var useFeed = "";
var useDate = "";
var container = document.getElementById(feedId);
entryArray = asort(entryArray, "sortDate");
if(listNum==100){//出力するリスト数
listNum = entryNum;
}

for (var i = 0; i < listNum; i++) {
var entry = entryArray[i];
var date = new Date(entry.publishedDate);
var y = date.getYear();
if (y < 2000) { y += 1900; }
var m = date.getMonth() + 1;
if (m < 10) {m = "0" + m;}
var d = date.getDate();
if (d < 10) {d = "0" + d;}
var h = date.getHours();
if (h < 10) {h = "0" + h;}
var mn = date.getMinutes();
if (mn < 10) {mn = "0" + mn;}
useDate  = m + "月" + d + "日";
useDate2 = y + "年" + m + "月" + d + "日";

useFeed += '<div class=blog-rss><a href="' + entry.link + '" target="_blank">' + entry.title + '</a>' + useDate2 + '</div>';
}

container.innerHTML = useFeed;
}
function asort(myArray, key){
return myArray.sort ( function (b1, b2) { return b1[key] > b2[key] ? -1 : 1; } );
}

google.setOnLoadCallback(initialize);

