var btn_timer = false;
function btn_show_popup(item)
{
	clearTimeout(btn_timer);
	var left=0,top=0;
	var toggle_child = document.getElementById('btn_popup');

	var style= toggle_child.style;
	var element = toggle_child.parentNode.firstChild;

	while (element) {
		left+=element.offsetLeft;
		top+=element.offsetTop;
		element=element.offsetParent;
	}
	style.left=left - 20 +'px';
	style.top= top-175+'px';
	toggle_child.style.visibility = 'visible';
	document.getElementById('img_popup').style.visibility = 'hidden';

}
function btn_hide_popup(item)
{
	btn_timer = setTimeout(
		function() {
			var btn = document.getElementById('btn_popup');
			btn.style.visibility = 'hidden';
				document.getElementById('img_popup').style.visibility = 'visible';
		}
		,1000);
}

function btn_selection()
{
	var sel='';
	if (window.getSelection)
		sel=window.getSelection();
	else if (document.selection)
		sel=document.selection.createRange();
	else
		sel='';
	if (sel.text)
		sel=sel.text;
	return sel;
}

function getBrowserInfo() {
	var t,v = undefined;
	if (window.opera)
		t = 'Opera';
	else if (document.all) {
		t = 'IE';
		var nv = navigator.appVersion;
		var s = nv.indexOf('MSIE')+5;
		v = nv.substring(s,s+1);
	}
	else if (navigator.appName)
		t = 'Netscape';
	return {type:t,version:v};
}

function btn_bookmark(a){
	var url = window.document.location;
	var title = window.document.title;
	var b = getBrowserInfo();
	if (b.type == 'IE' && 7 > b.version && b.version >= 4)
		window.external.AddFavorite(url,title);
	else if (b.type == 'Opera') {
		a.href = url;
		a.rel = "sidebar";
		a.title = title;
		return true;
	}
	else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
	else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки браузера.");
	return false;
}

