$(document).ready(
  function ()
  {
    var leftBorderNormal = 4;
    var leftBorderHover = 4;
    var leftBorderSelected = 4;
    var rightBorderNormal = 18;
    var rightBorderHover = 18;
    var rightBorderSelected = 18;     
  
    $('#help, #settings').LayerButton(
      {
        'groupID':        'toolbar',
        'normal':
        {
          'imageSource':  { 'prefix': 'subnav-normal_', 'suffix': '.png' },
          'imageBorders': { 'right': rightBorderNormal, 'left': leftBorderNormal }
        },
        'hover':
        {
          'imageSource':  { 'prefix': 'subnav-hover_', 'suffix': '.png' },
          'imageBorders': { 'right': rightBorderHover, 'left': leftBorderHover }
        },
        'selected':
        {
          'imageSource':  { 'prefix': 'subnav-pressed_', 'suffix': '.png' },
          'imageBorders': { 'right': rightBorderSelected, 'left': leftBorderSelected },
          'onShow':       function (element) {
                            var elementPos    = $(element).offset();
                            elementPos.width  = $(element).width();
                            elementPos.height = $(element).height();
                            if ($(element).attr('id') != 'help')
                            {
                              // 10 for padding
                              elementPos.height += 10;
                              elementPos.width += 42; // padding
                            }
                            call('#popupmenu:' + (($(element).attr('id') == 'help') ? '3' : '1') + ':' + elementPos.left + ':' + (elementPos.top - 1) + ':' + elementPos.width + ':' + elementPos.height);
                          }
        }
      }
    );

    $('#help').mousedown(
      function (e)
      {
        if (e.button == 1)
        {
          $(this).click();
        }
      }
    ).keydown(
      function (e)
      {
        if (e.keyCode == 13)
        {
          $(this).click();
        }
      }
    );
    
    $('#settings').mousedown(
      function (e)
      {
        if (e.button == 1)
        {
          $(this).click();
        }
      }
    ).keydown(
      function (e)
      {
        if (e.keyCode == 13)
        {
          $(this).click();
        }
      }
    );
  }
);