function buildShare() {
	encodedUrl = encodeURIComponent(window.location);
	$(".sh_facebook").click(function(){ window.open('http://www.facebook.com/sharer.php?u='+encodedUrl+'&t='+document.title, "Share it", 'height=350,width=700'); });
	$(".sh_delicious").click(function(){ window.location = 'http://delicious.com/save?jump=yes&url='+encodedUrl+'&title='+document.title; });
	$(".sh_gbuzz").click(function(){ window.open('http://www.google.com/buzz/post?url='+encodedUrl, "Post to Google Buzz", 'height=500,width=700'); });
	$.getJSON(
		'http://api.bit.ly/v3/shorten?login=hyperakt&apiKey=R_b55bdbbad0d5d51e9adec68e6a346642&longUrl='+encodeURIComponent(window.location)+'&format=json&callback=?',
		function(link) {
			tweetString = document.title+" : "+link.data.url;
			$(".sh_twitter").click(function(){ window.open('http://twitter.com/home?status='+encodeURIComponent(tweetString), "Post to Twitter"); });
		}
	);
}

$(document).ready(function() {
	buildShare();

	$(".shareType").hover(
		function() { $(this).css("background-color","#dfdfdf"); },
		function() { $(this).css("background-color","#eee"); }
	);

	$.getJSON(
		'http://feeds.delicious.com/v2/json/urlinfo/data?url='+encodeURIComponent(window.location)+'&callback=?',
		function(data) {$(".sh_delicious div .sharelink").append("<span>"+data[0].total_posts+"</span>");}
	);

	$.getJSON(
		'http://api.tweetmeme.com/url_info.jsonc?url='+encodeURIComponent(window.location)+'&callback=?',
		function(data) {
			if(data.story.url_count == 0) return;
			$(".sh_twitter div .sharelink").append("<span>"+data.story.url_count+"</span>");
		}
	);

	facebookFetch = encodeURIComponent('http://api.facebook.com/restserver.php?method=links.getStats&urls='+encodeURIComponent(window.location)),
	$.get(
		"http://hyperakt.com/crossFetch.php?url="+facebookFetch,
		function(data) {
			var shareCount = $(data).find('share_count').text();
			if(shareCount == 0) return;
			$(".sh_facebook div .sharelink").append("<span>"+shareCount+"</span>");
		}
	);
});