function AddToBookmark(a) { 
  title=document.title; 
  url=document.location; 
  try { 
    window.external.AddFavorite(url, title); 
  } 
  catch (e) { 
    try { 
      window.sidebar.addPanel(title, url, ""); 
    } 
    catch (e) { 
      if (typeof(opera)=="object") { 
        a.rel="sidebar"; 
        a.title=title; 
        a.url=url; 
        return true; 
      } 
      else { 
        alert('Для добавления страницы в Избранное нажмите Ctrl+D'); 
      } 
    } 
  } 
  return false; 
} 

var NotisCss='#f1f1f1';
var NoticeStyle='margin:0;padding:0;width:131px;background:'+NotisCss+';float:left;text-align:left;color:black;font:normal 12px arial;line-height:20px';
var BankImg='http://wmdn.ru/images/';
function NewButton() {
         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.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.redirect=function() {
              if (this.location) location.href=this.location;
              this.location=false;
         }
         this.go=function(i) {
              this.location=this.url(i);
              setTimeout('CButton.redirect()',50);
         }
         this.url=function(system) {
              var title=encodeURIComponent(document.title);
              var url=encodeURIComponent(location.href);
              switch (system) {
                      case 0: return 'http://zakladki.yandex.ru/userarea/links/addfromfav.asp?bAddLink_x=1&lurl='+url+'&lname='+title;
                      case 1: return 'http://www.google.com/bookmarks/mark?op=add&bkmk='+url+'&title='+title;
					  case 2: return '';
					  case 3: return 'mailto:vasha@po4ta.ru?subject='+url;
              }
         }
         this.hide=function() {
              if (this.timeout) clearTimeout(this.timeout);
              document.getElementById('IdButton').style.visibility='hidden';
         }
         this.show=function(element) {
              if (this.timeout) clearTimeout(this.timeout);
              var left=0,top=0;
              var style=document.getElementById('IdButton').style;
              while (element) {
                     left+=element.offsetLeft;
                     top+=element.offsetTop;
                     element=element.offsetParent;
              }
              style.left=left+'px';
              style.top=(top+20)+'px';
              style.visibility='visible';
         }
         this.init=function() {
              var titles=new Array('&#1071;&#1085;&#1076;&#1077;&#1082;&#1089;.&#1047;&#1072;&#1082;&#1083;&#1072;&#1076;&#1082;&#1080;','&#1047;&#1072;&#1082;&#1083;&#1072;&#1076;&#1082;&#1080; Google','&#1042;	&#1048;&#1079;&#1073;&#1088;&#1072;&#1085;&#1085;&#1086;&#1077;','&#1053;&#1072; &#1055;&#1086;&#1095;&#1090;&#1091;');
              if (!document.getElementById('IdButton')) {
                   var div=document.createElement('div');
                   var style=div.style;
                   div.id='IdButton';
                   div.innerHTML='<span style="'+NoticeStyle+'">&nbsp;&#1044;&#1086;&#1073;&#1072;&#1074;&#1080;&#1090;&#1100; &#1074; &#1079;&#1072;&#1082;&#1083;&#1072;&#1076;&#1082;&#1080;:</span>';
                   for (i=0;i<4;i++) {
					   if (i==2){
					   div.innerHTML+='<a onclick="return AddToBookmark(this);" href="'+this.url(i)+'" ><img src="'+BankImg+'backg.gif" width="16" height="16" title="'+titles[i]+'" style="border:0;padding:0;margin:2px;float:left;background:url('+BankImg+'buttons.png) -'+(i*16)+'px"/></a><a onclick="return AddToBookmark(this);" href="'+this.url(i)+'" style="float:left;width:110px;text-align:left;text-decoration:none;color:#666;font:normal 12px arial;line-height:20px;border:0" onmouseover="this.style.background=\''+NotisCss+'\'" onmouseout="this.style.background=\'#fff\'" >'+titles[i]+'</a><br />';   
					   }
					   else {
                       div.innerHTML+='<a target="_blank" href="'+this.url(i)+'" ><img src="'+BankImg+'backg.gif" width="16" height="16" title="'+titles[i]+'" style="border:0;padding:0;margin:2px;float:left;background:url('+BankImg+'buttons.png) -'+(i*16)+'px"/></a><a target="_blank" href="'+this.url(i)+'" style="float:left;width:110px;text-align:left;text-decoration:none;color:#666;font:normal 12px arial;line-height:20px;border:0" onmouseover="this.style.background=\''+NotisCss+'\'" onmouseout="this.style.background=\'#fff\'" >'+titles[i]+'</a><br />';
					   }
                   }
                   div.onmouseover=function() {if (CButton.timeout) clearTimeout(CButton.timeout)}
                   div.onmouseout=function() {CButton.timeout=setTimeout('CButton.hide()',500)};
                   style.position='absolute';
                   style.visibility='hidden';
                   style.maxWidth='131px';
				   style.width='132px';
                   style.border='1px solid #ddd';
                   style.background='#fff';
                   style.font='normal 12px arial';
                   style.lineHeight='20px';
                   style.margin='0';
                   style.padding='0';
                   style.overflow='hidden';
                   style.zIndex='1000';
                   document.body.insertBefore(div,document.body.firstChild);
              }
         document.write('<img src="http://wmdn.ru/images/star_icon16.png" width="16" height="16" style="border:0;margin:0;padding:0;cursor:hand;vertical-align:bottom;" onmouseover="CButton.show(this);" onmouseout="CButton.timeout=setTimeout(\'CButton.hide()\',500);">');
         }
}
CButton=new NewButton();
CButton.init();
