
/*-- RSS Read --*/
function rssRead(xmlId,xmlPath,trgt,dispNo){
	
	//LoadingID
	loadMsg = xmlId.split('#')[1] + 'Load';
	
	//remove
	if($('ul#' + xmlId.split('#')[1] + 'List')){
		$('ul#' + xmlId.split('#')[1] + 'List').remove();
	}
	//remove
	if($(xmlId + 'Load')){
		$(xmlId + 'Load').remove();
	}
	
	//Loading Img
	$(xmlId).ready(function (){
		var month_en = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
		var month_jp = new Array('1','2','3','4','5','6','7','8','9','10','11','12');
		
		$.ajax({
			url: xmlPath,
			type: 'GET',
			dataType: 'xml',
//			cache: false,
			timeout: 10000,
			error: function(){
				$(xmlId + 'Load').remove();
				$(xmlId).html('Error loading XML doc').appendTo(xmlId);
			},
			success: function(xml){
				ulId = xmlId.split('#')[1];
				$('<ul id="' +ulId+ 'List" class="rssDisp"></ul>').appendTo(xmlId);
				items = $(xml).find('item').slice(0,dispNo);
		    	items.each(function(){
		    		rssLnk = $(this).find('link:first').text();
		    		rssTtl = $(this).find('description:first').text();
		    		rssPub = $(this).find('pubDate:first').text();
		    		rssExe = $(this).find('guid:first').text();
		    		for(m=0; m<month_en.length; m++){
		    			if(rssPub.split(' ')[2] == month_en[m]){
		    				wMonth = month_jp[m];
		    			}
		    		}
		    		
		    		if(rssLnk == ''){
				    	$('<li></li>')
							.html('<dl><dt><span>'+ rssPub.split(' ')[3] +'.'+ wMonth + '.' + rssPub.split(' ')[1] + '</span></dt><dd>' +rssTtl+ '</dd></dl>')
							.appendTo('#' +ulId+ 'List');
		    		}else{
			    		if(rssExe == ''){
					    	$('<li></li>')
								.html('<dl><dt><span>'+ rssPub.split(' ')[3] +'.'+ wMonth + '.' + rssPub.split(' ')[1] + '</span></dt><dd><a href="' +rssLnk+ '">' +rssTtl+ '</a></dd></dl>')
								.appendTo('#' +ulId+ 'List');
						}else{
					    	$('<li></li>')
								.html('<dl><dt><span>'+ rssPub.split(' ')[3] +'.'+ wMonth + '.' + rssPub.split(' ')[1] + '</span></dt><dd><a href="' +rssLnk+ '" target="_blank">' +rssTtl+ '</a></dd></dl>')
								.appendTo('#' +ulId+ 'List');
						}
					}
			    });
				$(xmlId + 'Load').remove();
			}
		});
	});
}

$(function(){
	rssRead('#topicsArea','/topics/rss.xml','_self',5);
});



