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

function initialize() {

	var feedurl = "http://blog.livedoor.jp/danza_news/index.rdf";
	
  var feed = new google.feeds.Feed(feedurl);
	
  feed.setNumEntries(10); // 最大件数
  feed.load(dispfeed);

  function dispfeed(result){
    if (!result.error){
      var container = document.getElementById("feed");
      var htmlstr = "";

			// htmlstr += "<p>[タイトル]" + result.feed.title + "</p>";
      htmlstr += '<dl class="clearfix">';
      for (var i = 0; i < result.feed.entries.length; i++) {
        var entry = result.feed.entries[i];

				htmlstr += '<dt>'
        htmlstr += createDateString(entry.publishedDate);
        htmlstr += '</dt>'
        htmlstr += '<dd class="' + createCategoryString(entry.categories[0]) + '">'
        htmlstr += '<a href="' + entry.link + '" target="_blank">' + entry.title + '</a>&nbsp;';
        htmlstr += '</dd>'
      }
      htmlstr += '</dl>';

      container.innerHTML = htmlstr;
    }else{
       alert(result.error.code + ":" + result.error.message);
    }
  }
}

function createDateString(publishedDate){
  var pdate = new Date(publishedDate);

  var pday = pdate.getDate();
  var pmonth = pdate.getMonth() + 1;
  var pyear = pdate.getFullYear();
  var phour = pdate.getHours();
  var pminute = pdate.getMinutes();
  var psecond = pdate.getSeconds();
	//
	var pmonth = String(pmonth + 100).substring(1);
	var pday = String(pday + 100).substring(1);

  //var strdate = pyear + "年" + pmonth + "月" + pday + "日" + phour + "時" + pminute + "分" + psecond + "秒";
	var strdate = pyear + "." + pmonth + "." + pday + "";
	
  return strdate;
}

function createCategoryString(str){
	
	var res = "";
	if (str == "暖座本舗 下赤江店"){
		res = "dnak";
	} else if (str == "暖座 富山二口店"){
		res = "dnft";
	} else if (str == "暖座Classic 富山駅前店"){
		res = "dncl";
	} else if (str == "ふきのとう　富山二口店"){
		res = "fkft";
	} else if (str == "一番亭 富山蜷川店"){
		res = "icni";
	} else if (str == "丸超（まるちょう）"){
		res = "mrty";
	} else if (str == "暖座二店舗合同企画"){
		res = "dn2";
	} else if (str == "暖座三店合同企画"){
		res = "dn3";
	} else if (str == "(有)フーズデベロップメント"){
		res = "honb";
	} else {
		res = "othe";
	}
	
  return res;
}


google.setOnLoadCallback(initialize);


