
/*
	XMLからTOPのリストを作成します。
*/


$(document).ready(function () {

	var date = new Date();
	
	$.ajax({
		url: "/products/oen/info.xml?"+ date.getTime(),
		success: function(_data){
			
			var destinationElements = {accounts: "td.cateB", soho: "td.cateA", enterprises: "td.cateC", public_corp: "td.cateD"}
			
			$("category", _data).each(function(){
				var currentCategory = $(this).attr('name');
				$("info:lt("+ $(this).attr('lastn') +")", this).each(function(){
					
					var o = {};
					o["description"] = $(this).find("description").text();
					o["date"] = $(this).find("pubDate").text();
					
					var template = new HTMLTemplate(o);
					template.evaluate($(destinationElements[currentCategory]));
				});
			});
		}
	});
});

var HTMLTemplate = function(conv){
	this.template = $('<dl><dt><strong>'+conv.date+'</strong></dt><dd><p>'+conv.description+'</p></dd></dl>');
}

HTMLTemplate.prototype.evaluate = function(dest){
	$(dest).append(this.template)
}
