﻿var TweetThisLink = {
    shorten: function(e) {
        // this stops the click, which will later be handled in the  response method
        e.preventDefault();
        // find the link starting at the second 'http://'
        var url = this.href.substr(this.href.indexOf('http:', 5));
        BitlyClient.shorten(url, 'TweetThisLink.response');
    },

    response: function(data) {
        var bitly_link = null;
        for (var r in data.results) {
            bitly_link = data.results[r]['shortUrl'];
            break;
        }        
        var tweet_text = "Saiba o que está acontecendo no Dia dos Voluntários Telefônica. Veja meu comentário em "
        window.open("http://twitter.com/home?status=" + encodeURIComponent(tweet_text + ' ' + bitly_link + ' #DVT2011' ));
    }
}

$(document).ready(function() {

$('.btn-twitter').bind('click', TweetThisLink.shorten);
$('.btns-twitter').bind('click', TweetThisLink.shorten);

});

