jQuery(document).ready(function() {

  // xhtml 1.0 strict way of using target _blank
  jQuery('.nur-bookmarks a.external').attr("target", "_blank");

  // this block sets the auto vertical expand when there are more than 
  // one row of bookmarks.
  var nurBaseHeight=jQuery('.nur-bookmarks').height();
  var nurFullHeight=jQuery('.nur-bookmarks ul.socials').height();
  if (nurFullHeight>nurBaseHeight) {
    jQuery('.nur-bookmarks-expand').hover(
      function() {
        jQuery(this).animate({
            height: nurFullHeight+'px'
        }, {duration: 400, queue: false});
      },
      function() {
        jQuery(this).animate({
            height: nurBaseHeight+'px'
        }, {duration: 400, queue: false});
      }
    );
  }
  // autocentering
  if (jQuery('.nur-bookmarks-center') || jQuery('.nur-bookmarks-spaced')) {
    var nurFullWidth=jQuery('.nur-bookmarks').width();
    var nurBookmarkWidth=jQuery('.nur-bookmarks:first ul.socials li').width();
    var nurBookmarkCount=jQuery('.nur-bookmarks:first ul.socials li').length;
    var numPerRow=Math.floor(nurFullWidth/nurBookmarkWidth);
    var nurRowWidth=Math.min(numPerRow, nurBookmarkCount)*nurBookmarkWidth;
    
    if (jQuery('.nur-bookmarks-spaced').length>0) {
      var nurLeftMargin=Math.floor((nurFullWidth-nurRowWidth)/(Math.min(numPerRow, nurBookmarkCount)+1));
      jQuery('.nur-bookmarks ul.socials li').css('margin-left', nurLeftMargin+'px');
    } else if (jQuery('.nur-bookmarks-center'.length>0)) {
      var nurLeftMargin=(nurFullWidth-nurRowWidth)/2;
      jQuery('.nur-bookmarks-center').css('margin-left', nurLeftMargin+'px');
    }
    
  }
});
