
var shareTimeout = 0;

function openShare(parentObj, URL, jsSafeTitle){
	URL = siteDomain + URL;
	jsSafeTitle = jsSafeTitle.replace("'", "\\'");
	keepShare();
	$('#shareLinksGroup').remove();
	$('body').append('<div class="cF" id="shareLinksGroup">\
		<div class="ltCol">\
			<a class="iconDigg" href="javascript:articleShare(\'digg\',\''+URL+'\',\''+jsSafeTitle+'\',\''+jsSafeTitle+'\')">digg</a><br>\
			<a class="iconFace" href="javascript:articleShare(\'facebook\',\''+URL+'\',\''+jsSafeTitle+'\',\''+jsSafeTitle+'\')">facebook</a><br>\
			<a class="iconMySp" href="javascript:articleShare(\'myspace\',\''+URL+'\',\''+jsSafeTitle+'\',\''+jsSafeTitle+'\')">myspace</a><br>\
		</div>\
		<div class="rtCol">\
			<a class="iconDeli" href="javascript:articleShare(\'delicious\',\''+URL+'\',\''+jsSafeTitle+'\',\''+jsSafeTitle+'\')">del+icio+us</a><br>\
			<a class="iconPerm" href="javascript:articleShare(\'permalink\',\''+URL+'\',\''+jsSafeTitle+'\',\''+jsSafeTitle+'\')">permalink</a><br>\
			<a class="iconEmail" href="javascript:sendToFriend(\''+URL+'\', \''+jsSafeTitle+'\')" title="email" rel="nofollow">email</a>\
		</div>\
		<br class="clear">\
	</div>');
	var pos = $(parentObj).offset();
	
	$('#shareLinksGroup').css({
		top: 15 + pos.top + "px", 
		left: pos.left + "px"
		}).mouseleave(function(){ closeShare(); }).mouseenter(function(){ keepShare(); });
}

function removeShare() {
	if (shareTimeout != 0) {
		clearTimeout(shareTimeout);
		shareTimeout = 0;
	}
	$('#shareLinksGroup').remove();
}
function keepShare() {
	if (shareTimeout != 0) {
		clearTimeout(shareTimeout);
		shareTimeout = 0;
	}
}
function closeShare() {
	if (shareTimeout != 0) {
		clearTimeout(shareTimeout);
		shareTimeout = 0;
	}
	shareTimeout = setTimeout('removeShare()',300);
}

function toggleShareLinks(wId){
	$("#sLinks"+wId).toggle();
}

function articleShare(site,popUpUrl, title, description) {
  switch (site) {
	case "facebook":
		postPopUp('http://www.facebook.com/sharer.php?u=' + popUpUrl + '&t=' + encodeURIComponent(title), 'facebook', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
		break;
	case "digg":
		postPopUp('http://digg.com/remote-submit?phase=2&url=' + popUpUrl + '&title=' + encodeURIComponent(title) + '&bodytext=' + encodeURIComponent(description), 'digg', 'toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes');
		break;
	case "myspace":
		postPopUp('http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(title) + '&c=' + encodeURIComponent(description) + '&u=' + encodeURIComponent(popUpUrl) + '&l=' + '3', 'myspace', 'toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes');
		break;
	case "delicious":
		postPopUp('http://del.icio.us/v1/posts/add?&url=' + popUpUrl + '&description=' + encodeURIComponent(description), 'delicious', 'toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes');		
		break;
	case "permalink":
		alert('Copy the link in your browser window and post to your blog');
		break;
	}
  shareLinks(site,'article');
}
 
function postPopUp(url, name, params) {
	var win = window.open(url, name, params);
}