var cnt = 0;

$(function(){
	$('#link_info').remove();

	$.ajax({
		url:"/news/c/info/feed",
		async:true,
		cache:false,
		dataType:"xml",

		success:function(xml){
			$(xml).find('item').each(function(i){
				cnt = i;
				if (i > 5) return;

				var title = $(this).find('title').text();
				var url = $(this).find('link').text();
				var date = dateParse( $(this).find('pubDate').text() );
				var html = '<li id="top_info_nav_item'+i+'" style="opacity:0;"><span class="date">'+date+'</span> <a href="'+url+'" class="title">'+title+'</a></li>';

				setTimeout("pushItem(" + i + ",'" + html + "')", 300*i);
			});

			cnt++;
			var html = '<li id="top_info_nav_item'+cnt+'" class="link_info" style="opacity:0;"><a href="/news/c/info/">&#155;&nbsp;お知らせ一覧</a></li>';
			setTimeout("pushItem(" + cnt + ",'" + html + "')", 300*cnt);
		}

	});
});

function pushItem(index,html){
	$('#top_info_nav').append(html);
	$('#top_info_nav_item'+index).animate({opacity:'1'},300);
}

function dateParse(str){
	var result = '';
	var tmp;
	var d = new Date(str);

	result += d.getFullYear();

	tmp = "0" + (d.getMonth()+1);
	tmp = tmp.substr(tmp.length - 2, tmp.length);
	result += '/'+tmp;

	tmp = "0" + d.getDay();
	tmp = tmp.substr(tmp.length - 2, tmp.length);
	result += '/'+tmp;

	return result;
}
