function PopupButton() {
	this.domain = location.href + '/';
	this.domain = this.domain.substr(this.domain.indexOf('://') + 3);
	this.domain = this.domain.substr(0, this.domain.indexOf('/'));
	this.location = false;

	this.imgurl = '/nojoomla/socbookmarks/panel.png';
	this.imgurl2 = '/nojoomla/socbookmarks/btn.gif';

	this.description='';
	this.keywords='';
	metaTags=document.getElementsByTagName("META");
	for (i=0;i<metaTags.length;i++){
		var meta=metaTags[i];
		if(meta.getAttribute('NAME')=='description'){
			this.description=meta.getAttribute('CONTENT');
		}else if(meta.getAttribute('NAME')=='keywords'){
			this.keywords=meta.getAttribute('CONTENT');
		}
	}


	this.selection = function() {
		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 encodeURIComponent(sel);
	}
	this.url = function(system) {
		var title = encodeURIComponent(document.title);
		var url = encodeURIComponent(location.href);
		switch (system) {
		case 1:
			return 'http://memori.ru/link/?sm=1&u_data[url]=' + url
					+ '&u_data[name]=' + title;
		case 2:
			return 'http://bobrdobr.ru/addext.html?url=' + url + '&title='
					+ title;
		case 3:
			return 'http://www.google.com/bookmarks/mark?op=add&bkmk=' + url
					+ '&title=' + title;
		case 4:
			return 'http://zakladki.yandex.ru/userarea/links/addfromfav.asp?bAddLink_x=1&lurl='
					+ url + '&lname=' + title;
		case 5:
			return 'http://twitter.com/home?status=' + title + ' ' + url;
		case 6:
			return 'http://del.icio.us/post?v=4&noui&jump=close&url=' + url
					+ '&title=' + title;
		case 7:
			return 'http://text20.ru/add/?source=' + url + '&title=' + title
					+ '&text=' + this.selection();
		case 8:
			return 'http://news2.ru/add_story.php?url=' + url;
		case 9:
			return 'http://www.mister-wong.ru/index.php?action=addurl&bm_url='
					+ url + '&bm_description=' + title;
		case 10:
			return 'http://moemesto.ru/post.php?url=' + url + '&title=' + title;
		case 11:
			return 'http://smi2.ru/add/?url=' + url + '&precaption=' + title;
		case 12:
			return 'http://www.vaau.ru/submit/?action=step2&url=' + url;
		case 13:
			return 'http://myscoop.ru/add/?URL=' + url + '&title=' + title;
		case 14:
			return 'http://www.linkstore.ru/servlet/LinkStore?a=add&url=' + url
					+ '&title=' + title;
		case 15:
			return 'http://www.ruspace.ru/index.php?link=bookmark&action=bookmarkNew&bm=1&url='
					+ url + '&title=' + title;
		case 16:
			return 'http://www.100zakladok.ru/save/?bmurl=' + url + '&bmtitle='
					+ title;
		case 17:
			return 'http://vkontakte.ru/share.php?url=' + url;			
					
		}
	}
	this.hide = function() {
		if (this.timeout)
			clearTimeout(this.timeout);
		document.getElementById('pup').style.visibility = 'hidden';
	}
	this.show = function(element) {
		if (this.timeout)
			clearTimeout(this.timeout);
		var left = 0, top = 0;
		var style = document.getElementById('pup').style;
		while (element) {
			left += element.offsetLeft;
			top += element.offsetTop;
			element = element.offsetParent;
		}
		style.left = left + 'px';
		style.top = top + 'px';
		style.visibility = 'visible';
	}
	this.init = function() {
		var titles = new Array(
				'Memori',
				'БобрДобр',
				'Закладки Google',
				'Яндекс.Закладки',
				'Twitter',
				'del.icio.us',
				'Текст 2.0',
				'News2',
				'Мистер Вонг',
				'МоёМесто',
				'СМИ 2',
				'Ваау!',
				'AddScoop',
				'LinkStore',
				'RuSpace',
				'Сто Закладок',
				'ВКонтакте');
		if (!document.getElementById('pup')) {
			var div = document.createElement('div');
			div.id = 'pup';
			div.style.position = 'absolute';
			div.style.visibility = 'hidden';
			div.style.width = '264px';
			div.style.height = '182px';
			div.style.backgroundColor = 'transparent';
			div.style.backgroundImage = 'url(' + this.imgurl + ')';
			div.style.border = '0';
			div.style.margin = '0';
			div.style.padding = '0 1px 4px 1px';
			div.style.overflow = 'hidden';
			div.style.zIndex = '1000';
			div.style.font = 'normal 12px arial';
			div.style.lineHeight = '20px';
			div.style.color = '#666';
			html = '<a span style="display:block;float:left;width:258px;height:20px;overflow:hidden;margin:1px 0;padding:0;background-color:transparent;font:bold 11px arial;color:#666;text-decoration:none"></span>';
			for ( var i = 0; i < 17; i++) {
				html += '<a target="_blank" href="'
						+ this.url(i + 1)
						+ '" style="display:block;float:left;width:108px;height:16px;overflow:hidden;margin:1px 0;padding:0 0 0 24px;background-color:transparent;background:url(' + this.imgurl + ') no-repeat -266px '+ (-i * 16)
						+ 'px;font:normal 12px arial;color:#666;text-decoration:none;text-align:left" onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'" >' + titles[i] + '</a>';
			}

			div.innerHTML = html;
			div.onmouseover = function() {
				if (popupButton.timeout)
					clearTimeout(popupButton.timeout)
			}
			div.onmouseout = function() {
				popupButton.timeout = setTimeout('popupButton.hide()', 500)
			};
			document.body.insertBefore(div, document.body.firstChild);
		}
		document
				.write('<a'
						+ (document.body.clientWidth / 2 - 300)
						+ ',top='
						+ (document.body.clientHeight / 2 - 250)
						+ ',resizable=yes,toolbar=no,location=no,status=no\');return false;"><img src=" ' + this.imgurl2 + ' " width="24" height="16" alt="&#1044;&#1086;&#1073;&#1072;&#1074;&#1080;&#1090;&#1100;&#1047;&#1072;&#1082;&#1083;&#1072;&#1076;&#1082;&#1080;" title="&#1044;&#1086;&#1073;&#1072;&#1074;&#1080;&#1090;&#1100;&#1047;&#1072;&#1082;&#1083;&#1072;&#1076;&#1082;&#1080;" style="border:0;margin:0;padding:0" onmouseover="popupButton.show(this);" onmouseout="popupButton.timeout=setTimeout(\'popupButton.hide()\',500);"></a>');
	}
}
popupButton = new PopupButton();
popupButton.init();
