/*------------------------------------------------------------------------------------*/
/*  Blog - pull recent blog entries
/*------------------------------------------------------------------------------------*/
function showrecentposts(json) {
  // start a loop
  // in this loop we get the entry from the feed and parse it
  for (var i = 0; i < numposts; i++) {
    // get entry i from feed
    var entry = json.feed.entry[i];
    // get the posttitle
    var posttitle = entry.title.$t;
    // get the post url
    // check all links for the link with rel = alternate
    var posturl;
    if (i == json.feed.entry.length) break;
    for (var k = 0; k < entry.link.length; k++) {
      if (entry.link[k].rel == 'alternate') {
        posturl = entry.link[k].href;
        break;
      }
    }
    // get the postdate, take only the first 10 characters
    var postdate = entry.published.$t.substring(0,10);
	var d = Date.parse(postdate);
	var dateFunc = new Date();
	var timeSince = dateFunc.getTime() - d;
	var inSeconds = timeSince / 1000;
	var inMinutes = timeSince / 1000 / 60;
	var inHours = timeSince / 1000 / 60 / 60;
	var inDays = timeSince / 1000 / 60 / 60 / 24;
	var inYears = timeSince / 1000 / 60 / 60 / 24 / 365;
    // get the post author
    var postauthor = entry.author[0].name.$t;
    // get the postcontent
    // if the Blogger-feed is set to FULL, then the content is in the content-field
    // if the Blogger-feed is set to SHORT, then the content is in the summary-field
    if ("content" in entry) {
      var postcontent = entry.content.$t;}
    else
    if ("summary" in entry) {
      var postcontent = entry.summary.$t;}
    else var postcontent = "";
    // strip off all html-tags
    var re = /<\S[^>]*>/g; 
    postcontent = postcontent.replace(re, "");
    // reduce postcontent to numchar characters
    if (postcontent.length > numchars) postcontent = postcontent.substring(0,numchars);
    // display the results
    // document.write('<br>');
    // document.write('Entry #' + i + '<br>');
    document.write('<a href="'+ posturl + '">'+ posttitle + '</a><br>');
    // document.write('Post url      : '+ posturl + '<br>');
    // document.write('Post author   : '+ postauthor + '<br>');
    document.write(''+ postcontent + '... ');
	// document.write(''+ postdate + '<br>');
	
	// Convert to relative date
	// in seconds
		if(Math.round(inSeconds) == 1){
		document.write("1 second ago");
		}
		else if(inMinutes < 1.01){
		document.write(Math.round(inSeconds) + " seconds ago");
		}
 
	// in minutes
		else if(Math.round(inMinutes) == 1){
		document.write("1 minute ago");
		}
		else if(inHours < 1.01){
		document.write(Math.round(inMinutes) + " minutes ago");
		}
 
	// in hours
		else if(Math.round(inHours) == 1){
		document.write("1 hour ago");
		}
		else if(inDays < 1.01){
		document.write(Math.round(inHours) + " hours ago");
		}
 
	// in days
		else if(Math.round(inDays) == 1){
		document.write("1 day ago");
		}
		else if(inYears < 1.01){
		document.write(Math.round(inDays) + " days ago");
		}
 
	// in years
		else if(Math.round(inYears) == 1){
		document.write("1 year ago");
		}
		else
		{
		document.write(Math.round(inYears) + " years ago");
		}
	
	
    
    document.write('<hr style="margin-top: 10px; margin-bottom:10px; border:none 0px; border-bottom: solid 1px #d5d2cc;">');
  }
}

