var blip = {
    init: function() {
        $('body').append('<script type="text/javascript" src="http://blip.pl/users/jerzysokolpl/statuses.json?limit=5&callback=blip.putData" charset="utf-8"></script>');
    },
    putData: function(json) {
        var content = $('<div class="body blip" />');
        $(json).each(function(k,v){
            var body = v.body.replace(/(http:[\S]+)/,'<a href="$1" target="_blank">$1</a>')
            var entry = $('<div/>')
                .append('<p class="entry">'+body+'</p>')
                .append('<p class="desc">'+v.created_at+', przez: '+v.transport_description+'</p>')
                .appendTo(content);
            if( v.pictures_path != undefined ) {
                $('.entry', entry).append('<a href="" class="blipFancyBox"><img width="25" height="25" rel="'+v.id+'" border="0" /></a>');
                $.ajax({
                    url: 'http://blip.pl/'+v.pictures_path,
                    dataType: 'jsonp',
                    success: function(data) {
                        var entryId = data[0].update_path.replace('/updates/','');
                        $('div.blip img[rel='+entryId+']')
                            .attr('src','http://static.blip.pl/user_generated/update_pictures/'+data[0].id+'_standard.jpg')
                            .parent()
                            .attr('href','http://static.blip.pl/user_generated/update_pictures/'+data[0].id+'.jpg');
                    }
                });
            }
        }); 
        $('div.box div.blip').replaceWith(content);
        $("a.blipFancyBox").fancybox();

    }
};
