jQuery Superfish align sub-menu under main menu

jQuery Superfish align sub-menu under main menu

Hi, 

I used Superfish to display menu and submenus in horizontal style. As you know in Superfish all the submenus are left align. I want to align the sub-menus centered according to the main menu. I thought to find out the width of a sub-menus item. As in super-fish there is delay in appearance of sub-menus so I can't get the width of submenu item becuause I am using ' onShow'.

Then in superfish  onBeforeShow I cloned the item in DIV and tried to find out its width. But the problem is the width of item is different in  onBeforeShow and  onShow.  I could not figure out what I am doing wrong. 



  1.  jQuery(document).ready(function () {
  2.                
  3.                 jQuery('ul.sf-menu').superfish({
  4.                     pathClass: 'current',
  5.                     onBeforeShow: function () {
  6.                         getItem($(this), 'onBeforeShow');
  7.                     },

  8.                     onShow: function () {
  9.                         getItem($(this), 'onShow');
  10.                     }
  11.                 });
  12.                


  13.                 //Real Width of Element even if element/parents are hidden
  14.                 function getItem(item,triggerBy) {
  15.                     var lastSub = (item).closest('li').attr('id');
  16.                     var $subMenuFirstItem = $('#' + lastSub + ' li:Last');
  17.                     console.log('RealWidth: ' + $subMenuFirstItem.elementRealWidth() + ' Width: ' + $subMenuFirstItem.width() + '  Trigger: ' + triggerBy);
  18.                    
  19.                 }

  20.                 $.fn.elementRealWidth = function () {
  21.                     /*var $clone = this.clone()
  22.                         .css("visibility", "hidden")
  23.                         .appendTo($('body'));
  24.                         */
  25.                     var $clone = this.clone().appendTo($('#EmptyDummy'));
  26.                     
  27.                     var $width = $clone.children().width();
  28.                    // $clone.remove();
  29.                     return $width+' - '+this.text();
  30.                 };

  31.             });