var summaryEndpointURI = "/blog/summary.do";

function getSummary(type, blogId) {
	var url = summaryEndpointURI;
	var params = "type=" + type + "&id=" + blogId;
	var args = {
		method:"get",
		parameters:params,
		onComplete:renderSummary
	};
	var myAjax = new Ajax.Request(summaryEndpointURI, args);
}

function renderSummary(res) {
	var xml = res.responseXML;
	var entries = xml.getElementsByTagName("entry");

	if (entries == null || entries.length <= 0) {
		return;
	}

	var html = '';

	for (var i=0; i<entries.length; i++) {
		var entry = entries.item(i);
		var date = entry.getAttribute("date");
		var uri = entry.getAttribute("uri");
		var title = entry.firstChild.nodeValue;
		var categoryName = entry.getAttribute("categoryName");
		var categoryURI = entry.getAttribute("categoryURI");
		html += '<div class="dateListLabel">' + date + "</div>";
		html += '<div class="dateListContent">';
		html += '<a href="' + uri + '">' + title + '</a>';
		if (categoryName != null) {
			html += '<span class="categoryLabel">';
			html += '<a href="' + categoryURI + '" class="category">';
			html += categoryName;
			html += '</a>';
			html += '</span>';
		}
		html += '</div>';
	}

	$("newestEntries").innerHTML = html;
}
