google.load("feeds", "1");
function initialize() {
    var feed = new google.feeds.Feed("http://feedblog.ameba.jp/rss/ameblo/protent/rss20.xml");
    feed.setNumEntries(5);  // 最大件数
    
    feed.load(function(result) {
    
        if (!result.error) {
            // 読み込みに成功したときの処理

            var ul = document.createElement("ul");
            ul.setAttribute("className", "report_list");
            ul.setAttribute("class", "report_list");
            
            //フィード全体の情報を出力
            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 span1 = document.createElement("span");
                span1.setAttribute("className", "report_date");
                span1.setAttribute("class", "report_date");
                
                var span2 = document.createElement("span");
                span2.setAttribute("className", "content");
                span2.setAttribute("class", "content");
                
                //表示文字の生成
                
                //日付作成
                var pdate = new Date(entry.publishedDate);
                //西暦の作成
                var entry_y = pdate.getYear();
                if (entry_y < 2000){
                     entry_y += 1900;
                }
                //月の作成(前0追加)
                var entry_m = pdate.getMonth()+1;
                if(entry_m < 10){
                    entry_m = '0' + entry_m;
                }
                //日の作成(前0追加)
                var entry_d = pdate.getDate();
                if(entry_d < 10){
                    entry_d = '0' + entry_d;
                }
                var entry_date = entry_y + '.' + entry_m + '.' + entry_d;
                
                //タイトル文字の作成(バイト数制限)
                var titlelink = cutString(entry.title,54);
                
                //日付のセット
                span1.appendChild(document.createTextNode(entry_date));
                
                //リンク先セット
                a.href = entry.link;
                //タイトルセット
                span2.appendChild(document.createTextNode(titlelink));
                a.appendChild(span2);
                
                //日付のセット
                li.appendChild(span1);
                li.appendChild(a);
                ul.appendChild(li);
            }
            var container = document.getElementById("index_report");
            container.appendChild(ul);
        }
    });
}

google.setOnLoadCallback(initialize);


function cutString(str,num){
  len = 0;
  estr = escape(str);
  ostr = "";
  for(i=0;i<estr.length;i++){
    len++;
    ostr = ostr + estr.charAt(i);
    if(estr.charAt(i) == "%"){
      i++;
      ostr = ostr + estr.charAt(i);
      if(estr.charAt(i) == "u"){
        ostr = ostr + estr.charAt(i+1) + estr.charAt(i+2) + estr.charAt(i+3) + estr.charAt(i+4);
        i+=4;
        len++;
      }
    }
    if(len >= num-3){
      return unescape(ostr)+"...";
    }
  }
  return unescape(ostr);
}
