var lastHREF = location.href;

function getShareHTML(url,title) {
	var niceURL = escape(url);
	var niceTitle = escape(title);
	return '<li id="global-nav-share-facebook"><iframe src="http://www.facebook.com/plugins/like.php?href=' + niceURL + '&amp;layout=button_count&amp;show_faces=true&amp;width=90&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe></li>' +
		'<li><a href="http://twitter.com/home?status=' + niceTitle + '+' + niceURL + '" target="_blank" id="global-nav-share-twitter" onclick="capture(\'event44, event19, event22\',\'Share This Twitter\')">Twitter</a></li>' +
		'<li><a href="mailto:?subject=' + niceTitle + '&amp;body=' + niceURL + '" id="global-nav-share-email" onclick="capture(\'event44, event19, event20\',\'Email Share This\')">E-mail</a></li>' +
		'<li><a href="http://www.stumbleupon.com/submit?url=' + niceURL + '%26title=' + niceTitle + '" target="_blank" id="global-nav-share-stumbleupon" onclick="capture(\'event44, event19\',\'StumbleUpon Share This\')">StumbleUpon</a></li>' +
		'<li><a href="http://del.icio.us/post?url=' + niceURL + '%26title=' + niceTitle + '" target="_blank" id="global-nav-share-delicious" onclick="capture(\'event44, event19\',\'Delicious Share This\')">Delicious</a></li>' +
		'<li><a href="http://digg.com/submit?phase=2%26url=' + niceURL + '%26title=' + niceTitle + '" target="_blank" id="global-nav-share-digg" onclick="capture(\'event44, event19\',\'Digg Share This\')">Digg</a></li>' +
		'<li><a href="http://www.reddit.com/submit?url=' + niceURL + '%26title=' + niceTitle + '" target="_blank" id="global-nav-share-reddit" onclick="capture(\'event44, event19\',\'Reddit Share This\')">Reddit</a></li>';
}

$(document).ready(function(){
	var html = '<ul id="global-nav-right" class="global-nav-buttons"><li id="global-nav-share" class="global-nav-button">' + 
		'<a href="#" id="global-nav-share-anchor" class="global-nav-anchor"><span>Share this page</span></a>' +
		'<ul>' +
			getShareHTML(location.href,document.title) + 
		'</ul>' +
	'</li></ul>';
	$(html).appendTo('#global-nav-fixed');
	var ul = $('#global-nav-share ul');
	var newPos = -900 + (ul.width()-$('#global-nav-share-anchor').width());
	ul.css('background-position', newPos+'px 0');
	$('#global-nav-share').hover(function(){
		if (location.href != lastHREF) {
			lastHREF = location.href;
			$('ul:first',this).html(getShareHTML(location.href,document.title));
		}
		$(this).addClass('global-nav-share-active');
	}, function(){
		$(this).removeClass('global-nav-share-active');
	});
});
