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_title = document.title;
		document.location = "http://twitter.com/home?status=" + encodeURIComponent(tweet_title + ' ' + bitly_link);
	}
}