function btntn()
{
	var title=encodeURIComponent(document.title);
	var url=encodeURIComponent(location.href);

	this.links = [
		{name:'Memory', link:'http://memori.ru/link/?sm=1&u_data[url]='+url+'&u_data[name]='+title, pos:'-264px 0'},
		{name:'БобрДобр', link:'http://bobrdobr.ru/addext.html?url='+url+'&title='+title, pos:'-264px -144px'},
		{name:'Google', link:'http://www.google.com/bookmarks/mark?op=add&bkmk='+url+'&title='+title, pos:'-264px -16px'},
		{name:'Яндекс', link:'http://zakladki.yandex.ru/userarea/links/addfromfav.asp?bAddLink_x=1&lurl='+url+'&lname='+title, pos:'-264px -160px'},
		{name:'Stumble', link:'http://www.stumbleupon.com/submit?url='+url+'&title='+title, pos:'-264px -32px'},
		{name:'Delicious', link:'http://del.icio.us/post?v=4&noui&jump=close&url='+url+'&title='+title, pos:'-264px -176px'},
		{name:'Yahoo!', link:'http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+url+'&t='+title, pos:'-371px -112px'},
		{name:'Blogger', link:'http://www.blogger.com/blog_this.pyra?t&u='+url+'&n='+title, pos:'-371px -144px'},
		{name:'FriendFeed', link:'http://friendfeed.com/share?link='+url+'&title='+title, pos:'-371px -96px'},
		{name:'Текст 2.0', link:'http://text20.ru/add/?source='+url+'&title='+title+'&text='+btn_selection(), pos:'-264px -48px'},
		{name:'News 2', link:'http://news2.ru/add_story.php?url='+url, pos:'-264px -192px'},
		{name:'MySpace', link:'http://www.myspace.com/Modules/PostTo/Pages/?u='+url+'&t='+title+'&c=%3Ca+href%3D%22'+url+'%3E'+title+'%3C%2Fa%3E%0A', pos:'-371px -128px'},
		{name:'Мистер Вонг', link:'http://www.mister-wong.ru/index.php?action=addurl&bm_url='+url+'&bm_description='+title, pos:'-264px -64px'},
		{name:'Моё Место', link:'http://moemesto.ru/post.php?url='+url+'&title='+title, pos:'-371px 0'},
		{name:'СМИ 2', link:'http://smi2.ru/add/?url='+url+'&precaption='+title, pos:'-264px -80px'},
		{name:'Baay!', link:'http://www.vaau.ru/submit/?action=step2&url='+url, pos:'-371px -16px'},
		{name:'LinkStore', link:'http://www.linkstore.ru/servlet/LinkStore?a=add&url='+url+'&title='+title, pos:'-371px -32px'},
		{name:'RuSpace', link:'http://www.ruspace.ru/index.php?link=bookmark&action=bookmarkNew&bm=1&url='+url+'&title='+title, pos:'-264px -112px'},
		{name:'Сто закладок', link:'http://www.100zakladok.ru/save/?bmurl='+url+'&bmtitle='+title, pos:'-371px -48px'},
		{name:'Мблоги', link:'http://mblogi.ru/knopka/?url='+url+'&title='+title, pos:'-371px -176px'}
	];
	this.links_main =[
                {name:'Liveinternet', link:'http://www.liveinternet.ru/journal_post.php?action=l_add&cnurl='+url+'&title='+title, pos:'32px 0px'},
		{name:'Twitter', link:'http://twitter.com/home?status='+title+' '+url, pos:'0px 0px'},
		{name:'Вконтакте', link:'http://vkontakte.ru/share.php?url='+url, pos:'-32px -0px'},
		{name:'Facebook', link:'http://www.facebook.com/share.php?u='+url+'&t='+title, pos:'-64px -0px'},
		{name:'LiveJournal', link:'http://www.livejournal.com/update.bml?subject='+title+'&event=%3Ca+href%3D%22'+url+'%22%3E'+title+'%3C%2Fa%3E%0A%0A', pos:'-96px 0px'},
		{name:'mail', link:'http://connect.mail.ru/share?share_url='+url, pos:'-128px 0px'},
	];

	var bookmark_width = 85;
	var bookmark_height = 18;
	var button_text = '';
	var img = 'http://www.werno.ru/bookmarks/sharing_buttons.png';
	
	button_text +='<div>'+
	'<div id="btn" style="display:block;width:237px;height:26px;color:#000;font-family:arial;font-size:10px;font-style:normal;font-weight:normal;font-variant:normal;color:#000;line-height:normal;font-size-adjust:none;vertical-align: middle;background:url('+img+') no-repeat -2px -179px;" title="Добавить сайт в закладки">';
	for(var l in this.links_main)
	{
		button_text +='<a href="'+this.links_main[l].link+'" target="_blank" title="'+this.links_main[l].name+'" style="float:left;margin-top:4px;padding:0px;margin-right: 2px;font-family:arial;color:#000;font-size-adjust:none;text-align:left;display:inline-block;width:18px; height:18px;vertical-align:middle;position:relative;top:2px;left:102px;"></a>';
	}
	button_text +='<div onmouseover="btn_show_popup(this)" onmouseout="btn_hide_popup(this)" style="display:block;overflow:hidden;float:left;position: relative;top:0px;left:103px;width:14px;height:26px;"><i id="img_popup" style="background:url('+img+') no-repeat -226px -209px;width:14px;height:26px;display:block;"></i></div>'+
	'</div>'+
	'<div id="btn_popup" onmouseover="btn_show_popup(this)" onmouseout="btn_hide_popup(this)" style="visibility:hidden;position:absolute; left:0; top:50px;"><div style="height:170px;width:255px;z-index:1000;background:url('+img+') no-repeat -4px -1px;padding-top:5px;padding-left:5px;margin:0;border:0">'+
	'<a onclick="return btn_bookmark(this)" href="#" style="text-align:center;width:'+bookmark_width+'px;display:block;-display: inline;text-align:center;float:left;overflow:hidden;font-family:arial;font-size:12px;margin-top:2px;font-style:normal;font-weight:normal;font-variant:normal;color:#000;text-decoration:none;line-height:normal;font-size-adjust:none;text-align:left;">В избранное</a>';

	for(var l in this.links)
	{
		button_text +='<a href="'+this.links[l].link+'" target="_blank" style="width:'+bookmark_width+'px; height:'+bookmark_height+'px;display:block;-display: inline;text-align:center;float:left;overflow:hidden;font-family:arial;font-size:12px;margin-top:2px;font-style:normal;font-weight:normal;font-variant:normal;color:#000;text-decoration:none;line-height:normal;font-size-adjust:none;text-align:left;">'+
		'<i style="background:url('+img+') no-repeat '+this.links[l].pos+';display:inline-block;width:16px; height:16px;vertical-align: middle;"></i>&nbsp;'+this.links[l].name+'</a>';
	}
	button_text +='<a target=_blank href="http://www.werno.ru/seo-masscheck/" style="font-size:11px;display:block;text-align:center;" title="Добавить сайт в социальные закладки">werno.ru</a>'+
	'</div></div>'+
	'</div>';
	document.write(button_text);
}

btntn();
