﻿$(function () {
    $("[data-tweet-id]").each(function () {
        var tweetStatus = $(this).attr("data-tweet-id");
        Twitter.GetTweet(tweetStatus);
    });
});

var Twitter = {

    GetTweet: function (status) {
        $.ajax({
            data: { id: status },
            dataType: "jsonp",
            jsonpCallback: "Twitter.parseCallback",
            url: "http://www.connemara.net/services/twitter/TweetClient.ashx" //"http://localhost/services/twitter/TweetClient.ashx"
        });
    },

    parseCallback: function (json) {
        // show the tweet!
        Twitter.GetHTML({ "json": json });
    },

    GetHTML: function (params) {
        var json = params["json"];
        var userName = json.UserName;
        var status = json.Status;
        
        // the URL of the tweet
        var tweetUrl = "http://twitter.com/#!/" + userName + "/status/" + status;

        // twitter blue bird logo
        var twitterLogoHTML = "<a href=\"" + tweetUrl + "\" class=\"twitterLogo\"><img src=\"http://www.connemara.net/Content/Images/SocialMedia/twitter.png\" alt=\"Twitter\" /></a>";

        // find the element whose where 'data-tweet-id=[status]' and set the HTML
        $('[data-tweet-id="' + status + '"]').html(twitterLogoHTML + json.Content);
    }
};
