$(function() {
    // mark "Services" link as selected
    $("a[title='Services']").parents().addClass("selected");
    if (document.body.attributes['data-picture']) {
	var sheet = document.head.appendChild(document.createElement("style")).sheet;
	sheet.insertRule('#content .topbanner-wrapper .bandeau {background-image: url("' + document.body.attributes['data-picture'].value + '"); background-repeat: no-repeat; background-size: cover;}', 0);
    };
    $('div.wcs-tracking-code-input h2').on('click', function (e) {
        $(this).parent().toggleClass('toggled');
    });
  $('div.notification a.ack').on('click', function(event) {
    var notification = $(this).parents('.notification');
    var forget_url = $(notification).data('combo-notification-forget-url');
    $.ajax({
         url: forget_url,
         success: function(html) {
           $(notification).hide({effect: 'fade', complete: function() { $(this).remove() }});
         }
    });
    return false;
  });

  $('a#publik-mobile-menu').on('click', function(e) {
      $('div#nav').toggleClass('toggled');
  });

  $(document).on('combo:cell-loaded', function(ctx, elem) {
      if ($('.menucell', elem).length > 0) {
          var menu_page_ids = $.makeArray($('[data-menu-page-id]', elem).map(function() { return $(this).data('menu-page-id'); }))
          $.ajax({url: $('body').data('api-root') + 'menu-badges/',
                  xhrFields: { withCredentials: true },
                  async: true,
                  dataType: 'json',
                  data: {'page': menu_page_ids},
                  crossDomain: true,
                  success: function(data) {
                      $(document).trigger('combo:menu-badges-loaded', data);
                  }});
      }
  });
})
