var RTR_ArticleBlurb="";

function shareDelicious(url,title) {
	if (typeof(title) != 'undefined')
		commonPopup('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(url+"?rpc=28")+'&title='+encodeURIComponent(title)+'&notes='+encodeURIComponent(RTR_ArticleBlurb)+'&tags=news', 540, 500, 1, 'deliciousPopup');
}

function shareFacebook(url,title) {
	if (typeof(title) != 'undefined')
		commonPopup('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url+"?rpc=60")+'&t='+encodeURIComponent(title), 626, 436, 1, 'facebookPopup');
}

function shareNewsvine(url,title) {
	if (typeof(title) != 'undefined')
		commonPopup('http://www.newsvine.com/_wine/save?aff=reuters&h='+encodeURIComponent(title)+'&t=world-news&u='+encodeURIComponent(url+"?rpc=63")+'&e='+encodeURIComponent(RTR_ArticleBlurb), 650, 445, 1, 'newsvinePopup');
}

function shareYahoo(url,title) {
	if (typeof(title) != 'undefined')
		commonPopup('http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+encodeURIComponent(title)+'&u='+encodeURIComponent(url+"?rpc=46")+'&ei=UTF-8'+'&d='+encodeURIComponent(RTR_ArticleBlurb)+'&tag=news', 620, 540, 1, 'yahooPopup');
}

function shareMixx(url,title) {
	if (typeof(title) != 'undefined')
		commonPopup('http://www.mixx.com/submit/story?title='+encodeURIComponent(title)+'&page_url='+encodeURIComponent(url+"?rpc=62")+'&partner=REU&description='+encodeURIComponent(RTR_ArticleBlurb), 1024, 640, 1, 'mixxPopup');
}

function shareDigg(url,title) {
	if (typeof(title) != 'undefined')
		commonPopup('http://digg.com/remote-submit?phase=2&url='+encodeURIComponent(url+"?rpc=64")+'&title='+encodeURIComponent(title)+'&bodytext='+encodeURIComponent(RTR_ArticleBlurb)+'&topic=world_news', 540, 500, 1, 'diggPopup');
}

var arrShareLinks = new Array(
	"Delicious",
	"javascript:shareDelicious",
	"Digg",
	"javascript:shareDigg",
	"Facebook",
	"javascript:shareFacebook",
//	"Mixx",
//	"javascript:shareMixx;",
	"Newsvine",
	"javascript:shareNewsvine",
	"Yahoo!",
	"javascript:shareYahoo"
);

var shareOverlayFocus = false;
var shareInterval;

// document.getElementById("shareLink").onclick = showShareOverlay;

function trimTools(strText) {
	return strText.replace(/\\./,"").replace("!","").replace(" ","");
}

function parseShareName(strWord) {
	if (strWord == "Delicious")
		strWord = "Del.icio.us";
	return strWord;
}

function tryShareOverlay(id,url,title) {
	if (!document.getElementById("shareContainer-"+id)) {
		var shareDiv = document.createElement("div");
		shareDiv.id = "shareContainer-"+id;
		shareDiv.className = "hidden";
		var objShareDiv = document.getElementById("atools-"+id).insertBefore(shareDiv, document.getElementById("autilities-"+id));
	}
	if (document.getElementById("shareContainer-"+id).innerHTML == '') {
		showShareOverlay(id,url,title);
	} else {
		hideShareOverlay(id);
	}
}

function showShareOverlay(id,url,title) {
	var strShareOverlay = '<div id="shareTab-'+id+'" class="shareTab"></div>';	
	strShareOverlay += '<div id="shareShadow-'+id+'" class="shareShadow"><div id="shareContents-'+id+'" class="shareContents">';	
	for (i=0; i<arrShareLinks.length; i++) {
		if ((i%2) == 0) {
			strShareOverlay += '<div class="shareTool-'+id+'">';
			strShareOverlay += '<a id="' + trimTools(arrShareLinks[i]).toLowerCase() + 'Link" href="' + arrShareLinks[i+1] + '(\''+url+'\',\''+title+'\')">' + parseShareName(arrShareLinks[i]) + '</a>';
			strShareOverlay += '</div>';
		}
	}
	strShareOverlay += '<div id="shareWhat"><a href="javascript:commonPopup('+"'http://www.reuters.com/tools/share',	540, 600, 1, 'sharePopup'"+');">(what is this?)</a></div>';
	strShareOverlay += '</div></div>';
	strShareOverlay += '<div id="shareCloseButton"><a href="javascript:hideShareOverlay('+id+');"></a></div>';
	if (document.getElementById) {
		var intShareX = document.getElementById("shareLink-"+id).offsetLeft - 6;
		var intShareY = document.getElementById("shareLink-"+id).offsetTop + document.getElementById("shareLink-"+id).offsetHeight - 2;		

		document.getElementById("shareContainer-"+id).innerHTML = strShareOverlay;
		document.getElementById("shareContainer-"+id).className = "shareContainer";
		document.getElementById("shareContainer-"+id).style.cssText = "position:absolute; top:" + intShareY + "px; left:" + intShareX + "px;";
	}
}

function hideShareOverlay(id) {
	if (document.getElementById) {
		document.getElementById("shareContainer-"+id).innerHTML = "";
		document.getElementById("shareContainer-"+id).className = "hidden";
		document.getElementById("shareContainer-"+id).style.cssText = "";
		shareOverlayFocus = false;
	}
}
