$(window).bind('load', function () {
    $.getScript('http://bit.ly/javascript-api.js?version=latest&login=mtmh&apiKey=R_3d2f64f155ebcd6d8685318b5b966079', function () {
        BitlyCB.statsResponse = function (data) {
            $('.retweet').each(function () {
                var link = $(this),
                    title = link.attr('rel');
                $(['<b>', data.results.clicks, '</b>'].join('')).appendTo(link);
                var href = encodeURIComponent([
                    'RT @myteachermyhero ',
                    title,
                    ' http://bit.ly/',
                    data.results.userHash, ' #mtmh'].join(''));
                link.attr('href', 'http://twitter.com/home?status=' + href);
            });
        };
        BitlyCB.shortenResponse = function (data) {
            for (var url in data.results) {
                var hash = data.results[url].userHash;
                BitlyClient.stats(hash, 'BitlyCB.statsResponse');
            }
        };
        if (typeof BitlyClient !== 'undefined') {
            BitlyClient.shorten(document.location, 'BitlyCB.shortenResponse');
        };
    });
});