//Borrowed from:
//http://webdesignandsuch.com/2009/12/embed-a-twitter-feed-on-your-website-with-jquery
//http://www.drunkenfist.com/304/2008/10/30/twitter-search-results-with-json-and-callbacks

// Documentation:
// Add a tag looking like this anywhere: <span id="twitter">Loading</span>
// The HTML tag itself isn't important
// Config is in the top of the twitterSearch and the twitter functions


function twitterSearch(obj) {
    var tdiv, tweet, created_at;
    var output='';
    var reload_time = 1000000; //Miliseconds
    var tweet;
    var number_of_tweets = obj.length;
    // Get the latest tweet that is not a re-tweet
    for (i=0; i<number_of_tweets; i++) {
        tweet = obj[i];
        if (!(tweet.retweeted)){
            tdiv = document.getElementById('twitter');  
            text = tweet.text;
            created_at = tweet.created_at;
            var month_name = created_at.substring(4,7);
            var month_day = created_at.substring(8,10);
            if (created_at.substring(8,9) == '0') month_day = created_at.substring(9,10);

            output += '<span class = "twitter-date">' + month_day + ' ' + month_name + '</span> ';
            output += '<span class = "twitter-text">' + text +'</span>';
            
            if (text == '') output = 'No posts yet';
            tdiv.innerHTML = output;
            break; //we got the latest non re-tweet tweet
            }
        }
    setTimeout("twitter();", reload_time);
}


function twitter() {
    //Config
    //Callback statement is important. jq will replace the ?
    var search_url = 'http://api.twitter.com/1/statuses/user_timeline.json?user_id=180310067&count=20&callback=?';
     jq.getJSON(search_url,twitterSearch);
    return false;
}

jq(document).ready(function(){
    twitter();
});


