/* Google Feed で外部RSS読み込みJavascript 2011.03.23 */

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

function initialize() {
  /* 読み込むfeedのURLを設定する */
  var feed = new google.feeds.Feed("http://www.google.com/reader/public/atom/user%2F13342402048974844137%2Flabel%2Fberrycarefeed");
/*  var feed = new google.feeds.Feed("http://auctions.search.yahoo.co.jp/rss?ei=UTF-8&auccat=2084292253&s1=end&o1=d&apg=1&mode=2&tab_ex=commerce&ei=UTF-8&fixed=0");*/

  /* 読み込むfeedの最大件数を設定する */
  feed.setNumEntries(10);

  /* feedのロード */
  feed.load(function(result) {
    if (!result.error) {
      var container = document.getElementById("feed");

      var ulBlock = document.createElement("ul");
      ulBlock.className = "list_arrow_02";

      for (var i = 0; i < result.feed.entries.length; i++) {
        var entry = result.feed.entries[i];
        var liBlock = document.createElement("li");
        var a = document.createElement("a");
        /* A タグの設定（エントリのリンクとターゲットの指定 */
        a.href = entry.link;
        a.target = "_blank";

        /* 取得したpublishDateから日付を整形して出力 */
        if(entry.publishedDate) {
          var time = Date.parse(entry.publishedDate);
          var date = new Date();
          date.setTime(time);
          var stDate = date.getFullYear()  + "年"
                     + ( (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1) ) + "月"
                     + ( date.getDate() < 10 ? "0" + date.getDate() : date.getDate() ) + "日";
          /* 日付の出力と改行 */
          liBlock.appendChild(document.createTextNode(stDate));
          liBlock.appendChild(document.createElement("br"));
        }

        /* 取得したエントリのタイトルを出力（17文字よりも長い場合は17文字+...で出力する） */
        var stTitle = (entry.title.lenght < 17 ? entry.title : entry.title.substring(0,17) + "...");
        /* A タグにくっつける */
        a.appendChild(document.createTextNode(stTitle));

        /* liにくっつけてからULにくっつける */
        liBlock.appendChild(a);
        ulBlock.appendChild(liBlock);
      }

      container.appendChild(ulBlock);
    }
  });
}
google.setOnLoadCallback(initialize);

