// passage time
var pass = 240;
// now time
var currentDate = new Date();
var currentTime = currentDate.getTime();


google.load("feeds", "1");

function initialize() {
	var feed = new google.feeds.Feed("http://www.hakko-group.co.jp/tps/jaguar/atom.xml");
	feed.setNumEntries(4);
	feed.load(dispfeed);
	
	function dispfeed(result){
		if (!result.error){
			var container = document.getElementById("topicsList");
			var htmlstr = "\n";
			for (var i = 0; i < result.feed.entries.length; i++) {
				var entry = result.feed.entries[i];
				var cate = entry.categories[0];
				
				/*
				// categorySwitch
				if (cate == "JAGUAR") {
				*/
					// timeLag
					var entryDate = new Date(entry.publishedDate);
					var entryTime = entryDate.getTime();
					var timeLag = Math.ceil((currentTime - entryTime)/(60*60*1000));
					
					htmlstr += "<dt>"
					var strdate = createDateString(entry.publishedDate);
					htmlstr += strdate;
					// newIcon
					if (timeLag < pass) {
						htmlstr += '<img src="common/img/ico_new.gif" alt="new" width="19" height="9" />';
					}
					htmlstr += "</dt>\n"
					
					htmlstr += "<dd>"
					htmlstr += '<a href="' + entry.link + '" onclick="pageTracker._link(this.href); return false;">' + entry.title + '</a>';
					htmlstr += "</dd>\n"
				/*
				}
				*/
			}
			
			container.innerHTML = htmlstr;
		} else {
			container.innerHTML = "<p>" + result.error.code + ":" + result.error.message + "</p>\n";
		}
	}
}


function createDateString(publishedDate){
	var pdate = new Date(publishedDate);
	
	var pday = pdate.getDate();
	var pmonth = pdate.getMonth() + 1;
	var pyear = pdate.getFullYear();
	
	var pdayFull = to2String(pday);
	var pmonthFull = to2String(pmonth);
	
	var strdate = pyear + "." + pmonthFull + "." + pdayFull;
	
	return strdate;
}


function to2String (value) {
	label = "" + value;
	if (label.length < 2) {
	label = "0" + label;
	}
	return label;
}


google.setOnLoadCallback(initialize);