var favorite_timeout_param;
var favorite_item_id = 0;
var this_url_without_http_with_slash = "abraham-marketing.com/function/favorite/";

var favorite_hreftype;
if(location.href.match("https"))
{
	favorite_hreftype = "https";
}
else
{
	favorite_hreftype = "http";
}


function fnOpen(eid,sid,point) 
{
	var ret = {}

	switch(point)
	{
		case "bottomright":
			ret = getPosition(sid, "bottomright");
			setPosition(eid, "topright", ret["x"], ret["y"]);
			break;
		case "bottomleft":
			ret = getPosition(sid, "bottomleft");
			setPosition(eid, "topleft", ret["x"], ret["y"]);
			break;
		case "topright":
			ret = getPosition(sid, "topright");
			setPosition(eid, "bottomright", ret["x"], ret["y"]);
			break;
		case "topleft":
			ret = getPosition(sid, "topleft");
			setPosition(eid, "bottomleft", ret["x"], ret["y"]);
			break;
	}
	clearTimeout(favorite_timeout_param);
	document.getElementById(eid).style.visibility = 'visible';
}

function fnClose(eid) {
	document.getElementById(eid).style.visibility = 'hidden';
}

function fnCloseSlow(eid)
{
	favorite_timeout_param = setTimeout("fnClose('"+eid+"')",1000);
}


function getPosition(eid, point)
{
	var x,y;
	var rtn = {};
	var ret = {};
	ret = getElementPosition(eid);
	switch(point)
	{
		case "topleft":
			x = ret["x"];
			y = ret["y"];
			break;
		case "topright":
			x = ret["x"] + document.getElementById(eid).offsetWidth;
			y = ret["y"];
			break;
		case "bottomleft":
			x = ret["x"];
			y = ret["y"] + document.getElementById(eid).offsetHeight;
			break;
		case "bottomright":
	//alert(document.getElementById(eid));
			x = ret["x"] + document.getElementById(eid).offsetWidth;
			y = ret["y"] + document.getElementById(eid).offsetHeight;
			break;
	}
	rtn["x"] = x;
	rtn["y"] = y;
	return rtn;
}

function getElementPosition(element) 
{
	var offsetTrail = (typeof element == 'string') ? document.getElementById(element) : element;
	var offsetLeft = 0;
	var offsetTop = 0;
	var rtn = {};

	while (offsetTrail) {
	offsetLeft += offsetTrail.offsetLeft;
	offsetTop += offsetTrail.offsetTop;
	offsetTrail = offsetTrail.offsetParent;
	}
	
	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != "undefined") {
	offsetLeft += document.body.leftMargin;
	offsetTop += document.body.topMargin;
	}
	rtn["x"] = offsetLeft;
	rtn["y"] = offsetTop;
	return rtn;
}

function setPosition(eid, point, x, y)
{
	var xx,yy;

	switch(point)
	{
		case "topleft":
			xx = x;
			yy = y;
			break;
		case "topright":
			xx = x - document.getElementById(eid).offsetWidth;
			yy = y;
			break;
		case "bottomleft":
			xx = x;
			yy = y - document.getElementById(eid).offsetHeight;
			break;
		case "bottomright":
			xx = x - document.getElementById(eid).offsetWidth;
			yy = y - document.getElementById(eid).offsetHeight;
			break;
	}

	document.getElementById(eid).style.left = xx + "px";
	document.getElementById(eid).style.top  = yy + "px";

}

