/* ---------------------------------------------------------------- */
// FEED(XML) URL
var feed_url_report = '/report/index_report.xml'; 

// Category
var categories_report = ["all", "movie", "photo", "blog"];
var category_names_report = {all: "Report", movie: "movie", photo: "photo", blog:"blog"};

/* ---------------------------------------------------------------- */
// onload
function init_report() {
	createRecentEntryContent_report(); 
	request_feed_report(feed_url_report, disp_entry_report);
}

/* ---------------------------------------------------------------- */
function createRecentEntryContent_report(){

	var df_cont = document.createDocumentFragment();

	categories_report.each(function(cat){
		var div = document.createElement("div");
		div.id = "lp_" + cat;
		df_cont.appendChild(div);
	});

	$("lp_content").appendChild(df_cont);
}

/* ---------------------------------------------------------------- */
function request_feed_report(url, callback){
	var http = new JKL.ParseXML(url);
	http.async(callback);
	http.parse();
}

/* ---------------------------------------------------------------- */
// All Entry HTML
function disp_entry_report(data) {

	data = data.rss;
	var items = (!!data.item) ? data.item : data.channel.item; // For RSS 1.0 / 2.0 
	items = (items instanceof Array) ? items : [items];

	categories_report.each(function(cat){
		var html ="", count = 0;

		if(cat == "all") {
			items.detect(function(item){
				html += get_entry_tag_report(item);
				count++;
				if(count > 10) return true; // MAX 10Entry break
			});
			$("lp_" + cat).innerHTML = html;
		}
	});
}

/* ---------------------------------------------------------------- */
// 1Entry HTML
function get_entry_tag_report(item) {

	var date = new Date(item.pubDate);
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var day = date.getDate();

	if(String(month).length == 1) month = "0" + month;
	if(String(day).length == 1) day = "0" + day;

	var html = "";

	html += '<div class="report_entry">';
	html += '<div><a href="'+ item.link +'" title="'+item.title+'"><img src="img/icon_' + category_names_report[item.category["#text"]] + '.gif" border="0"></a></div>';
	html += '<p>[ ' + year + '.' + month + '.' + day + ' ]<br />';
	html += '<a href="'+ item.link +'" title="'+item.title+'">'+item.title+'</a></p>';
	html += '</div>';

	return html;
}

