var __mainDiv; var __preLoaderHTML; var __opts;
function __ReceiveData(data, callback) {
     var cnt = 0;
     $.each(data.items, function(i, e) {
         if (cnt < __opts.numberToDisplay) {
             var out = '<li><a href="' + e.alternate.href + '" target="_blank" title="' + 
                 e.title + '">' + e.title + '</a> <span class="reader_source">(<a href="' + 
                 e.origin.htmlUrl + '">' + e.origin.title + '</a>)</span>';
             if (e.annotations && e.annotations[0] && e.annotations[0].content) {
                 var comment = e.annotations[0].content;
                 if (comment.length > 150) {
                     comment = comment.substr(0, 149);
                     while (comment.substr(comment.length - 1) != " ") {
                         comment = comment.substr(0, comment.length - 1);
                     }
                     comment = comment.trim() + "&hellip;";
                 }
                 out += '<p class="reader_comment">"' + comment + '"</p>';
             }
             out += '</li>';
             __mainDiv.append(out);
             cnt = cnt + 1;
         }
     });
    $(__preLoaderHTML).remove();
    __mainDiv.show();
    callback();
}
(function($) {
    $.fn.googleReaderShared = function(options) {
        var readerDiv = $(this);
        $.fn.googleReaderShared.defaults = {
            userId: null,
            loadingText: "Loading...",
            numberToDisplay: 5,
            onComplete: function() {}
        }
        __opts = $.extend({}, $.fn.googleReaderShared.defaults, options);
        if (__opts.userId != null) {
            readerDiv.append("<ul id=\"reader_div\"></ul>");
            __mainDiv = $("#reader_div");
            __mainDiv.hide();
            __preLoaderHTML = $("<li class=\"loader\">" + __opts.loadingText + "</li>");
            readerDiv.append(__preLoaderHTML);
            var urle = "http://www.google.com/reader/public/javascript/user/" + 
                __opts.userId + "/state/com.google/broadcast?callback=?";
            $.getJSON(urle, function(data) { __ReceiveData(data, __opts.onComplete); });
        }
    };
})(jQuery);
