function initialize()
{
    Tab.Group.byAnchors('tab', 'active', 'inactive');
    initOnozakiFeed();
}

function initOnozakiFeed()
{
    new Ajax.Request('http://www.zetalabo.com/onozaki/?feed=rss2&cat=7', {
        method: 'get',
        onSuccess: showOnozakiFeed,
        onFailure: function() {alert('error');}
    });
}

function showOnozakiFeed(transport)
{
    var items = transport.responseXML.getElementsByTagName('item');
    var length = items.length;
    var posts = [];
    for (var i = 0; i < length; ++i) {
        var item = items[i];
        posts[i] = {
            title: item.getElementsByTagName('title')[0].firstChild.nodeValue,
            pubDate: new Date(item.getElementsByTagName('pubDate')[0].firstChild.nodeValue),
            link: item.getElementsByTagName('link')[0].firstChild.nodeValue};
    }

    posts.sort(function(a, b)
    {
        return b.pubDate.getTime() - a.pubDate.getTime();
    });

    function format(date)
    {
        var Y = date.getFullYear(),
            m = date.getMonth() + 1,
            d = date.getDate();
        if (m < 10) {
            m = '0' + m;
        }
        if (d < 10) {
            d = '0' + d;
        }
        return Y + '/' + m + '/' + d;
    }
    var html = '<dl>';
    posts.slice(0, 5).each(function(post)
    {
        html += '<dt>' + format(post.pubDate) + '</dt><dd><a href="'
                + post.link + '" target="_blank">' + post.title.escapeHTML() + '</a></dd>';
    });
    $('onozaki_feed').innerHTML = html + '</dl>';
}

if (window.attachEvent) {
    window.attachEvent('onload', initialize);
} else {
    window.addEventListener('load', initialize, false);
}

