/*
 * @requires Google AJAX Feed API, jquery
 * code to include google api:
 * <script type="text/javascript" src="http://www.google.com/jsapi"></script>
 * <script type="text/javascript">google.load("feeds", "1");</script>
 *
 * getFeed(containerId, feedUrl, numberOfEntriesToDisplay)
 *
 * This script is designed to give you the flexibility to create your own template
 * for the display of the feed entries using a template setup. Simpy define the
 * item container, the anchor, and the date container and the script will duplicate
 * and populate it for each entry.
 *
 * e.g.; 
 * <div id="myRssFeed">
 *     <ul>
 *         <li class="feedItem">
 *             <a href="" class="feedLink"></a>
 *             <span class="feedPublishedDate"></span>
 *         </li>
 *     </ul>
 * </div>
 *
 * feedItem class specifies the entry container
 * feedLink class specifies the entry link (which contains the url, and the title)
 * feedPublishedDate class specifies the entry time
 * feedTimeSince class specifies the amount of time since post was created (e.g.; about an hour ago)
 */
 
// minified version of jquery.timeago.js
(function(d){d.timeago=function(g){if(g instanceof Date){return b(g)}else{if(typeof g=="string"){return b(d.timeago.parse(g))}else{return b(d.timeago.parse(d(g).attr("title")))}}};var f=d.timeago;d.extend(d.timeago,{settings:{refreshMillis:60000,allowFuture:false,strings:{prefixAgo:null,prefixFromNow:null,suffixAgo:"ago",suffixFromNow:"from now",ago:null,fromNow:null,seconds:"less than a minute",minute:"about a minute",minutes:"%d minutes",hour:"about an hour",hours:"about %d hours",day:"a day",days:"%d days",month:"about a month",months:"%d months",year:"about a year",years:"%d years"}},inWords:function(k){var l=this.settings.strings;var h=l.prefixAgo;var p=l.suffixAgo||l.ago;if(this.settings.allowFuture){if(k<0){h=l.prefixFromNow;p=l.suffixFromNow||l.fromNow}k=Math.abs(k)}var n=k/1000;var g=n/60;var m=g/60;var o=m/24;var i=o/365;var j=n<45&&a(l.seconds,Math.round(n))||n<90&&a(l.minute,1)||g<45&&a(l.minutes,Math.round(g))||g<90&&a(l.hour,1)||m<24&&a(l.hours,Math.round(m))||m<48&&a(l.day,1)||o<30&&a(l.days,Math.floor(o))||o<60&&a(l.month,1)||o<365&&a(l.months,Math.floor(o/30))||i<2&&a(l.year,1)||a(l.years,Math.floor(i));return d.trim([h,j,p].join(" "))},parse:function(h){var g=d.trim(h);g=g.replace(/-/,"/").replace(/-/,"/");g=g.replace(/T/," ").replace(/Z/," UTC");g=g.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2");return new Date(g)}});d.fn.timeago=function(){var h=this;h.each(c);var g=f.settings;if(g.refreshMillis>0){setInterval(function(){h.each(c)},g.refreshMillis)}return h};function c(){var g=f.parse(this.title);if(!isNaN(g)){d(this).text(b(g))}return this}function b(g){return f.inWords(e(g))}function e(g){return(new Date().getTime()-g.getTime())}function a(g,i){var h=d.isFunction(g)?g(i):g;return h.replace(/%d/i,i)}if(d.browser.msie&&d.browser.version<7){document.createElement("abbr")}})(jQuery);

function getTimeAgo(dateString){if(dateString != ''){var d=new Date(dateString);$.timeago.settings.allowFuture=true;return $.timeago(d);}else{return '';}}

function getFeed(container,url,numEntries){var feed=new google.feeds.Feed(url);feed.setNumEntries(numEntries);feed.load(function(result){var $thisFeedItem="";if(!result.error){for(var i=0;i<result.feed.entries.length;i++){$thisFeedItem=$('#'+container+' .feedItem:first').clone();$thisFeedItem.find('.feedLink').attr('href',result.feed.entries[i].link).html(result.feed.entries[i].title);$thisFeedItem.find('.feedPublishedDate').html(result.feed.entries[i].publishedDate);$thisFeedItem.find('.feedTimeSince').html(getTimeAgo(result.feed.entries[i].publishedDate));$thisFeedItem.insertAfter('#'+container+' .feedItem:last');}$('#'+container+' .feedItem:first').remove();}});}