﻿function GetLatestTweet() {
    var url = "http://twitter.com/statuses/user_timeline/kenardforsc.json?count=3&callback=?";

    $(document).ready(function() {
        $.getJSON(url, function(tweet) {

            var tweet_text = "";
            for (var i = 0; i < tweet.length; i++) {
                // The following date processing code is in place to handle
                // IE's inability to properly parse date strings (go figure)
                // This is unnecessary in Firefox.
                var raw_tweet_date = tweet[i].created_at.split(' ');
                var tweet_date = new Date(Date.parse(raw_tweet_date[1] + ' ' 
                                            + raw_tweet_date[2] + ' ' 
                                            + raw_tweet_date[5] + ' ' 
                                            + raw_tweet_date[3]));                 
                var formatted_date = (tweet_date.getMonth() + 1) + '/' + tweet_date.getDate() + '/' + tweet_date.getFullYear() +
                                        " " + tweet_date.getHours() + ":" + tweet_date.getMinutes();
                tweet_text += "<p class='tweet_text'>"
                    + tweet[i].text + "<br /><b>"
                    + formatted_date
                    + "</b></p>";
            }
            $(".latest_tweet").html(tweet_text);

        });
    });

}

function GetLatestVideo(ytplayer) {
    
    $.getJSON("http://gdata.youtube.com/feeds/api/videos?author=KenArdForSc&orderby=published&alt=json&callback=?",
        function(data) {
            var base_url = "http://gdata.youtube.com/feeds/api/videos/"
            var video_url = data.feed.entry[0].id["$t"];
            ytplayer.loadVideoById(video_url.substring(base_url.length, video_url.length));
            //ytplayer.loadVideoById('RD4cG7Tg0g0');
        });
        
}
