
$(document).ready(function() {

        
    //var buildString = 'from:moodagent';
    //buildString = '@moodagent nowplaying';
    var buildString = 'moodagent';
    //buildString = 'from:moodagent @moodagent nowplaying';

    $.getJSON(
        "http://search.twitter.com/search.json?callback=?",
        {
            //"since": "2010-06-20",
            "q": buildString,
            "rpp": "7"
        },
        function (data, textStatus) {
            var container = $('#tweet-container');
            console.log(data);
            container.html('');
            $(data.results).each(function(el) {
                var str = '<div class="tweet pullgutter_1"><div class="time">'+relativeTime(this.created_at)+'</div><div class="txt">'+formatTweet(this.text)+'</div></div>';
                container.append(str);
            });

            $('#tweet_panel > div').not('div.clear').equalHeights();
        });
});

function formatTweet(str) {
    str = ' ' + str;
    str = str.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>');
    str = str.replace(/([^\w])\@([\w\-]+)/gm,'$1@<a href="http://twitter.com/$2" target="_blank">$2</a>');
    str = str.replace(/([^\w])\#([\w\-]+)/gm,'$1<a href="http://twitter.com/search?q=%23$2" target="_blank">#$2</a>');
    return str;
}


