jQuery.fn.social_bookmark = function(options){
   var options = jQuery.extend({
      socn_images : 'static/js/jquery/plugin/social_bookmark/image/', /* путь к папке с изображениями соц сетей */
      t           : encodeURIComponent(document.title),
      u           : encodeURIComponent(document.location.href),
      def_img_size: '16px',
      dif_div_s_b : 'social_bookmark',
      dif_div_s_l : 'social_likeit',
      social_bm   : false,
      social_li   : false,
      sites       : 'twitter, googlebz, friendfeed, facebook, vkontakte, mail, livejournal, google, bobrdobr, memori, misterwong, yandex, ctozakladok, mblogi, liveinternet',
      sites_li    : 'facebook, vkontakte, odnoklassniki'
   },options);

   var methods = {
      // удаляем пробелы по краям текста
      trim:function( str ) {
         var charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
         var re = new RegExp('^[' + charlist + ']+|[' + charlist + ']+$', 'g');
         return str.replace(re, '');
      },
      // ссылка открывается в новом окне
      goTo:function(url) {
         window.open(url, '_blank', 'width=600,height=400,menubar=no,toolbar=no,scrollbars=yes');
      }
   };

   //адреса соц сетей
   var sitesbase = {
      twitter: '<a href="http://twitter.com/home?status=' + options.t + ' - ' + options.u + '" title="Добавить в Twitter"><img src="' + options.socn_images + 'twitter.png" alt="" /></a>',
      googlebz: '<a href="http://www.google.com/reader/link?url=' + options.u + '&title=' + options.t + '&srcURL=http://dimox.name/" title="Добавить в Google Buzz"><img src="' + options.socn_images + 'google-buzz.png" alt="" /></a>',
      friendfeed: '<a href="http://www.friendfeed.com/share?title=' + options.t + ' - ' + options.u + '" title="Добавить в FriendFeed"><img src="' + options.socn_images + 'friendfeed.png" alt="" /></a>',
      facebook: '<a href="http://www.facebook.com/sharer.php?u=' + options.u + '&amp;t=' + options.t + '" title="Поделиться в Facebook"><img src="' + options.socn_images + 'facebook.png" alt="" /></a>',
      vkontakte: '<a href="http://vkontakte.ru/share.php?url=' + options.u + '&amp;title='+ options.t +'" title="Поделиться ВКонтакте"><img src="' + options.socn_images + 'vkontakte.png" alt="" /></a>',
      mail: '<a href="http://connect.mail.ru/share?share_url=' + options.u + '" title="Поделиться в Моем Мире"><img src="' + options.socn_images + 'moy-mir.png" alt="" /></a>',
      livejournal: '<a href="http://www.livejournal.com/update.bml?event=' + options.u + '&subject=' + options.t + '" title="Опубликовать в своем блоге livejournal.com"><img src="' + options.socn_images + 'livejournal.png" alt="" /></a>',
      delicious: '<a href="http://delicious.com/save?url=' + options.u + '&title=' + options.t + '" title="Сохранить закладку в Delicious"><img src="' + options.socn_images + 'delicious.png" alt="" /></a>',
      google: '<a href="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=' + options.u + '&title=' + options.t + '" title="Сохранить закладку в Google"><img src="' + options.socn_images + 'google.png" alt="" /></a>',
      bobrdobr: '<a href="http://bobrdobr.ru/add.html?url=' + options.u + '&title=' + options.t + '" title="Забобрить"><img src="' + options.socn_images + 'bobrdobr.png" alt="" /></a>',
      memori: '<a href="http://memori.ru/link/?sm=1&u_data[url]=' + options.u + '&u_data[name]=' + options.t + '" title="Сохранить закладку в Memori.ru"><img src="' + options.socn_images + 'memori.png" alt="" /></a>',
      misterwong: '<a href="http://www.mister-wong.ru/index.php?action=addurl&bm_url=' + options.u + '&bm_description=' + options.t + '" title="Сохранить закладку в Мистер Вонг"><img src="' + options.socn_images + 'mister-wong.png" alt="" /></a>',
      yandex: '<a href="http://zakladki.yandex.ru/newlink.xml?url=' + options.u + '&name=' + options.t + '" title="Добавить в Яндекс.Закладки"><img src="' + options.socn_images + 'yaboo.png" alt="" /></a>',
      ctozakladok: '<a href="http://www.100zakladok.ru/save/?bmurl=' + options.u + '&bmtitle=' + options.t + '" title="Добавить в 100 Закладок"><img src="' + options.socn_images + '100.gif" alt="" /></a>',
      mblogi: '<a href="http://mblogi.ru/knopka/?url=' + options.u + '&title=' + options.t + '" title="Добавить в QIP Микроблоги"><img src="' + options.socn_images + 'mblogi.png" alt="" /></a>',
      liveinternet: '<a href="http://www.liveinternet.ru/journal_post.php?action=n_add&cnurl=' + options.u + '&cntitle_win==' + options.t + '" title="Добавить в liveinternet"><img src="' + options.socn_images + 'li.gif" alt="" /></a>'
   };

   var siteslibase = {
      odnoklassniki :
      '<script type="text/javascript" src="http://stg.odnoklassniki.ru/share/odkl_share.js"></script>' +
      '<link href="http://stg.odnoklassniki.ru/share/odkl_share.css" rel="stylesheet">' +
      '<div style="width: 90px; padding-rigth: 4px !important;"><a class="odkl-klass-stat" href="'+options.u+'" onclick="ODKL.Share(this);return false;" ><span>0</span></a></div>',
      facebook :
      '<div style="clear: none !important; width: 140px; margin-left: 4px;"><iframe src="http://www.facebook.com/plugins/like.php?href=' + options.u + '&amp;layout=button_count&amp;show_faces=false&amp;width=140&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:140px; height:21px;" allowTransparency="true"></iframe></div>',
      moimir :
      '<div style="clear: none ! important; width: 130px; margin-left: 4px; float: left; padding: 2px;"><a target="_blank" class="mrc__plugin_like_button" href="http://connect.mail.ru/share" data-mrc-config="{\'type\' : \'button\', \'width\' : \'130\', \'show_faces\' : \'true\'}">Нравится</a></div>' +
      '<script src="http://cdn.connect.mail.ru/js/loader.js" type="text/javascript" charset="UTF-8"></script>',
      vkontakte :
      '<div id="vk_like" style="clear:none !important; width: 140px !important;"></div><script type="text/javascript">VK.Widgets.Like("vk_like", {type: "button"});</script>'
   };

   var className = jQuery(this).attr('id') + '_cl';
   var hrefs = '';
   var cur_div;
   var curH = 0;

   return this.each(function() {
      /*Закладки*/
      if (options.social_bm === true)  {
         jQuery('<div id="' + options.dif_div_s_b + '"></id>').appendTo(jQuery(this));
         cur_div = jQuery(this).find('div#' + options.dif_div_s_b);

         options.sites = options.sites.split(',');

         for (i = 0; i < options.sites.length; i++) {
            hrefs = hrefs + sitesbase[methods.trim(options.sites[i])];
         }

         jQuery(hrefs).appendTo(cur_div);

         //Меняем размеры картинок в зависимости от настроек css
         jQuery(cur_div).find('a').find('img').css('height', options.def_img_size);
         jQuery(cur_div).find('a').find('img').css('width', options.def_img_size);

         jQuery(cur_div).css('height', jQuery(cur_div).find('a').outerHeight(true));

         if (jQuery.browser.msie)  {
            jQuery(cur_div).css('width', jQuery(cur_div).find('a').outerWidth(true) * jQuery(cur_div).find('a').length + 5);
         } else {
            jQuery(cur_div).css('width', jQuery(cur_div).find('a').outerWidth(true) * jQuery(cur_div).find('a').length);
         }
         //Изменение прозрачности при наведении
         jQuery(cur_div).find('a').css({
            opacity: 0.5
         }).hover(
            function() {
               jQuery(this).css({
                  opacity: 1
               });
            },
            function() {
               jQuery(this).css({
                  opacity: 0.5
               });
            }
            );
         hrefs = '';
         jQuery(cur_div).find('a').click(function() {
            methods.goTo(jQuery(this).attr('href'));
            return false;
         })
      }

      /*Мне нравится*/
      if (options.social_li === true)  {
         jQuery('<div id="' + options.dif_div_s_l + '"></id>').appendTo(jQuery(this));
         cur_div = jQuery(this).find('div#' + options.dif_div_s_l);

         hrefs = '';
         options.sites_li = options.sites_li.split(',');

         for (i = 0; i < options.sites_li.length; i++) {
            hrefs = hrefs + siteslibase[methods.trim(options.sites_li[i])];
         }

         jQuery(hrefs).appendTo(cur_div);

         jQuery('#' + jQuery(cur_div).attr('id') + ' > div').each( function() {
            jQuery(this).css('float', 'left').css('padding', '2px').css('clear', 'none !important');
            curH = curH + jQuery(this).outerWidth(true);
         });
         jQuery(cur_div).css('width', curH).css('height', '26px').css('clear', 'both');
      }
   });
};
