function share(icon,url,title) {
	$("p.share_window").remove();
	$("p.share_wait").remove();
	$("p.share_error").remove();

	switch(icon) {
		case 'facebook':
			var fb_url = 'http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title);
			//share_append_link(fb_url, "Facebook");
			window.open( fb_url, '_blank');
			$("div.share_box").hide();
		break;
		
		case 'twitter':
			$("div.share_box").show();
			// warn user this may take some time
			$("div.share_box").append('<p class="end share_wait">Shortening the URL, please wait.</p>');
			
			// create the short URL
			$.ajax({
				url: '/site/utils/bitly',
				data: 'url='+url,
				dataType: 'json',
				success: function(json) {
					$("p.share_wait").hide();
					if(json.status_code != 200) {
						$("div.share_box").append('<p class="end share_error">There was an error shortening the URL, please try again.</p>');
					}
					else
					{
						var new_url = json.data.url;
		   var t_url = 'http://twitter.com/share?url='+encodeURIComponent(new_url)+
                      '&text='+encodeURIComponent('Shared from @liveunsigned')+
                      '&related='+encodeURIComponent('liveunsigned');
						share_append_link(t_url, "Twitter");
						window.open( t_url, '_blank');	
					}
				}
			});        
		break;
		
		case 'google':
			var g_url = 'https://www.google.com/bookmarks/mark?op=add&bkmk='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&annotation=';
			//share_append_link(g_url, "Google Bookmarks");
			window.open( g_url, '_blank');
		break;
		
		default:
			break;
	}
}

function share_append_link(url, where) {
	$("div.share_box").append('<p class="share_window">We will try to open a new window to share this content.</p><p class="share_window end"> Sometimes browsers can block this. If no window opens, <a href="'+url+'" target="_blank">click here to share on '+where+'</a>.</p>');
}

