﻿var _numResults_ = 7;
/*
 * google ajax feed API:
 * http://code.google.com/apis/ajaxfeeds/documentation/
 * http://code.google.com/apis/ajaxfeeds/documentation/reference.html
 * google API => pubDate is returned as the JSON property publishedDate
 */
function initialize() {
  var rss = 'http://sourceforge.net/export/rss2_keepsake.php?group_id=72954';
  var heading = 'iTextSharp Project Activity';
  var rssText = "<div><h3><span style='margin:0;margin-right:8px;'>"
    + heading
    + "</span><a href='" + rss 
    + "'><img src='/kyouyuu/image/rss_button.gif' style='margin:0;border:none;' alt='RSS' /></a></h3></div>"
  ;
  var feed = new google.feeds.Feed(rss);
  feed.setNumEntries(_numResults_ + 1);
  feed.load(function(result) {
    if (!result.error) {
      for (var i = 0; i < result.feed.entries.length; i++) {
        var entry = result.feed.entries[i];
        rssText += 
          "<div class='tbm8'><div><a href='"
          + entry.link + "'>" + entry.title + '</a></div>'
          + '<div>' + entry.publishedDate + '</div>'
          + '</div>'
        ;
      }
      $('#iTextSharpRSS').html(rssText);
    }
    else {
      $('#iTextSharpRSS').html(
        rssText + '<p>Unable to get ' + heading + '</p>'
      );
    }
  });
}

$(function(){
  var TweetUrl = 'http://twitter.com/statuses/user_timeline/jquery.json?count='
    + _numResults_
  ;
  var jQueryTweetHeading = 'jQuery on Twitter';
  var jQueryTweetText = "<div><h3><span style='margin:0;margin-right:8px;'>"
    + jQueryTweetHeading
    + "</span><a href='http://twitter.com/jquery'><img src='/kyouyuu/image/tweetn.png' style='margin:0;border:none;' alt='tweets' height='16' width='44' /></a></h3></div>"
  ;
  jQuery.ajax({
    url:TweetUrl,
    dataType: 'jsonp',
    success: function (data, textStatus, XMLHttpRequest) {
      for (var i = 0; i < data.length; i++) {
        var tweetText = data[i].text
          .replace(/(https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/, function (u) {
            var shortUrl = (u.length > 30) ? u.substr(0, 30) + '...': u;
            return '<a href="' + u + '">' + shortUrl + '</a>';
          })
          .replace(/@([a-zA-Z0-9_]+)/g, '@<a href="http://twitter.com/$1">$1</a>')
          .replace(/(?:^|\s)#([^\s\.\+:!]+)/g, function (a, u) {
            return ' <a href="http://twitter.com/search?q=' + encodeURIComponent(u) + '">#' + u + '</a>';
          });

        jQueryTweetText += "<div class='tbm8'>" + tweetText 
          + '<div>' + data[i].created_at + '</div>'
          + '</div>'
        ;
      }
      $('#jQueryTwitter').html(jQueryTweetText);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      $('#jQueryTwitter').html(
        rssText + '<p>Unable to get ' + jQueryTweetHeading + '</p>'
      );
    }
  });

  google.setOnLoadCallback(initialize);
});

