/**
 * Shorten an url and redirect to Twitter
 * 
 * @param link
 * @return void
 */
function shortenAndTweet(link, text)
{
	var text = text;
	
	if ($('notifier') != undefined && $('notifierMessage') != undefined)
	{
		$('notifier').show();
     
		$('notifierMessage').update('shortening url');
	}
	
	var url = '/links/shorten?link=' + encodeURIComponent(link);

	new Ajax.Request(url, {
		
		method: 'get',

		onSuccess: function(transport) {
		
			var message = "Via Tweetminster";
			
			if (text != null)
			{
				message = text;
			}
			
			var tweet_url = "http://twitter.com/home?status=" + encodeURIComponent(message+" "+transport.responseText);

			if ($('notifierMessage') != undefined)
			{
		        $('notifierMessage').update('taking you to Twitter');
			}

			window.location = tweet_url;
		}
	});
}

/**
 * Simple status retweet
 * 
 * @param text
 * @return void
 */
function reTweet(text)
{
	var message = "RT " + text;
	
	var tweet_url = "http://twitter.com/home?status=" + encodeURIComponent(message);

	if ($('notifier') != undefined && $('notifierMessage') != undefined)
	{
		$('notifier').show();
     
		$('notifierMessage').update('redirecting you to Twitter');
	}
	
	window.location = tweet_url;
}