$(document).ready(function() {
  $(".jk_share").toggle(function(e) {
    var share_link = $(this);
    var bookmarks = $(this).siblings('.bookmarks');
    
    if (bookmarks.children().size() == 0) {
      bookmarks.html($('#bookmarks_placeholder').html());
      bookmarks.find('a').each(function() {
        $(this).attr('href', $(this).attr('href').replace('%TITLE%', bookmarks.attr('title')));
        $(this).attr('href', $(this).attr('href').replace('%URI%', share_link.attr('href')));
        $(this).attr('href', $(this).attr('href').replace('%TITLE_DECODED%', escape(bookmarks.attr('title'))));
      });
    }
    
    bookmarks.show();

    if ($(this).hasClass('top')) {
      var share_top=$(this).position().top - $(this).siblings('.bookmarks').children('ul:first').outerHeight();
      bookmarks.children('ul').css({'top': share_top+'px'});
    }
    e.preventDefault();
  },function(e) {
    $(this).siblings('.bookmarks').hide();
    e.preventDefault();
  });
});

ReTwitter = {
  username: "kea000",
  apikey: 'R_5d4161dd5990d8191edba1b4c6589b1f',
  bitlyShortenerUrl: function(url, title)
  {
    link = 'http://twitter.com/home?source=jacktech.it&status=RT%20@jackteck_it:%20';
    callback = function(json){
      for(attribute in json.results)
      {
        shortUrl = json.results[attribute].shortUrl;
      }
      //$('<a target="_new" href="'+link+title+'%20-%20'+shortUrl+'" id="sot3214">Share on Twitter</a>').appendTo('body').click();
      //obj.attr('href', link+title+'%20-%20'+shortUrl).obj.unbind('click').click(function(){return true}).click();
      window.open(link+title+'%20-%20'+shortUrl);
    }

    $.getJSON('http://api.bit.ly/shorten?version=2.0.1&longUrl='+url+'&login='+this.username+'&apiKey='+this.apikey+'&callback=?', callback);
  }
}

