/* Common setup for public content pages */

$(document).ready(function($){
    // init Masonry
    var $grid = $('.programme').masonry({
        percentPosition: true,
        gutter: '.gutter-sizer',
        columnWidth: '.grid-sizer',
        itemSelector: '.grid-item'
    });
    // layout Masonry after each image loads
    $grid.imagesLoaded().progress(function() {
       $grid.masonry('layout');
    });
});

// Belt and braces: do a final masonry layout after all images are
// definitely loaded:
$(window).load(function() {
    $('.programme').masonry('layout');
});

$(document).ready(function() {
    $("#mobile-menu-btn").click(function() {
        var toggle_el = $(this).data("toggle");
        $(toggle_el).toggleClass("open-sidebar");
        $(".black_overlay").toggleClass("active-search-bg");
    });
});

$(function() {
    $(".black_overlay").swipe({
        swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
            $(".grid").removeClass("open-sidebar");
            $(".black_overlay").removeClass("active-search-bg");
        },
        threshold: 0
    });
});

$(document).ready(function() {
    $('#navmenu > ul > li:has(ul)').addClass("has-sub");
    $('#navmenu > ul > li > a').click(function() {
        var checkElement = $(this).next();

        $('#navmenu li').removeClass('active');
        $(this).closest('li').addClass('active');

        if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            $(this).closest('li').removeClass('active');
            checkElement.slideUp('normal');
        }

        if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $('#navmenu ul ul:visible').slideUp('normal');
            checkElement.slideDown('normal');
        }

        if (checkElement.is('ul')) {
            return false;
        } else {
            return true;
        }
    });
});

@@ -74,17 +74,17 @@
 )%7B%0A    /
-/
+*
  init Ma
@@ -88,16 +88,76 @@
  Masonry
+ -------------------------------------------------------- */
 %0A    var
@@ -338,15 +338,19 @@
 %7D);%0A
+%0A
     // 
+re-
 layo
@@ -474,204 +474,88 @@
 %7D);%0A
-%7D);%0A%0A// Belt and braces: do a final masonry layout after all images are%0A// definitely loaded:%0A$(window).load(function() %7B%0A    $('.programme').masonry('layout');%0A%7D);%0A%0A$(document).ready(function() %7B
+%0A    /* set up small form factor menu --------------------------------------- */
 %0A   
@@ -767,27 +767,8 @@
 %7D);%0A
-%7D);%0A%0A$(function() %7B
 %0A   
@@ -1046,43 +1046,88 @@
 %7D);%0A
-%7D);%0A%0A$(document).ready(function() %7B
+%0A    /* Set up nav menu ----------------------------------------------------- */
 %0A   
@@ -1176,24 +1176,25 @@
 %22has-sub%22);%0A
+%0A
     $('#navm
@@ -1868,13 +1868,962 @@
 %0A    %7D);
+%0A%0A    /* Set up grid/list switcher (event list only) ------------------------- */%0A    $('a#listbtn.switcher').click(function() %7B%0A        $('.programme').animate(%7Bopacity: 0%7D,function() %7B%0A            $('.programme').hide();%0A            $('.list').addClass('active');%0A            $('.list.active').stop().animate(%7Bopacity: 1%7D);%0A        %7D);%0A    %7D);%0A%0A    $('a#gridbtn.switcher').click(function() %7B%0A        $('.list').animate(%7Bopacity:0%7D,function() %7B%0A            $('.list').removeClass('active');%0A            $('.programme').show();%0A            $('.programme').masonry(%7B%0A                gutter: '.gutter-sizer',%0A                columnWidth: '.showing-sizer',%0A                itemSelector: '.showing'%0A            %7D);%0A            $('.programme').stop().animate(%7Bopacity: 1%7D);%0A        %7D);%0A    %7D);%0A%7D);%0A%0A// Belt and braces: do a final masonry layout after all images are%0A// definitely loaded:%0A$(window).load(function() %7B%0A    $('.programme').masonry('layout');
 %0A%7D);%0A

Tidy up JS a little