document.write("<script src='http://www.uwplatt.edu/template_data/rss/jfeed.min.js' type='text/javascript' charset='utf-8'><\/script>\n");

//override the jfeed object to grab the categories as well
document.write("<script src='http://www.uwplatt.edu/template_data/rss/rss-category.js' type='text/javascript' charset='utf-8'><\/script>\n");
/*
*fillRSS() - function to fill an rss feed into a div box with a filter of category
*     how many to display, the content to be displayed and the number of days in the
*     past to view.
*  params:  div - ID of div to append rss to
*           loc - URL location of the atom.xml file to parse
*           num - number of rss entries to display
*           content - 1 = just the title 2 = title and first 128 chars of
*                 description.
*           daysViewed - number of days from present to view entries for
*           category - category of entry to filter on                 
*/
function fillRSS(div, loc, num, content, daysViewed, category)
{
   var one_day_in_ms = 86400000;
   var rssCounter, myHTML;
   var title, descrip, link, pubDate, year, month, day;
   var pastDays;
   $('#' + div).empty();
   rssCounter = 0;
   myHTML = '';
   myHTML += '<ul>';
   jQuery.getFeed({
      url: loc,
      success: function(feed) {
         $(feed.items).each( function() {
            if(category === undefined || isCategory(this, category))
            {
               rssCounter++;
               title = this.title;
               link = this.link;
               year = this.updated.substring(0,4);
               month = this.updated.substring(5,7) - 1;
               day = this.updated.substring(8,10);
               pubDate = new Date(year, month, day);
               pastDays = (Date.parse(Date()) - Date.parse(pubDate))/ one_day_in_ms;
               
               
               //"2009-11-02T15:51:09.024-08:00"
               descrip = $.trim(this.description).substring(0,128);
               if(daysViewed == 0 || (pastDays > 0 && pastDays < daysViewed))
               {
                  if( content == 1 )
                  {
                     $('#' + div).parent().show();
                     myHTML += '<li><h3><a href="'+ link +'">' + title + '</a></h3></li>';
                  }
                  else if( content == 2 )
                  {
                     $('#' + div).parent().show();
                     myHTML += '<li><h3><a href="'+ link +'">' + title + '</a></h3>' + '<p>' + descrip + '<a href="' + link +'" class="moreLink">...more</a></p></li>';
                  }
               }
               if( rssCounter >= num )
                  return false;
            } 
            else 
            { //continue loop
               return true;
            }
         });
         myHTML += '</ul>'
         
         $('#' + div).append(myHTML);
         
      }
   });            
}

function isCategory(item, category)
{
   var inCategory = false;
   $(item.categories).each( function() {
      if($(this).attr('term') == category)
      {
         inCategory = true;
         //break the loop
         return false;
      }
   })
   return inCategory;
}