﻿/*
 *  2010.04.04
 */


$(function(){
	$.ajax({
		url: "blog/index.xml",//RSSのパス
		//url: "http://eneloopy.com/blog/index.xml",//RSSのパス
		async: true,
		cache: false,
		dataType:"xml",
		success: function(xml){
		
			var i = 0;
			
			$(xml).find('item').each(function(){
			
				/* 初期設定で3件出力します。件数を変更は"i > 2"の部分を修正してください。
				数値は"出力したい件数 - 1"を入力して下さい。*/
				if ( i > 3 ) {
					return false;
				}
				
				//記事内容の取得
				var title = $(this).find('title').text();
				var link = $(this).find('link').text();
				
				//日にちの編集
				var date;
				
				$(this).children().each(function() {
					if ($(this)[0].tagName == "pubDate") {
						date = $(this).text();
					}
				});
				
				date = dateParse(date);
				
				//カテゴリの取得
				var category;
				
				$(this).children().each(function() {
					if ($(this)[0].tagName == "category") {
						category = $(this).text();
					}
				});
				
				//出力内容
				var htmlData = '';
				htmlData += '<li><div class="rtable"><span>'+date+'</span></div>';
				htmlData += '<div class="newstext"><a href="'+link+'">'+title+'</a></div></li>';
				
				if(category == "ダウンロード" || category == "商品紹介" || category == "お仕事" || category == "イベント・キャンペーン"){
					$('#feedBox').append(htmlData);
					i++;
				}
			
			});
		
		}
	});
});


function dateParse(cmd){
	
	var objDate = cmd;
	
	//曜日カット
	if (objDate.search(/,\s/i) != -1) {
		objDate = RegExp.rightContext;
	}
	//日
	if (objDate.search(/\s/i) != -1) {
		var date = RegExp.leftContext;
		objDate = RegExp.rightContext;
	}
	//月
	if (objDate.search(/\s/i) != -1) {
		var month = RegExp.leftContext;
		objDate = RegExp.rightContext;
		if(month == "Jan"){ month = "01" }
		if(month == "Feb"){ month = "02" }
		if(month == "Mar"){ month = "03" }
		if(month == "Apr"){ month = "04" }
		if(month == "May"){ month = "05" }
		if(month == "Jun"){ month = "06" }
		if(month == "Jul"){ month = "07" }
		if(month == "Aug"){ month = "08" }
		if(month == "Sep"){ month = "09" }
		if(month == "Oct"){ month = "10" }
		if(month == "Nov"){ month = "11" }
		if(month == "Dec"){ month = "12" }
	}
	//西暦
	if (objDate.search(/\s/i) != -1) {
		var year = RegExp.leftContext;
		objDate = RegExp.rightContext;
	}
	
	cmd = year + '.' + month + '.' + date;
	
	return cmd;
	
}





