﻿$(document).ready(function () {
    // get the last tweet
    var username = 'ashcraftphoto'; // set user name
    var format = 'json'; // set format, you really don't have an option on this one
    var url = 'http://api.twitter.com/1/statuses/user_timeline/' + username + '.' + format + '?callback=?'; // make the url

    $.getJSON(url, function (data) { // get the tweets
        // process links and reply

        var tweet = data[0].text;

        tweet = tweet.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, function (url) {
            return '<a href="' +  url + '" target="_blank">' + url + '</a>';
        }).replace(/B@([_a-z0-9]+)/ig, function (reply) {
            return reply.charAt(0) + '<a href="http://twitter.com/%27+reply.substring%281%29+%27">' + reply.substring(1) + '</a>';
        });

        $("#tweet-dude-tweet").html(tweet); // get the first tweet in the response and place it inside the div
    });
});
