var RTR_ArticleURL = location.href.replace("idev.adminapps.amers.ime","jp").replace(":82","");

function shareHatena() {
	if (typeof(RTR_ArticleTitle) != 'undefined')
		commonPopup('http://b.hatena.ne.jp/append?'+(RTR_ArticleURL), 540, 500, 1, 'hatenaPopup');
}

function shareLivedoor() {
	if (typeof(RTR_ArticleTitle) != 'undefined')
		commonPopup('http://clip.livedoor.com/clip/add?link='+(RTR_ArticleURL)+'&title='+encodeURIComponent(RTR_ArticleTitle)+'&jump=myclip', 626, 436, 1, 'livedoorPopup');
}

function shareYahooBM() {
	if (typeof(RTR_ArticleTitle) != 'undefined')
		commonPopup('http://bookmarks.yahoo.co.jp/action/bookmark?t='+encodeURIComponent(RTR_ArticleTitle)+'&u='+(RTR_ArticleURL), 800, 500, 1, 'yahooPopup');
}

//function shareNewsing() {
//	if (typeof(RTR_ArticleTitle) != 'undefined')
//		commonPopup('http://newsing.jp/nbutton?title='+encodeURIComponent(RTR_ArticleTitle)+'&url='+(RTR_ArticleURL), 800, 500, 1, 'newsingPopup');
//}
function shareNewsing() {
	if (typeof(RTR_ArticleTitle) != 'undefined')
		commonPopup('http://newsing.jp/add?='+(RTR_ArticleURL)+encodeURIComponent(RTR_ArticleTitle), 800, 500, 1, 'newsingPopup');
}

function shareBuzzurl() {
	if (typeof(RTR_ArticleTitle) != 'undefined')
		commonPopup('http://buzzurl.jp/entry/'+(RTR_ArticleURL), 800, 500, 1, 'buzzurlPopup');
}

function shareChoix() {
	if (typeof(RTR_ArticleTitle) != 'undefined')
		commonPopup('http://www.choix.jp/bloglink/'+(RTR_ArticleURL), 800, 500, 1, 'choixPopup');
}

var arrShareLinks = new Array(
	"Hatena",
	"javascript:shareHatena();",
	"Livedoor",
	"javascript:shareLivedoor();",
	"YahooBM",
	"javascript:shareYahooBM();",
	"Newsing",
	"javascript:shareNewsing();",
	"Buzzurl",
	"javascript:shareBuzzurl();",
	"Choix",
	"javascript:shareChoix();"
);

var shareOverlayFocus = false;
var shareInterval;

// document.getElementById("shareLink").onclick = showShareOverlay;

function trimTools(strText) {
	return strText.replace(/\\./,"").replace("!","").replace(" ","");
}

function parseShareName(strWord) {
	if (strWord == "Hatena")
		strWord = "はてな";
	if (strWord == "Livedoor")
		strWord = "livedoor";
	if (strWord == "YahooBM")
		strWord = "Yahoo!";
	if (strWord == "Newsing")
		strWord = "NewsIng";		
	if (strWord == "Buzzurl")
		strWord = "Buzzurl";
	if (strWord == "Choix")
		strWord = "Choix";		
	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('+"'http://jp.reuters.com/tools/share',	620, 600, 1, 'sharePopup'"+');">(ソーシャルブッ<br />クマークとは?)</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;
		//IE fix
		//document.getElementById("shareLink").style.cssText = "float:right; margin:2px 5px 0 0;";
		//var intShareX1 = document.getElementById("shareLink").offsetLeft;
		//var intShareY1 = document.getElementById("shareLink").offsetTop;		
		//document.getElementById("shareContainer").innerHTML = strShareOverlay;
		//document.getElementById("shareContainer").className = "";
		document.getElementById("shareContainer").style.cssText = "position:absolute; top:0px; left:0px; float:right;";
	}
}
