jQuery(document).ready(function(){
  if (typeof VK != 'undefined'){
    
    $('div.write_vk').each(function(i,elm){
      var btn = VK.Share.button({
            type: "round",
            text: "ВКонтакте",
            url: $(elm).attr('url'),
            title: $(elm).attr('title'),
            description: $(elm).attr('message'),
            noparse: true,
            image: $(elm).attr('img') ? $(elm).attr('img') : $('link[rel="image_src"]').attr('href')
         });
         $('a#'+$(this).attr('id')+'_link:first').attr('index', VK.Share._gens.length-1);
         $(this).append($(btn));
    });
  }

  $('.vkontakte_share').click(function(event){
    _gaq.push(['_trackEvent', 'Social', 'Vkontakte_'+$(this).attr('title')]);
    VK.Share.click($(this).attr('index'), this);
    event.preventDefault();
    event.stopPropagation();
  });
  $('.twitter_share').click(function(event){
//    alert(1);
    _gaq.push(['_trackEvent', 'Social', 'Twitter_'+$(this).attr('title')]);
    event.preventDefault();
    event.stopPropagation();
    window.open($(this).attr('href'));
  });
  $('.facebook_share').click(function(event){
//    alert(1);
    _gaq.push(['_trackEvent', 'Social', 'Facebook_'+$(this).attr('title')])
    event.preventDefault();
    event.stopPropagation();
    window.open($(this).attr('href'), 'activia_facebook', 'width=565,height=350');
  });

  $('.odkl-klass-oc').click(function(event)
  {
    _gaq.push(['_trackEvent', 'Social', 'Odnoklassniki_'+$(this).attr('title')]);
    event.preventDefault();
    event.stopPropagation();
    ODKL.Share(this);
  });
  
});
