// Load RSS feeds.
jQuery(document).ready(function($) {
    // FLICKR
    $.jGFeed('http://api.flickr.com/services/feeds/photos_public.gne?id=30254301@N04',
        function(feeds){
            if(!feeds){ return; }

            var str = '';
            var parts, url;
            $(feeds.entries).each(function(){
                parts = this.content.match(/http:\/\/farm(\d)\.staticflickr.com(.*)\.jpg/gi)[0].split('_m');
                url = this.content.match(/http:\/\/.*flickr.com\/photos\/(.*)\/"/gi)[0];
                str += '<a href="' + url + '><img src="' + parts[0] + '_s' + parts[1] + '" alt="' + this.title + '" title="' + this.title + '" width="75" height="75"></a>';
            });

            $('#flickr > .content').append(str);
        },
    10);

    // TWITTER
    $.jGFeed('http://twitter.com/statuses/user_timeline/karbassi.rss',
        function(feeds){
            if(!feeds){ return; }

            var str = '<ul>';
            $(feeds.entries).each(function(){
                str += '<li><a href="' + this.link + '">' + this.content.substring(10) + '</a></li>';
            });
            str += '</ul>';

            $('#twitter > .content').append(str);
        },
    5);

/*
    // GITHUB
    $.jGFeed('https://github.com/karbassi.atom',
        function(feeds){
            if(!feeds){ return; }

            var str = '<ul>';
            $(feeds.entries).each(function(){
                str += '<li><a href="' + this.link + '">' + this.content.substring(10) + '</a></li>';
            });
            str += '</ul>';

            $('#github > .content').append(str);
        },
    5);
*/

    // LAST.FM
    $.jGFeed('http://ws.audioscrobbler.com/1.0/user/mrWoot/recenttracks.rss',
        function(feeds){
            if(!feeds){ return; }

            var str = '<ul>';
            $(feeds.entries).each(function(){
                str += '<li><a href="' + this.content + '">' + this.title + '</a></li>';
            });
            str += '</ul>';

            $('#lastfm > .content').append(str);
        },
    5);

    // // DELICIOUS
    // $.jGFeed('http://feeds.delicious.com/v2/rss/mrwoot?count=5',
    //     function(feeds){
    //         if(!feeds){ return; }
    // 
    //         var str = '<ul>';
    //         $(feeds.entries).each(function(){
    //             str += '<li><a href="' + this.link + '">' + this.title + '</a></li>';
    //         });
    //         str += '</ul>';
    // 
    //         $('#delicious > .content').append(str);
    //     },
    // 5);

    // // DIGG
    // $.jGFeed('http://digg.com/users/mrWoot/history/diggs.rss',
    //     function(feeds){
    //         if(!feeds){ return; }
    // 
    //         var str = '<ul>';
    //         $(feeds.entries).each(function(){
    //             str += '<li><a href="' + this.link + '">' + this.title + '</a></li>';
    //         });
    //         str += '</ul>';
    // 
    //         $('#digg > .content').append(str);
    //     },
    // 5);

    // FRIENDFEED
    $.jGFeed('http://friendfeed.com/karbassi?format=atom',
        function(feeds){
            if(!feeds){ return; }

            var str = '<ul>';
            $(feeds.entries).each(function(){
                str += '<li><a href="' + this.link + '">' + this.title + '</a></li>';
            });
            str += '</ul>';


            $('#friendfeed > .content').append(str);
        },5);

    // googlereader
    $.jGFeed('http://www.google.com/reader/public/atom/user%2F07483848639058383105%2Fstate%2Fcom.google%2Fbroadcast',
        function(feeds){
            if(!feeds){ return; }

            var str = '<ul>';
            $(feeds.entries).each(function(){
                str += '<li><a href="' + this.link + '">' + this.title + '</a></li>';
            });
            str += '</ul>';

            $('#googlereader > .content').append(str);
        },
    5);

    // Tech.karbassi.com
    $.jGFeed('http://feeds.feedburner.com/karbassi/tech/',
        function(feeds){
            if(!feeds){ return; }

            var str = '<ul>';
            $(feeds.entries).each(function(){
                str += '<li><a href="' + this.link + '">' + this.title + '</a></li>';
            });
            str += '</ul>';

            $('#tech_karbassi_com > .content').append(str);
        },
    5);

});

/*
 * jGFeed 1.0 - Google Feed API abstraction plugin for jQuery
 * Copyright (c) 2009 jQuery HowTo
 * Licensed under the GPL license: http://www.gnu.org/licenses/gpl.html
 * URL: http://jquery-howto.blogspot.com
 * Author URL: http://me.boo.uz
 */
(function($){
    $.extend({
        jGFeed : function(url, fnk, num, key){
            // Make sure url to get is defined
            if(url == null){ return false; }
            // Build Google Feed API URL
            var gurl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=" + url;
            if(num != null){ gurl += "&num=" + num; }
            if(key != null){ gurl += "&key=" + key; }
            // AJAX request the API
            $.getJSON(gurl, function(data){
                if(typeof fnk == 'function') {
                    fnk.call(this, data.responseData.feed);
                }
                else {
                    return false;
                }
            });
        }
    });
})(jQuery);

