window.onload = function() {
  //Show social bookmarks
  if ($('socialbookmarks-show') != undefined)
  {
    $('socialbookmarks-show').observe('click', function(event) {
      Event.stop(event);
  
      var element  = Event.element(event);
      var position = Position.cumulativeOffset(element);
      var left     = position[0];
      var top      = position[1] + 20;
  
      $('socialbookmarks').toggle().setStyle({
         left: left + 'px',
         top:  top + 'px'
      });
  
      Event.observe(document, 'click', function(event) {
        hideSocialBookmarks();
      });
    });
  }

  //Hide social bookmarks
  if ($('socialbookmarks-hide') != undefined)
  {
    $('socialbookmarks-hide').observe('click', function(event) {
      Event.stop(event);
      hideSocialBookmarks();
    });

    function hideSocialBookmarks() {
      $('socialbookmarks').hide();
    } 
  }

  //Show social bookmark name
  if ($('socialbookmarks-inline') != undefined)
  {
    $$('#socialbookmarks-inline a').invoke('observe', 'mouseover', function(event)
    {
      Event.stop(event);
      showSocialBookmarkTitle(this);
    });

    $$('#socialbookmarks-inline a').invoke('observe', 'mouseout', function(event)
    {
      Event.stop(event);
      hideSocialBookmarkTitle(this);
    });

    function showSocialBookmarkTitle(bookmark)
    {
      $('socialbookmarks-text').innerHTML = bookmark.title;
    }

    function hideSocialBookmarkTitle(bookmark)
    {
      text = $('socialbookmarks-text');
      if (text.innerHTML = bookmark.title)
      {
        text.innerHTML = '...';
      }
    }
  }
  
  if ($('socialbookmarks-show-bottom') != undefined)
  {
    $('socialbookmarks-show-bottom').observe('click', function(event) {
      Event.stop(event);
  
      var element  = Event.element(event);
      var position = Position.cumulativeOffset(element);
      var left     = position[0];
      var top      = position[1] + 20;
  
      $('socialbookmarks-bottom').toggle().setStyle({
         left: left + 'px',
         top:  top + 'px'
      });
  
      Event.observe(document, 'click', function(event) {
        hideSocialBookmarksBottom();
      });
    });
  }

  //Hide social bookmarks
  if ($('socialbookmarks-hide-bottom') != undefined)
  {
    $('socialbookmarks-hide-bottom').observe('click', function(event) {
      Event.stop(event);
      hideSocialBookmarksBottom();
    });

    function hideSocialBookmarksBottom() {
      $('socialbookmarks-bottom').hide();
    } 
  }

  //Show social bookmark name
  if ($('socialbookmarks-inline-bottom') != undefined)
  {
    $$('#socialbookmarks-inline-bottom a').invoke('observe', 'mouseover', function(event)
    {
      Event.stop(event);
      showSocialBookmarkTitleBottom(this);
    });

    $$('#socialbookmarks-inline-bottom a').invoke('observe', 'mouseout', function(event)
    {
      Event.stop(event);
      hideSocialBookmarkTitleBottom(this);
    });

    function showSocialBookmarkTitleBottom(bookmark)
    {
      $('socialbookmarks-text-bottom').innerHTML = bookmark.title;
    }

    function hideSocialBookmarkTitleBottom(bookmark)
    {
      text = $('socialbookmarks-text-bottom');
      if (text.innerHTML = bookmark.title)
      {
        text.innerHTML = '...';
      }
    }
  }
}

