var RTR_ArticleURL = location.href;
if (location.href.search("\\?") != -1) {
	RTR_ArticleURL = location.href.split("?")[0];
}

function bookDelicious(btitle,bdesc,mnu) {
 opensesame('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(RTR_ArticleURL+"?mnu=" + mnu)+'&title='+encodeURIComponent(btitle)+'&notes='+encodeURIComponent(bdesc)+'&tags=news');
}
function bookDigg(btitle,bdesc,mnu) {
	opensesame('http://digg.com/remote-submit?phase=2&url='+encodeURIComponent(RTR_ArticleURL+"?mnu=" + mnu) +'&title='+encodeURIComponent(btitle)+'&bodytext='+encodeURIComponent(bdesc));
//+'&topic=302');
}
function bookgoogle(btitle,bdesc,mnu) {
opensesame('http://google.com/bookmarks/mark?op=add&bkmk='+encodeURIComponent(RTR_ArticleURL+"?mnu=" + mnu)+'&title='+encodeURIComponent(btitle)+'&annotation='+encodeURIComponent(bdesc));

   }

function bookreddit(btitle,bdesc,mnu) {
opensesame('http://reddit.com/submit?url='+encodeURIComponent(RTR_ArticleURL+"?mnu=" + mnu));
   }
function bookstumbleUpon(btitle,bdesc,mnu) {
opensesame('http://www.stumbleupon.com/submit?url='+encodeURIComponent(RTR_ArticleURL+"?mnu=" + mnu) + '&title='+encodeURIComponent(btitle));
   }
function bookYahoo(btitle,bdesc,mnu) {                           
opensesame('http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+encodeURIComponent(btitle)+'&u='+encodeURIComponent(RTR_ArticleURL+"?mnu="+mnu)+'&ei=UTF-8'+'&d='+encodeURIComponent(bdesc)+'&tag=news');
}

function shareFacebook() {
	if (typeof(RTR_ArticleTitle) != 'undefined')
		commonPopup('http://www.facebook.com/sharer.php?u='+encodeURIComponent(RTR_ArticleURL+"?rpc=60")+'&t='+encodeURIComponent(RTR_ArticleTitle), 626, 436, 1, 'facebookPopup');
}

function shareNewsvine() {
	if (typeof(RTR_ArticleTitle) != 'undefined')
		commonPopup('http://www.newsvine.com/_wine/save?aff=reuters&h='+encodeURIComponent(RTR_ArticleTitle)+'&t=world-news&u='+encodeURIComponent(RTR_ArticleURL+"?rpc=63")+'&e='+encodeURIComponent(RTR_ArticleBlurb), 650, 445, 1, 'newsvinePopup');
}


function shareMixx() {
	if (typeof(RTR_ArticleTitle) != 'undefined')
		commonPopup('http://www.mixx.com/submit/story?title='+encodeURIComponent(RTR_ArticleTitle)+'&page_url='+encodeURIComponent(RTR_ArticleURL+"?rpc=62")+'&partner=REU&description='+encodeURIComponent(RTR_ArticleBlurb), 1024, 640, 1, 'mixxPopup');
}



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() {
	if (!document.getElementById("shareContainer")) {
		var shareDiv = document.createElement("div");
		shareDiv.id = "shareContainer";
		shareDiv.className = "hidden";
		var objShareDiv = document.getElementById("atools").insertBefore(shareDiv, document.getElementById("autilities"));
	}
	if (document.getElementById("shareContainer").innerHTML == '') {
		showShareOverlay();
	} else {
		hideShareOverlay();
	}
}

function showShareOverlay() {
	var strShareOverlay = '<div id="shareTab"></div>';	
	strShareOverlay += '<div id="shareShadow"><div id="shareContents">';	
	for (i=0; i<arrShareLinks.length; i++) {
		if ((i%2) == 0) {
			strShareOverlay += '<div class="shareTool">';
			strShareOverlay += '<a id="' + trimTools(arrShareLinks[i]).toLowerCase() + 'Link" href="' + arrShareLinks[i+1] + '">' + parseShareName(arrShareLinks[i]) + '</a>';
			strShareOverlay += '</div>';
		}
	}
	strShareOverlay += '<div id="shareWhat"><a href="javascript:commonPopup('+"'/tools/share',	540, 600, 1, 'sharePopup'"+');">(what is this?)</a></div>';
	strShareOverlay += '</div></div>';
	strShareOverlay += '<div id="shareCloseButton"><a href="javascript:hideShareOverlay();"></a></div>';
	if (document.getElementById) {
		var intShareX = document.getElementById("shareLink").offsetLeft - 6;
		var intShareY = document.getElementById("shareLink").offsetTop + document.getElementById("shareLink").offsetHeight - 2;		
		document.getElementById("shareContainer").innerHTML = strShareOverlay;
		document.getElementById("shareContainer").className = "";
		document.getElementById("shareContainer").style.cssText = "position:absolute; top:" + intShareY + "px; left:" + intShareX + "px;";
	}
}

function hideShareOverlay() {
	if (document.getElementById) {
		document.getElementById("shareContainer").innerHTML = "";
		document.getElementById("shareContainer").className = "hidden";
		document.getElementById("shareContainer").style.cssText = "";
		shareOverlayFocus = false;
	}
}
