function FeedDisplayer(container_id, url, entries) {
    this.container = document.getElementById(container_id);
    var displayer  = this;
    var feed       = new google.feeds.Feed(url)
    feed.setNumEntries(entries);
    feed.load(function(result){displayer.display(result)});
}
FeedDisplayer.prototype.display = function(result) {
    while (this.container.hasChildNodes())
        this.container.removeChild(this.container.firstChild);

    if (result.error) {
        this.container.appendChild(document.createTextNode(result.error.message));
        return;
    }

    var list = document.createElement("ul");
    this.container.appendChild(list);

    for (var i = 0; i < result.feed.entries.length; i++) {
        var entry = result.feed.entries[i];
        var li    = document.createElement("li");
        var a     = document.createElement("a");
        var span  = document.createElement("span");
        var date  = new Date(entry.publishedDate);

        a.setAttribute("href", entry.link);
        a.appendChild(document.createTextNode(entry.title));
        span.setAttribute("class", "updated");
        span.appendChild(document.createTextNode(
            ' ('                          +
                  date.getDate()          + '.' +
                ( date.getMonth() + 1 )   + '.' +
                  date.getFullYear()      +
             ')'
        ));
        li.appendChild(a);
        li.appendChild(span);
        list.appendChild(li);
    }
}

function initialize() {
    if (!feeds) return; // global configuration var "feeds" is required
    for (var id in feeds) {
        var url       = feeds[id].url;
        var entries   = feeds[id].entries || 10;
        var container = document.getElementById(id);
        if (!url || !container) continue;

        while (container.hasChildNodes())
            container.removeChild(container.firstChild)
        container.appendChild(document.createTextNode('Loading feed...'));

        new FeedDisplayer(id, url, entries);
    }
}

google.load("feeds", "1");
google.setOnLoadCallback(initialize);


