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

function initialize() {
  var feedurl = "http://www.mu-hung.net/blog/?feed=rss2";
  var feed = new google.feeds.Feed(feedurl);
  feed.setNumEntries(5);
  feed.load(dispfeed);

  function dispfeed(result){
    if (!result.error){
      var container = document.getElementById("feed");
      var htmlstr = "";
		htmlstr += "<div style='width: 230px;margin: 5px auto;' id='feedcolor'>";
		for (var i = 0; i < result.feed.entries.length; i++) {
		var entry = result.feed.entries[i];
		
		var strdate = createDateString(entry.publishedDate);
		htmlstr += "<p style='font-weight: bold;'>" + strdate + "</p>";
		htmlstr += '<h5 style="margin:0;"><a href="' + entry.link + '">' + entry.title + '</a></h5>';
		htmlstr += "<p style='margin:0;border-bottom: 1px dotted #999999;padding-bottom: 5px;color#39120A;'>" + entry.contentSnippet.substr(0,45) + "...</p>";
      }
      htmlstr += "</div>";

       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 strdate = pyear + "." + pmonth + "." + pday + "" ;

  return strdate;
}

google.setOnLoadCallback(initialize);