function write_favorite(position)
{
	favorite_item_id++;
	
	switch(position)
	{
		case "bottomleft":
		case "bottomright":
		case "topleft":
		case "topright":
			break;
		default:
			position = "bottomleft";
			break;
	}

	document.write(""+
	"<style TYPE=\"text/css\">"+
	"<!--"+
	".favorite_menu"+
	"{"+
	"	border:solid 1px red;"+
	"	width: 150px;"+
	"}"+
	".favorite_menu_menu"+
	"{"+
	"	font-family: \"Hiragino Kaku Gothic Pro\", \"ヒラギノ角ゴ Pro W4\", 'メイリオ', \"Osaka\", \"ＭＳ Ｐゴシック \",sans-serif;"+
	"	 font-size	 : 1pt;"+
	"	 display	 : block;"+
	"	 text-align	 : center;"+
	"	 text-decoration : none;"+
	"	 width		 : 100px;"+
	"	 border      : 0px;"+
	"	}"+
	".favorite_menu_list	{"+
	"	text-align: left;"+
	"	 visibility: hidden;"+
	"	 position	 : absolute;"+
	"	 color		 : black;"+
	"	 background-color: white;"+
	"	 width		 : 350px;"+
	"	 margin-top  : -1px;"+
	"	 border-top	 : 1px solid #CCCCCC;"+
	"	 border-left : 1px solid #CCCCCC;"+
	"	 border-bottom: 1px solid #999999;"+
	"	 border-right: 1px solid #999999;"+
	"	}"+
	".favorite_menu_list	img"+
	"{"+
	"	vertical-align: middle;"+
	"	border: 0px;"+
	"}"+
	".favorite_menu_item"+
	"{"+
	"	font-family: \"Hiragino Kaku Gothic Pro\", \"ヒラギノ角ゴ Pro W4\", 'メイリオ', \"Osaka\", \"ＭＳ Ｐゴシック \",sans-serif;"+
	"	vetical-align: middle;"+
	"	 font-size	 : 10pt;"+
	"	 width		 : 100%;"+
	"	 text-decoration : none;"+
	"	 padding	 : 2px 4px 2px 4px;"+
	"	}"+
	"a.favorite_menu_item:link{"+
	"	 text-decoration : none;"+
	"	 color		 : #555555;"+
	"	}"+
	"a.favorite_menu_item:visited{"+
	"	 text-decoration : none;"+
	"	 color		 : #555555;"+
	"	}"+
	"a.favorite_menu_item:active{"+
	"	 text-decoration : none;"+
	"	 color		 : #FFFFFF;"+
	"	 background-color: #999999;"+
	"	}"+
	"a.favorite_menu_item:hover{"+
	"	 text-decoration : none;"+
	"	 color		 : #FFFFFF;"+
	"	 background-color: #999999;"+
	"	}"+
	"-->"+
	"</style>"+
	"	<div style=\"text-align:left;width:150px;\">"+
	"		<div id=\"favorite_menu_menu"+favorite_item_id+"\" onmouseout=\"fnCloseSlow('favorite_menu_list"+favorite_item_id+"');\">"+
	"			<a class=\"favorite_menu_menu\" href='javascript:window.external.AddFavorite(location.href,document.title);' onmouseover=\"fnOpen('favorite_menu_list"+favorite_item_id+"','favorite_menu_menu"+favorite_item_id+"','"+position+"');\"><img src=\""+favorite_hreftype+"://"+this_url_without_http_with_slash+"images/addfavorite.gif\" border=\"0\"></a>"+
	"		</div>"+
	"		<div id=\"favorite_menu_list"+favorite_item_id+"\" class=\"favorite_menu_list\" onmouseover=\"fnOpen('favorite_menu_list"+favorite_item_id+"','favorite_menu_menu"+favorite_item_id+"','"+position+"');\" onmouseout=\"fnCloseSlow('favorite_menu_list"+favorite_item_id+"');\">"+
	"			<a class=\"favorite_menu_item\" href='javascript:window.external.AddFavorite(location.href,document.title);'><img src=\""+favorite_hreftype+"://"+this_url_without_http_with_slash+"images/favorite_ie.gif\" target=\"_blank\">&nbsp;このページをブラウザのお気に入りに追加</a><br/>"+
	"			<a class=\"favorite_menu_item\" href='javascript:location.href=\"http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?ei=UTF-8&u=\"%2bencodeURIComponent(location.href)%2b\"&t=\"%2bencodeURIComponent(document.title);'><img src=\""+favorite_hreftype+"://"+this_url_without_http_with_slash+"images/favorite_yahoo.gif\" target=\"_blank\">&nbsp;このページをYahoo!ブックマークに登録</a><br />"+
	"			<a class=\"favorite_menu_item\" href='javascript:location.href=\"http://www.google.com/bookmarks/mark?op=add&bkmk=\"%2bencodeURIComponent(location.href)%2b\"&title=\"%2bencodeURIComponent(document.title);'><img src=\""+favorite_hreftype+"://"+this_url_without_http_with_slash+"images/favorite_google.gif\" border=\"0\" style=\"vertical-align:middle;\" target=\"_blank\">&nbsp;このページを Google Bookmarks に追加</a><br/>"+
//	"			<a class=\"favorite_menu_item\" href='javascript:location.href=\"http://b.hatena.ne.jp/add?mode=confirm&url=\"%2bencodeURIComponent(location.href)%2b\"&title=\"%2bencodeURIComponent(document.title);' target=\"_blank\"><img src=\""+favorite_hreftype+"://"+this_url_without_http_with_slash+"images/favorite_hatena.gif\">&nbsp;このページをはてなブックマークに登録</a><br/>"+
	"			<a class=\"favorite_menu_item\" href='javascript:location.href=\"http://b.hatena.ne.jp/add?mode=confirm&url="+location.href+"\";' target=\"_blank\"><img src=\""+favorite_hreftype+"://"+this_url_without_http_with_slash+"images/favorite_hatena.gif\">&nbsp;このページをはてなブックマークに登録</a><br/>"+
	"			<a class=\"favorite_menu_item\" href='javascript:location.href=\"http://clip.livedoor.com/redirect?link=\"%2bencodeURIComponent(location.href)%2b\"&title=\"%2bencodeURIComponent(document.title);' ><img src=\""+favorite_hreftype+"://"+this_url_without_http_with_slash+"images/favorite_livedoor.gif\" target=\"_blank\">&nbsp;この記事をLivedoorでクリップ！</a><br/>"+
	"			<a class=\"favorite_menu_item\" href='javascript:location.href=\"http://buzzurl.jp/config/add/confirm?url=\"%2bencodeURIComponent(location.href)%2b\"&title=\"%2bencodeURIComponent(document.title);' ><img src=\""+favorite_hreftype+"://"+this_url_without_http_with_slash+"images/favorite_buzzurl.gif\" target=\"_blank\">&nbsp;このページをBuzzurlにブックマーク</a><br/>"+
	"		</div>"+
	"	</div>"+
	"");
}	
