// homepage feeds

//

// set up json

function TwitterAPI(){}

TwitterAPI.Users = function Users(){}
TwitterAPI.Statuses = function Statuses(){}

TwitterAPI.Users.show = function(username, callback){
    requestURL = "http://twitter.com/users/show/" + username + ".json?callback=?";
    $.getJSON(requestURL, callback);
}

TwitterAPI.Statuses.user_timeline = function(username, callback){
    requestURL = "http://twitter.com/statuses/user_timeline/" + username + ".json?callback=?";
    $.getJSON(requestURL, callback);
}

function RSSFeed(){}

RSSFeed.Entries = function(feed_url, callback){
    requestURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=6e02f3d46634fbe2924cf01905b38ef8&_render=json&_callback=?&feed=" + feed_url;
    $.getJSON(requestURL, function(json, status){
        callback(json.value.items, status);
    });
}

// twitter
TwitterAPI.Statuses.user_timeline("jsnsck", function(json, status){
    var content = "";
    $.each(json, function(i){
        tweet = this['text'];
        link = "http://www.twitter.com/jsnsck/status/" + this['id'];
        content += "<div><a href=\"" + link + "\" target=\"_blank\">" + tweet + "</a></div>\n";
        if (i==4) { return false; }
    });
    $("#twitter .content").html(content);
});

// ffffound
RSSFeed.Entries("http://ffffound.com/home/jsack/found/feed", function(json, status){
    var content = "";
    $.each(json, function(i){
    	//console.debug(json);
        description = this['description'];
        content += description;
        if (i==9) { return false; }
    });
    $("#ffffound .content").html(content);
    $("#ffffound .content p:contains('via')").remove();
    $("#ffffound .content img").attr("width","240");
    $("#ffffound .content img").removeAttr("height");
});

// vimeo
RSSFeed.Entries("http://vimeo.com/jasonsack/likes/rss", function(json, status){
    var content = "";
    $.each(json, function(i){
    	//console.debug(json);
        description = this['description'];
        content += description;
        if (i==11) { return false; }
    });
    $("#vimeo .content").html(content);
    $("#vimeo .content p a[title]").clone().appendTo("#vimeo .content");
    $("#vimeo .content p").remove();
    $("#vimeo .content img").attr("width","160");
    $("#vimeo .content img").removeAttr("height");
    $("#vimeo .content a").wrap("<div></div>");
});

// lastfm
RSSFeed.Entries("http://ws.audioscrobbler.com/1.0/user/isanybodythere/recenttracks.rss", function(json, status){
    var content = "";
    $.each(json, function(i){
    	//console.debug(json);
        songTitleLink = "<li><a href=\"" + this['description'] + "\" target=\"_blank\">" + this['title'] + "</a></li>";
        content += songTitleLink;
        if (i==9) { return false; }
    });
    $("#lastfm .content ul").html(content);
});

// delicious
RSSFeed.Entries("http://feeds.delicious.com/v2/rss/jsnsck?count=10", function(json, status){
    var content = "";
    $.each(json, function(i){
    	//console.debug(json);
        deliciousLink = "<li><a href=\"" + this['link'] + "\" target=\"_blank\">" + this['title'] + "</a></li>";
        content += deliciousLink;
        if (i==9) { return false; }
    });
    $("#delicious .content ul").html(content);
});

// flickr
RSSFeed.Entries("http://api.flickr.com/services/feeds/photos_public.gne?id=8445447@N03&lang=en-us&format=rss_200", function(json, status){
    var content = "";
    $.each(json, function(i){
    	//console.debug(json);
        description = this['description'];
        content += description;
        if (i==9) { return false; }
    });
    $("#flickr .content").html(content);
    $("#flickr .content p:contains('posted')").remove();
    $("#flickr .content img").attr("width","180");
    $("#flickr .content img").removeAttr("height");
});


// foursquare
RSSFeed.Entries("http://feeds.foursquare.com/history/f68897938edabb4a54b9f94d43399d27.rss", function(json, status){
    var content = "";
    $.each(json, function(i){
    	//console.debug(json);
    	var dateTime = this['pubDate'];
        dateTime = dateTime.replace("+0000", "");
        songTitleLink = "<li><a href=\"" + this['link'] + "\" target=\"_blank\">" + this['description'] + "</a> "  + dateTime + "</li>";
        content += songTitleLink;
        if (i==9) { return false; }
    });
    $("#foursquare .content ul").html(content);
});

// mousepath
/*RSSFeed.Entries("http://mousepath.tumblr.com/rss", function(json, status){
    var content = "";
    $.each(json, function(i){
    	console.debug(json);
        description = this['description'];
        imglink = "<a href=\"" + this['link'] + "\" target=\"_blank\" border=\"0\">" + description + "</a>"
        content += imglink;
        if (i==9) { return false; }
    });
    $("#mousepath .content").html(content);
    $("#mousepath .content br").remove();
    $("#mousepath .content img").wrap("<p></p>");
    $("#mousepath .content img").attr("width","240");
    $("#mousepath .content img").removeAttr("height");
});*/