PageSourceSearch

https://www.estherschipper.com/scripts/main.js?c=6060632af&v=4a867de&g=a9b638ab8fe3e095294690bfd61a934f

js estherschipper.com collected 2026-10-02 05:09:37 UTC 594,875 bytes, 10,443 lines download raw bytes

1(function($) {
2    
3	window.cart.cart_summary.update_callback = function() {
4        if ($('#store_cart_widget').length) {
5            var original_sub_total = $('#store_cart_widget .scw_total_price_amount_with_vat').text();
6            if (original_sub_total != '' && typeof original_sub_total != 'undefined') {
7                var new_sub_total = original_sub_total.replace('.00', '');
8                $('#store_cart_widget .scw_total_price_amount_with_vat').text(new_sub_total);
9            }
10        }
11    };
12
13    window.cart.cart_summary.quick_cart_widget_open_callback = function() {
14        $('#container_outer').removeClass('scrolling-down');
15        h.accessibility.on_popup_opening('#store_quick_cart_widget', '.sqcw_item_image a:first', '#sqcw_close');
16    };
17    window.cart.cart_summary.quick_cart_widget_close_callback = function() {
18        h.accessibility.on_popup_closing();
19    };
20    window.cart.wishlist_summary.quick_wishlist_cart_widget_open_callback = function() {
21        $('#container_outer').removeClass('scrolling-down');
22        window.site.misc.init();
23        window.cart.init();
24        h.accessibility.on_popup_opening('#wishlist_quick_cart_widget', false, '#wqcw_close');
25    };
26    window.cart.wishlist_summary.quick_wishlist_cart_widget_close_callback = function() {
27        h.accessibility.on_popup_closing();
28    };
29    
30    var intervals = [];
31    
32    dev_site = document.getElementsByClassName("site-version-development-mode").length;
33
34    window.site = {
35
36        init: function() {
37            
38			window.site.device.init();
39            window.site.pageload.init();
40            window.site.setup();
41        },
42        
43        setup: function() {
44            window.site.artworks.init();
45            window.site.layout.init();
46            window.site.video.init();
47            window.site.slideshow.init();
48            window.site.scroll.init();
49            window.site.home.init();
50            window.site.overlays.init();
51            window.site.lazy_load.init();
52            window.site.artlogic_inview.init();
53            window.site.social_media.init();
54            window.site.mailing_list_form.init();
55            window.site.enquiry.init();
56            window.site.quick_enquiry.init();
57            window.site.tracking.init();
58            window.site.store.init();
59            window.site.misc.init();
60            window.site.artists.init();
61            ///window.site.exhibitions.init();
62            window.site.filters.init();
63            window.site.objectfit_polyfill.init();
64            window.site.countdown_clock.init();
65            // window.site.covid19_notification.init();
66            window.site.news.init();
67            window.site.interactive_scroller.init();
68            window.site.art_fairs_non_popup.init();
69        },
70
71
72        news: {
73            init: function(){
74                if ($('.subsection-blog-detail').length) {
75                    window.site.layout.max_height_read_more('.text');
76                }
77            },
78        },
79        
80        covid19_notification: {
81            
82            init: function () {
83                
84                var covid_19 = {
85                    time_to_wait: 2000
86                };
87                var custom_covid_19 = $('#covid_19_notification').data('covid_19-notification-settings') || {};
88                $.extend(covid_19, custom_covid_19);
89                
90                var covid_19_html = ' \
91                    <div id="covid_19_notification" data-covid_19-notification-settings="" > \
92                        <div class="inner"> \
93                            <div id="covid_19_notification_message"> \
94                                    <p>Esther Schipper is temporarily closed to the public in response to the current situation with COVID-19.</p> \
95                            </div> \
96                            <div id="covid_19_notification_accept" class="button"><a href="#">Close</a><div class="button_loader"><svg class="loader" viewBox="25 25 50 50"><circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="3" stroke-miterlimit="10"></circle></svg></div></div> \
97                        </div> \
98                    </div>';
99                // Inject html
100                $('#container').append(covid_19_html);
101                
102                $('#covid_19_notification').each(function () {
103                    var notification_cookie = h.getCookie('covid_19_notification_dismissed');
104                    if (!notification_cookie) {
105                        // Display the covid 19 notification after a set amount of time
106                        setTimeout(function () {
107                            $('#covid_19_notification').addClass('active')
108                        }, covid_19.time_to_wait)
109
110                        // Accept btn event listener
111                        $('#covid_19_notification_accept').click(function(e){
112                            window.site.covid19_notification.covid_19_notification_accept_btn_callback(e);
113                        });
114                    }
115                    else {
116                        $(this).hide();
117                    }
118                });
119            },
120
121            covid_19_notification_accept_btn_callback: function (e) {
122                h.setCookie('covid_19_notification_dismissed', '1', 365);
123                /* Display:none the banner once it's transformed off the screen 
124                    - do this instead of $.hide because it's janky */
125                $('#covid_19_notification').on('transitionend', function (te) {
126                    if (te.originalEvent.propertyName == 'transform') {
127                        $('#covid_19_notification').hide();
128                    }
129                });
130                $('#covid_19_notification').removeClass('active');
131                e.preventDefault();
132            }
133        },
134
135
136        home: {
137
138            canvas_effect_enabled: false,
139
140            init: function() {
141                window.site.home.setup();
142            },
143
144            start_slideshow_pre_init: function() {
145                
146                
147                $('#main_slideshow .slide:eq(0) video').each(function() {
148                    var video = $(this).get(0);
149                    video.currentTime = 0;
150                    video.play();
151                });
152            },
153
154            start_slideshow: function(run_pre_init) {
155    
156                window.site.cookie_notification.init();
157                
158                run_pre_init = typeof run_pre_init != 'undefined' ? run_pre_init : true;
159                $('#main_slideshow, .main_slideshow').each(function() {
160                    if (!$('#main_slideshow, .main_slideshow').hasClass('slideshow-paused-by-default')) {
161                        setTimeout(function() {
162                            $('#main_slideshow, .main_slideshow').cycle('resume');
163                        }, 100);
164                    }
165                    main_slideshow_cycle_before(false, false, false, $('#main_slideshow .slide:eq(0)'), false);
166
167                    $('body').addClass('main_slideshow_active');
168                    
169                    setTimeout(function() {
170                        if (run_pre_init) {
171                            window.site.home.start_slideshow_pre_init();
172                        }
173                        $('body').addClass('main_slideshow_animate');
174                    }, 400, run_pre_init);
175                });
176            },
177
178            setup: function() {
179
180
181                if (window.site.device.handheld_ios()) {
182                    
183                    $('.full_bleed_panel').each(function() { 
184                        var h = $(this).find('.area').height();
185                        if ($(this).find('.area_additional_scroll').length > 0) {
186                            h = h + $(this).find('.area_additional_scroll').height();
187                        }
188                        $(this).height(h).addClass('pseudo_fixed_bg');
189                    });
190
191                    var resizeTimer;
192                    var previous_width = $(window).width();
193                    
194                    $(window).on('resize', function(e) {
195                      clearTimeout(resizeTimer);
196                      resizeTimer = setTimeout(function() {
197                        if ($(window).width() != previous_width)  {
198                            $('.full_bleed_panel').each(function() { 
199                                var h = $(this).find('.area').height();
200                                if ($(this).find('.area_additional_scroll').length > 0) {
201                                    h = h + $(this).find('.area_additional_scroll').height();
202                                }
203                                $(this).height(h).addClass('pseudo_fixed_bg');
204                            });
205                        }
206                      }, 250);
207                    
208                    });
209                }
210                
211                // Slideshow init
212                $('body').removeClass('main_slideshow_active main_slideshow_animate hero-variant-dark');
213
214                $('#hero, .hero_header').each(function() {
215                    
216                    if ($('#hero.hero_text_colour_dark').length) {
217                        $('body').addClass('hero-variant-dark');
218                    }
219                    
220                    $('body').addClass('layout-hero-active')
221                    
222                    // Setup each slide (non-canvas)
223                    if ($('#main_slideshow .slide', this).length == 1) {
224                        $(this).addClass('cycle-single-slide');
225                    }
226                    
227                    // Play all the videos to force them to load
228                    $('xx#main_slideshow .slide video').each(function() {
229                        $(this).get(0).play();
230                    });
231                    
232                    if ($('#main_slideshow .slide').length > 0) {
233                        $(this).addClass('has-slideshow');
234                    }
235                    
236                    $('#main_slideshow .slide', this).each(function() {
237                        cycle_resume_timeout = false;
238                        $('.store_item').hover(function() {
239                            clearTimeout(cycle_resume_timeout);
240                            if (!$('#main_slideshow, .main_slideshow').hasClass('cycle-paused')) {
241                                $('#main_slideshow, .main_slideshow').stop().clearQueue();
242                                $('#main_slideshow, .main_slideshow').addClass('temporary-pause').cycle('pause');
243                            }
244                        }, function() {
245                            if ($('#main_slideshow, .main_slideshow').hasClass('temporary-pause')) {
246                                clearTimeout(cycle_resume_timeout);
247                                cycle_resume_timeout = setTimeout(function() {
248                                    $('#main_slideshow, .main_slideshow').removeClass('temporary-pause').cycle('resume');
249                                }, 500);
250                            }
251                        });
252
253                        if ($('a', this).length) {
254                            $('.image, .image_hover_area', this).css('cursor', 'pointer').click(function() {
255                                $(this).closest('.slide').find('a').trigger('click');
256                            });
257                        }
258                    });
259                    
260                    $('.main_slideshow_quick_nav ul li button').click(function() {
261                        main_slideshow_go_to_slide($(this).parent().attr('data-index'));
262                        return false; 
263                    });
264                    
265                    $('#main_slideshow_nav .records_list_slider').on('select.flickity', function(event, index) {
266                        if (!$('body').hasClass('resizing')) {
267                            
268                            $('#main_slideshow_nav .records_list_slider').addClass('auto-change');
269                            $(this).find('.is-selected').addClass('active');
270                            main_slideshow_go_to_slide($(this).find('.is-selected').attr('data-index'), true);
271                        }
272                    });
273                    
274                    pad_number = function(num, size) {
275                        if (String(num).length > size) {
276                            var size = String(num).length;
277                        }
278                        var s = "000000" + num;
279                        return s.substr(s.length-size);
280                    }
281
282                    main_slideshow_cycle_end = function(next_slide_index, forced) {
283                        // Change image in the canvas element
284                        if (!$('#hero, .hero_header').hasClass('cycle-single-slide')) {
285                            if (next_slide_index && typeof next_slide_index != 'undefined') {
286    
287                            } else {
288                                // assume it is the next slide
289                                next_slide_index = parseInt($('#main_slideshow .slide.cycle-slide-active').attr('data-index')) + 1;
290                                if (next_slide_index > $('#main_slideshow .slide').length) {
291                                    next_slide_index = 1;
292                                }
293                            }
294                            
295                            $('#main_slideshow_nav li, .main_slideshow_quick_nav li').removeClass('active');
296                            $('#main_slideshow_nav li[data-index="' + next_slide_index + '"]').addClass('active');
297                            $('.main_slideshow_quick_nav li[data-index="' + next_slide_index + '"]').addClass('active');
298                            $('#main_slideshow, .main_slideshow').addClass('slide-changing');
299                            //$('.cycle-slide.cycle-slide-active').find('.text_animate').textillate('out');
300                            $('#main_slideshow, .scroll-container').addClass('slide-end');
301                            $('#main_slideshow, .scroll-container').removeClass('slide-active');
302                        }
303                    }
304
305                    main_slideshow_cycle_first_slide_change = true;
306                    
307                    main_slideshow_cycle_before = function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
308                        var forced = typeof forced != 'undefined' ? forced : false;
309                        this_index = $(incomingSlideEl).attr('data-index');
310                        this_color = $(incomingSlideEl).attr('data-color') || 'light';
311                        
312                        // For hero_header.mako you can't set individual slide text colours and theres just one main override
313                        if ($('#hero .hero-inner').length && $('#hero .hero-inner').hasClass('hero_text_colour_dark')) {
314                            this_color = 'dark';
315                        }
316    
317                        $('#main_slideshow, .main_slideshow').removeClass('slide-changing');
318            
319                        $('#main_slideshow_nav li').removeClass('active');
320                        $('#main_slideshow_nav li[data-index="' + this_index + '"]').addClass('active');
321                        
322                        $('.main_slideshow_quick_nav li').removeClass('active');
323                        $('.main_slideshow_quick_nav li[data-index="' + this_index + '"]').addClass('active');
324                        
325                        $('#main_slideshow_progress .number').text(pad_number(this_index, 2));
326                        $('.main_slideshow_pagination .number').text(pad_number(this_index, 2));
327
328                        if (!$('#main_slideshow_nav .records_list_slider').hasClass('auto-change')) {
329                            $('#main_slideshow_nav .records_list_inner').flickity('select', parseInt(this_index-1));
330                        }
331                        $('#main_slideshow_nav .records_list_slider').removeClass('auto-change')
332                        
333                        if (outgoingSlideEl) {
334                            $('.text_animate', outgoingSlideEl).textillate('out');
335                        }
336                        
337                        $('#main_slideshow, .scroll-container').removeClass('slide-begin slide-begin2 slide-active');
338                        $('#main_slideshow, .scroll-container').removeClass('slide-end');
339                        $('#main_slideshow, .scroll-container').addClass('slide-reset');
340
341                        $('#main_slideshow video').each(function() {
342                            $(this).get(0).pause();
343                        });
344                        
345                        if ($('#hero, .hero_header').find('.slideshow_pager').length ){
346                            $('#hero, .hero_header').find('.slideshow_pager .slideshow-pager-item').removeClass('pager-item-active');
347                            $('#hero, .hero_header').find('.slideshow_pager .slideshow-pager-item[data-index="'+parseInt($(incomingSlideEl).attr('data-slide-index'))+'"]').addClass('pager-item-active');
348                        }
349                        
350                        // Play video
351                        if ($('video', incomingSlideEl).length) {
352                            $('video', incomingSlideEl).get(0).play();
353                        }
354                        
355                        // Note: textillate text needs to be brough in at this point because it will flicker if delayed
356                        $('.text_animate', incomingSlideEl).textillate('in');
357
358                        var slideshow_delay = 4400;
359                        if (main_slideshow_cycle_first_slide_change) {
360                            var slideshow_delay = 4000;
361                        }
362                        $('#main_slideshow, .main_slideshow')
363                            .stop().clearQueue()
364                            .animate({'display':'block'}, 10, function() {
365                                $('#main_slideshow, .scroll-container').addClass('slide-active');
366                                $('#hero, .hero_header').removeClass('hero_text_colour_light').removeClass('hero_text_colour_dark');
367                                $('body').removeClass('hero-variant-light').removeClass('hero-variant-dark');
368                                $('#hero, .hero_header').addClass('hero_text_colour_' + this_color);
369                                $('body').addClass('hero-variant-' + this_color);
370                            })
371                            .animate({'display':'block'}, 0, function() {
372                                $('#main_slideshow, .main_slideshow').addClass('slide-begin');
373                                $('#main_slideshow, .scroll-container').removeClass('slide-reset');
374                            })
375                            .animate({'display':'block'}, 10, function() {
376                                $('#main_slideshow, .main_slideshow').addClass('slide-begin2');
377                            })
378                            .animate({'display':'block'}, slideshow_delay, function() {
379                                
380                            })
381                            .animate({'display':'block'}, 2200, function() {
382                                if (!$('#main_slideshow, .main_slideshow').hasClass('cycle-paused')) {
383                                    main_slideshow_cycle_end();
384                                }
385                            })
386                        ;
387                        main_slideshow_cycle_first_slide_change = false;
388                    }
389                    
390                    main_slideshow_pause_toggle = function() {
391                        if (!$('#main_slideshow, .main_slideshow').hasClass('cycle-paused')) {
392                            $('#main_slideshow, .main_slideshow').cycle('pause');
393                            $('#main_slideshow, .main_slideshow').stop().clearQueue();
394                            $('#main_slideshow_progress').addClass('paused');
395                        } else {
396                            $('#main_slideshow, .main_slideshow').cycle('resume');
397                            main_slideshow_cycle_end();
398                            $('#main_slideshow_nav')
399                                .stop().clearQueue()
400                                .animate({'display':'block'}, 800, function() {
401                                    $('#main_slideshow, .main_slideshow').cycle('next');
402                                    $('#main_slideshow_nav').removeClass('slide-changing');
403                                })
404                            ;
405                            $('#main_slideshow_progress').removeClass('paused');
406                        }
407                        $('#main_slideshow a').focusin(function(){
408                            $('#main_slideshow, .main_slideshow').cycle('pause');
409                        });
410                    }
411                    
412                    main_slideshow_go_to_slide = function(slide_index, forced) {
413                        var forced = typeof forced != 'undefined' ? forced : false;
414                        if (slide_index && typeof slide_index != 'undefined') {
415                            if (!$('#main_slideshow .slide[data-index="' + slide_index + '"]').not('.cycle-sentinel').hasClass('cycle-slide-active')) {
416                                main_slideshow_cycle_end(slide_index, forced);
417                                $('#main_slideshow_nav li').removeClass('active');
418                                $('.main_slideshow_quick_nav li').removeClass('active');
419                                if (!forced) {
420                                    $('#main_slideshow, .main_slideshow').stop().clearQueue();
421                                    $('#main_slideshow, .main_slideshow').cycle('pause');
422                                }
423                                $('#main_slideshow_nav')
424                                    .stop().clearQueue()
425                                    .animate({'display':'block'}, 200, function() {
426                                        $('#main_slideshow, .main_slideshow').cycle(parseInt(slide_index) -1);
427                                        $('#main_slideshow_nav').removeClass('slide-changing');
428                                    })
429                                ;
430                            }
431                        }
432                    }
433
434                    main_slideshow_change_slide = function(direction) {
435
436                        if (direction == 'next') {
437                            $('#main_slideshow, .main_slideshow').stop().clearQueue();
438                            $('#main_slideshow_nav').addClass('slide-changing');
439                            next_slide_index = parseInt($('#main_slideshow .slide.cycle-slide-active').attr('data-index')) + 1;
440                            if (next_slide_index > $('#main_slideshow .slide').length) {
441                                next_slide_index = 1;
442                            }
443                            main_slideshow_cycle_end(next_slide_index);
444                            $('#main_slideshow_nav')
445                                .stop().clearQueue()
446                                .animate({'display':'block'}, 200, function() {
447                                    $('#main_slideshow, .main_slideshow').cycle('next');
448                                })
449                                .animate({'display':'block'}, 800, function() {
450                                    $('#main_slideshow_nav').removeClass('slide-changing');
451                                })
452                            ;
453                        } else if (direction == 'previous') {
454                            $('#main_slideshow, .main_slideshow').stop().clearQueue();
455                            $('#main_slideshow_nav').addClass('slide-changing');
456                            next_slide_index = $('#main_slideshow .slide.cycle-slide-active').attr('data-index') - 1;
457                            if (next_slide_index < 1) {
458                                next_slide_index = $('#main_slideshow .slide').length;
459                            }
460                            main_slideshow_cycle_end(next_slide_index);
461                            $('#main_slideshow_nav')
462                                .stop().clearQueue()
463                                .animate({'display':'block'}, 200, function() {
464                                    $('#main_slideshow, .main_slideshow').cycle('prev');
465                                })
466                                .animate({'display':'block'}, 800, function() {
467                                    $('#main_slideshow_nav').removeClass('slide-changing');
468                                })
469                            ;
470                        }
471                    }
472
473                    var cycle_timeout = 4500;
474                    cycle_timeout_type = 'standard';
475                    
476                    var cycle_settings = {
477                        fx:       'fade',
478                        speed:    800,
479                        timeout:  cycle_timeout,
480                        paused:   false,
481                        slides: '> .slide',
482                        autoHeight: 'container',
483                        swipe: true
484                    };
485                    
486                    if ($('#hero .slideshow_pager .slideshow-pager-item').length ) {
487                        $('#hero .slideshow_pager .slideshow-pager-item').unbind().click(function() {
488                            
489                            $('#hero .slideshow_pager .slideshow-pager-item').removeClass('pager-item-active');
490                            $(this).addClass('pager-item-active');
491                            $('#main_slideshow, .main_slideshow').cycle('pause');
492                            $('#main_slideshow, .main_slideshow').cycle(parseInt($(this).attr('data-index')));
493                            return false;
494                        });
495                    }
496                    
497                    $('#main_slideshow, .main_slideshow').unbind().cycle(cycle_settings);
498                    $('#main_slideshow, .main_slideshow').on('cycle-before', function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
499                        main_slideshow_cycle_before(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag);
500                    });
501                    if ($('#main_slideshow >').length == 1 || $('#main_slideshow, .main_slideshow').hasClass('cycle-paused') || $('#main_slideshow, .main_slideshow').hasClass('slideshow-paused-by-default')) {
502                        $('#main_slideshow, .main_slideshow').stop().clearQueue();
503                        $('#main_slideshow, .main_slideshow').cycle('pause');
504                        $('#main_slideshow_progress').addClass('paused');
505                    }
506                    
507                    $('#main_slideshow_pagination .prev, #hero .slideshow_pagination .prev').unbind().click(function() {
508                        $('#main_slideshow, .main_slideshow').cycle('pause');
509                        main_slideshow_change_slide('previous');
510                    });
511                    $('#main_slideshow_pagination .next, #hero .slideshow_pagination .next').unbind().click(function() {
512                        $('#main_slideshow, .main_slideshow').cycle('pause');
513                        main_slideshow_change_slide('next');
514                    });
515                    
516                    $('#main_slideshow_progress .pause').click(function() {
517                        main_slideshow_pause_toggle();
518                    });
519                    
520                    if (!$('#main_slideshow, .main_slideshow').hasClass('slideshow-paused-by-default') || ($('#main_slideshow, .main_slideshow').hasClass('slideshow-play-by-default-mobile')) && window.site.device.breakpoint() <= 2) {
521                        // Once setup, pause slideshow and wait for start_slideshow function to be called
522                        main_slideshow_pause_toggle();
523                    }
524
525                    var total_slides = $('#main_slideshow >').length;
526                    $('#main_slideshow_progress .total').text(pad_number(total_slides, 2));
527                    $('.main_slideshow_pagination .total').text(pad_number(total_slides, 2));
528
529                    $('#main_slideshow_nav li')
530                        .click(function() {
531                            $('#main_slideshow, .main_slideshow').stop().clearQueue();
532                            $('#main_slideshow, .main_slideshow').cycle('pause');
533                            slide_index = $(this).attr('data-index');
534                            if (!$(this).hasClass('active') && !$('#main_slideshow_nav').hasClass('slide-changing') && !$('body').hasClass('slider-drag')) {
535                                $('#main_slideshow_nav').addClass('slide-changing');
536                                $('#main_slideshow_nav .records_list_inner').flickity('select', parseInt(slide_index-1));
537                                main_slideshow_go_to_slide(slide_index);
538                                
539                                if ($(window).scrollTop() > $(window).height() / 2) {
540                                    window.site.commands.scrollto(0);
541                                }  
542                            } else {
543                                var related_slide_link = $('#main_slideshow .slide[data-index="' + slide_index + '"] a:eq(0)');
544                                if (related_slide_link.length) {
545                                    $.pageload.load(related_slide_link.attr('href'), true);
546                                }
547                            }
548                        })
549                    ;
550                    $("#main_slideshow_nav li .content").focusin(function(){
551                        var slide_index = $(this).closest('li').attr('data-index');
552                        main_slideshow_go_to_slide(slide_index);
553                    });
554                    
555                    $("#main_slideshow_nav li .content").keydown(function(e) {
556                        var slide_index = $(this).closest('li').attr('data-index');
557                        var related_slide_link = $('#main_slideshow .slide[data-index="' + slide_index + '"] a:eq(0)');
558                        if (e.which == 13){
559                            if (related_slide_link.length) {
560                                $.pageload.load(related_slide_link.attr('href'), true);
561                            }
562                        }
563                    });
564
565                    $(document).keydown(function(e) {
566                        if (e.which == 38 && $('#main_slideshow .cycle-slide-active a').is(":focus")) {
567                            // Up
568                            main_slideshow_change_slide('previous');
569                            e.preventDefault(); // prevent the default action (scroll)
570                            setTimeout(function(){
571                                $('#main_slideshow .cycle-slide-active a')[0].focus()
572                            }, 1000);
573                        } else if (e.which == 40 && $('#main_slideshow a').is(":focus")) {
574                            // Down
575                            main_slideshow_change_slide('next');
576                            e.preventDefault(); // prevent the default action (scroll)
577                            setTimeout(function(){
578                                $('#main_slideshow .cycle-slide-active a')[0].focus()
579                            }, 1000);
580                        }
581                    });
582
583                    if ($('body').hasClass('first-load-complete')) {
584                        window.site.home.start_slideshow();
585                    }
586                });
587            }
588        },
589
590        slideshow: {
591
592            init: function() {
593                window.site.slideshow.header();
594                window.site.slideshow.cascading();
595                window.site.slideshow.slider.init();
596            },
597
598            slider: {
599                
600                adjacent_captions: function(instance) {
601                    
602                    // Only enabled for the store slider atm
603                    if ($(instance).closest('section').hasClass('store_featured_slider')) {
604                        
605                        $('.list_caption_wrapper', instance).css('min-height', '');
606                        
607    				    tallest_content = 0;
608    				    items = $(instance).find('.item')
609    				    
610                        items.each(function(){
611                            if ($(this).find('.list_caption_wrapper').outerHeight() > tallest_content) {
612        					    tallest_content = $(this).find('.list_caption_wrapper').outerHeight();
613        					}
614                        }).promise().done(function() {
615    					    $(instance).find('.item .list_caption_wrapper').each(function() {
616    					        $(this).css('min-height', tallest_content);
617    					    });
618    					});
619                    }
620                },
621                
622                image_sizes: function(instance) {   
623				    
624                    $(instance).find('.item').each(function(){
625                
626                        var current_height = $(this).height();
627                        var ratio_width = $(this).find('.image').attr('data-width');
628                        var ratio_height = $(this).find('.image').attr('data-height');
629                        
630                        if (current_height > 0 && ratio_width && ratio_height) {
631                            var new_width = 0;
632                            var ratio = (ratio_height / current_height);
633                            var new_width = ratio_width / ratio;
634                            if (new_width > 0 && new_width < $(instance).width()) {
635                                // $(this).find('.image').css('width', new_width + 'px');
636                                $(this).css('width', new_width + 'px');
637                            } else {
638                                // $(this).find('.image').css('width', $(instance).width() + 'px');
639                                $(this).css('width', $(instance).width() + 'px');
640                            }
641                        }
642                        
643                    });
644                    
645                } ,  
646                
647                init: function() {
648                    
649                    // Clear any previous intervals
650                    intervals.forEach(clearInterval);
651                    intervals = [];
652                    
653                    $('.records_list_slider, .full_grid_slider').each(function() {
654
655                        var $slider_outer = $(this);
656                        var instance = $(this).find('.records_list_inner');
657                        var slider_infinite = $(this).hasClass('slider_infinite');
658                        var slider_cellalign = $(this).hasClass('slider_center') ? 'center' : 'left';
659                        var slider_draggable = $(this).hasClass('slider_drag_disabled') ? false : true;
660                        var slider_freescroll = $(this).hasClass('slider_freescroll_enabled') ? true : false;
661                        var lazyload_amount = 3;
662                        var groupCells = 'auto';
663                        
664                        if ($(instance).find('.item').length) {
665
666                            // $(instance).find('.item').each(function(){
667                            //     if ($(this).find('.image').length) {
668                            //         var current_height = $(this).find('.image').height();
669                            //     } else {
670                            //         var current_height = $(this).height();
671                            //     }
672                            //     var ratio_width = $(this).find('.image').attr('data-width');
673                            //     var ratio_height = $(this).find('.image').attr('data-height');
674                            //     if (current_height > 0 && ratio_width && ratio_height) {
675                            //         var new_width = 0;
676                            //         var ratio = (ratio_height / current_height);
677                            //         var new_width = ratio_width / ratio;
678                            //         if (new_width > 0 ) {
679                            //             $(this).find('.image').css('min-width', new_width + 'px');
680                            //         }
681                            //     }
682                            // });
683
684                          if ($slider_outer.hasClass('fullwidth_image_slider') || $slider_outer.hasClass('related_content_slider')) {
685                                var groupCells = false;
686                                slider_infinite = true;
687                                slider_cellalign = 'center';
688                                
689                                window.site.slideshow.slider.image_sizes(instance);
690                                
691                                var resizeTimer;
692                                var previous_width = $(window).width();
693                                
694                                $(window).on('resize', function(e) {
695                                    
696                                  clearTimeout(resizeTimer);
697                                  resizeTimer = setTimeout(function() {
698                                    
699                                    if ($(window).width() != previous_width)  {
700                                        
701                                        window.site.slideshow.slider.image_sizes(instance);
702                                        instance.flickity('reposition')   
703                                    }
704                                  }, 250);
705                                });
706                            }
707                            
708                            var resizeTimer2;
709                            var previous_width = $(window).width();
710                            
711                            window.site.slideshow.slider.adjacent_captions(instance);
712                            setTimeout(function() {
713                                window.site.slideshow.slider.adjacent_captions(instance);
714                            }, 400, instance);
715                            
716                            $(window).on('resize', function(e) {
717                              clearTimeout(resizeTimer2);
718                              resizeTimer2 = setTimeout(function() {
719                                if ($(window).width() != previous_width)  {
720                                    if ($(instance).find('.item .image').height() > 100) {
721                                        $(instance).closest('.records_list_slider').find('.pagination_controls button').css('top', $(instance).find('.item .image').height()/2 + 'px');
722                                    } else {
723                                        $(instance).closest('.records_list_slider').find('.pagination_controls button').css('top', '');
724                                    }
725                                    window.site.slideshow.slider.adjacent_captions(instance);
726                                }
727                              }, 250);
728                            });
729                            if ($(instance).find('.item .image').height() > 100) {
730                                $(instance).closest('.records_list_slider').find('.pagination_controls button').css('top', $(instance).find('.item .image').height()/2 + 'px');
731                            } else {
732                                $(instance).closest('.records_list_slider').find('.pagination_controls button').css('top', '');
733                            }
734
735                            $(instance).flickity({
736                                cellAlign: slider_cellalign,
737                                resize: true,
738                                prevNextButtons: false,
739                                groupCells: groupCells,
740                                draggable: slider_draggable,
741                                freeScroll: slider_freescroll,
742                                pageDots: false,
743                                contain: true,
744                                wrapAround: slider_infinite,
745                                imagesLoaded: true, //required for height on first load
746                                adaptiveHeight: false, //Change height on each slide change
747                                lazyLoad: lazyload_amount,
748                                setGallerySize: true //Auto set the slideshow height
749                            });
750
751                            var flkty = $(instance).data('flickity');
752                            var item_count = $(instance).find('.item').length;
753                            if ($(instance).find('.item').length > 1) {
754                                // The second item is more reliable - the first can be hidden depending on the layout
755                                var item_width = Math.floor($(instance).find('.item:eq(1)')[0].getBoundingClientRect().width);
756                            } else {
757                                var item_width = Math.floor($(instance).find('.item:eq(0)')[0].getBoundingClientRect().width);
758                            }
759                            var instance_width = $(instance).width();
760                            var items_per_group = instance_width / item_width;
761                            
762                            // If there are not enough items to be scrolled, disable pagination and unbind the drag
763                            if (items_per_group && !slider_infinite) {
764                                if ((flkty.cells.length - ($(instance).find('.item:eq(0)').width() == 0 ? 1 : 0)) <= items_per_group) {
765                                     flkty.unbindDrag();
766                                     $(instance).closest('.records_list_slider').addClass('slider_disabled');
767                                     $(instance).closest('.panel_type_records_slider').addClass('slider_disabled');
768                                 }
769                             }
770
771                            // Initialise controls
772                            $(this).closest('.records_list_slider_wrapper').find('.pagination_controls > button').unbind('click.pagination_controls').bind('click.pagination_controls', function() {
773                                if ($(this).hasClass('pagination_controls_prev')) {
774                                    $(this).closest('.records_list_slider, .panel_type_records_slider, .records_list_slider_wrapper').find('.records_list_inner').flickity('previous');
775                                    $(instance).trigger('dragEnd');
776                                } else if ($(this).hasClass('pagination_controls_next')) {
777                                    $(this).closest('.records_list_slider, .panel_type_records_slider, .records_list_slider_wrapper').find('.records_list_inner').flickity('next');
778                                    $(instance).trigger('dragEnd');
779                                }
780                            });
781                            
782                            if ($slider_outer.find('.progress-bar-wrapper').length) {
783                                if (flkty.slides.length == 1) {
784                                    $slider_outer.find('.slider_footer').hide();
785                                } else {
786                                    $slider_outer.find('.slider_footer').show();
787                                    var initialProgressBar = $slider_outer.find('.progress-bar-initial')[0];
788                                    var initial_progress = (1 / flkty.slides.length);
789                                    initialProgressBar.style.width = initial_progress * 100 + '%';
790                                    flkty.on( 'scroll', function( progress ) {
791                                        progress = Math.max( 0, Math.min( 1, progress ) );
792                                        initial_progress = (1 / flkty.slides.length);
793                                        initialProgressBar.style.width = initial_progress * 100 + '%';
794                                        $slider_outer.find('.progress-bar-inner').css('transform', 'scaleX(' + progress + ')');
795                                    });
796                                }
797                            }
798                            
799                            // Year filters reveal button
800                            $slider_outer.parent().find('.slider_year_filter_btn').off().on('click', function (e) {
801                                if ($(this).hasClass('active')) {
802                                    $slider_outer.parent().find('.slider_filter_years_container').slideUp();
803                                    $(this).removeClass('active');
804                                    $('.plus-icon-container', this).removeClass('closed');
805                                } else {
806                                    $slider_outer.parent().find('.slider_filter_years_container').slideDown();
807                                    $(this).addClass('active');
808                                    $('.plus-icon-container', this).addClass('closed');
809                                }
810                            });
811                            
812                            // Basic exhibitions year filter for carousels
813                            $slider_outer.parent().find('.filter_year_option').off().on('click', function (e) {
814                                
815                                if ($(this).hasClass('active') ) {
816                                    $(this).removeClass('active');
817                                    $('.item', instance).removeClass('selected_by_filter').show();
818                                } else {
819                                    $('.item', instance).removeClass('selected_by_filter').show();
820                                    var filter_year = $(this).attr('data-filter-year');
821                                    $('.item[data-filter-year="' + filter_year + '"]', instance).addClass('selected_by_filter');
822                                    $('.item:not(.selected_by_filter)', instance).hide();
823                                    
824                                    $slider_outer.parent().find('.filter_year_option').removeClass('active');
825                                    $(this).addClass('active');
826                                }
827                                
828                                // If there are not enough items to be scrolled, disable pagination and unbind the drag, otherwise enable them
829                                var visible_slides_count = $('.item:visible', instance).length;
830                                if (items_per_group && visible_slides_count && !slider_infinite) {
831                                    if ((visible_slides_count - ($(instance).find('.item:eq(0)').width() == 0 ? 1 : 0)) <= items_per_group) {
832                                        flkty.unbindDrag();
833                                        $(instance).closest('.records_list_slider').addClass('slider_disabled');
834                                        $(instance).closest('.panel_type_records_slider').addClass('slider_disabled');
835                                    } else {
836                                        $(instance).closest('.records_list_slider').removeClass('slider_disabled');
837                                        $(instance).closest('.panel_type_records_slider').removeClass('slider_disabled');
838                                        flkty.options.draggable = true;
839                                        flkty.updateDraggable();
840                                    }
841                                }
842                                
843                                // Scroll to first slide and reposition slides to adjust for hidden ones
844                                instance.flickity('reposition');
845                                instance.flickity( 'selectCell', 0);
846                                
847                                // Reset the slide counter
848                                var $progress_bar_counter = $(instance).parent().find('.progress-bar-counter');
849                                if (flkty.slides.length == 1) {
850                                    $slider_outer.find('.slider_footer').hide();
851                                } else {
852                                    $slider_outer.find('.slider_footer').show();
853                                    var progress_bar_counter_text = (flkty.selectedIndex + 1) + '/' + flkty.slides.length;
854                                    $progress_bar_counter.text(progress_bar_counter_text);
855                                }
856                            });
857                            
858                            
859                            // Full grid slider pagination
860                            if ($('.slider_footer_pagination', $slider_outer).length) {
861                                
862                                $('.slider_footer_pagination button', $slider_outer).click(function(){
863                                    var $list_element = $(this).parent();
864                                    $('.slider_footer_pagination li', $slider_outer).removeClass('active');
865                                    $list_element.addClass('active');
866                                    var slide_index = $list_element.index()
867                                    $(instance).flickity( 'select', slide_index );
868                                    isPause = true;
869                                    
870                                    $('.slider_footer_pagination li .fg-progress-bar-line', $slider_outer).css("transform", "").removeClass('clicked_element');
871                                    $('.slider_footer_pagination li.active .fg-progress-bar-line', $slider_outer).addClass('clicked_element')
872                                });
873                                
874                                // Compact layout initial caption
875                                function compact_layout_caption() {
876                                    
877                                    // Make sure the div is empty (important for resize events)
878                                    $('.compact_layout_caption', $slider_outer).html('');
879                                    
880                                    var $caption_clone = $('.slider_footer_pagination li', $slider_outer).eq(0).children().clone()
881                                    $caption_clone = $caption_clone.wrap('<div class="inview_element ani-group"></div>').parent();
882                                    $('.compact_layout_caption', $slider_outer).html($caption_clone);
883                                }
884                                
885                                if ($('.slider_footer_pagination', $slider_outer).hasClass('compact')) {
886                                    compact_layout_caption();
887                                } else if ($('.slider_footer_pagination li', $slider_outer).length > 1) {
888                                    
889                                    // Switch to compact layout for smaller screen sizes when the layout isn;t already compact
890                                    
891                                    $(window).resize(function() {
892                                        
893                                        if (!$('.compact_layout_caption .full-grid-progress-bar', $slider_outer).length && $(window).width() <= 1023) {
894                                            
895                                            // Add necessary styling classes for compact layout
896                                            $('.slider_footer_pagination', $slider_outer).addClass('compact')
897                                            $('.slider_footer_pagination > ul', $slider_outer).addClass('compact_layout');
898                                            
899                                            // Add compact layout captions
900                                            compact_layout_caption();
901                                            
902                                            // Trigger click on first slide to reset caption order which is necessary when switching to compact layout
903                                            setTimeout(function() {
904                                                $('.slider_footer_pagination li:first-child button', $slider_outer).click();
905                                            }, 100, instance);
906                                            
907                                        } else if ($('.compact_layout_caption .full-grid-progress-bar', $slider_outer).length && $(window).width() > 1023) {
908                                            
909                                            // Remove classes used for styling compact layout
910                                            $('.slider_footer_pagination', $slider_outer).removeClass('compact')
911                                            $('.slider_footer_pagination > ul', $slider_outer).removeClass('compact_layout');
912                                            
913                                            // Clear caption contents
914                                            $('.compact_layout_caption', $slider_outer).html('');
915                                        }
916                                    });
917                                    
918                                }
919                                
920                                $(instance).on( 'change.flickity', function( event, index ) {
921                                    
922                                    // Update active states on active pagination buttons
923                                    $('.slider_footer_pagination li', $slider_outer).removeClass('active');
924                                    $('.slider_footer_pagination li', $slider_outer).eq(index).addClass('active');
925                                    
926                                    // Compact layout caption on change
927                                    if ($('.slider_footer_pagination', $slider_outer).hasClass('compact')) {
928                                        
929                                        // Clone active caption from caption list
930                                        var $caption_clone = $('.slider_footer_pagination li', $slider_outer).eq(index).children().clone()
931                                        
932                                        // Fade out existing caption
933                                        $('.compact_layout_caption', $slider_outer).removeClass('visible');
934                                        
935                                        // Insert the new caption once the old caption has faded out
936                                        setTimeout(function() {
937                                            $('.compact_layout_caption', $slider_outer).html($caption_clone);
938                                        }, 400, instance);
939                                        
940                                        // Add visible class to fade new caption in
941                                        setTimeout(function() {
942                                            $('.compact_layout_caption', $slider_outer).addClass('visible');
943                                        }, 500, instance);
944                                    }
945                                });
946                                
947                                var tick,
948                                    percentTime,
949                                    isPause
950                                var time = 4;
951                                
952                                $('.records_list_inner .item .video_placeholder, .re
952cords_list_inner .item a', $slider_outer).click(function(){
953                                    isPause = true;
954                                    $('.slider_footer_pagination li .fg-progress-bar-line', $slider_outer).css("transform", "").removeClass('clicked_element');
955                                    $('.slider_footer_pagination li.active .fg-progress-bar-line', $slider_outer).addClass('clicked_element')
956                                    
957                                });
958                                
959                                function startProgressbar() {
960                                    if (flkty.cells.length > 1) {
961                                        resetProgressbar();
962                                        percentTime = 0;
963                                        isPause = false;
964                                        tick = setInterval(interval, 10);
965                                        intervals.push(tick);
966                                    }
967                                }
968                                
969                                function interval() {
970                                    if ( isPause === false ) {
971                                        percentTime += 1 / (time + 0.1) ;
972                                        $('.slider_footer_pagination li.active .fg-progress-bar-line', $slider_outer).css("transform", ("scaleX(" + (percentTime/100) + ")"));
973                                        if ( percentTime >= 100 ) {
974                                            $(instance).flickity('next', true);
975                                            startProgressbar();
976                                        }
977                                    }
978                                }
979                                
980                                function resetProgressbar() {
981                                    $('.slider_footer_pagination li .fg-progress-bar-line', $slider_outer).css("transform", "scaleX(0)");
982                                    clearInterval(tick);
983                                }
984                                
985                                startProgressbar();
986                            }
987                            
988                            // Event on start of drag
989                            $(instance).on('dragStart.flickity', function() {
990                                $('body').addClass('slider-drag');
991                            });
992                            
993                            // Event on end of drag
994                            $(instance).on('dragEnd.flickity', function() {
995                                
996                                // Removed - Not sure why it was added here but it was causing the heights to increase on dragEnd
997                                // window.site.slideshow.slider.adjacent_captions(instance);
998                                
999                                // Disable any playing video
1000                                $(instance).closest('.records_list_slider').find('.video_wrapper').removeClass('show_video');
1001                                
1002                                // Find the tallest slide in the current set and scale slider height to this height
1003                                tallest_item = 0;
1004                                
1005                                var item_count = $(instance).find('.item').length;
1006                                if ($(instance).find('.item').length > 1) {
1007                                    // The second item is more reliable - the first can be hidden depending on the layout
1008                                    var item_width = Math.floor($(instance).find('.item:eq(1)')[0].getBoundingClientRect().width);
1009                                } else {
1010                                    var item_width = Math.floor($(instance).find('.item:eq(0)')[0].getBoundingClientRect().width);
1011                                }
1012                                var instance_width = $(instance).width();
1013                                var items_per_group = Math.ceil(instance_width / item_width);
1014                                if (items_per_group == 0) {
1015                                    items_per_group = 1;
1016                                }
1017                                var items_in_viewport = $(instance).find('.item.is-selected').nextAll().andSelf().slice(0, items_per_group);
1018                                var additional_items_in_viewport = {};
1019                                
1020                                var current_index = $(instance).find('.item.is-selected').index();
1021                                
1022                                if (!slider_infinite) {
1023                                    if (current_index == 0) {
1024                                         $(instance).closest('.panel_type_records_slider, .records_list_slider_wrapper').addClass('slider_first');
1025                                         $(instance).closest('.records_list_slider').addClass('slider_first');
1026                                         $(instance).closest('.area_wrapper').find('.pagination_controls_prev').prop("disabled", true);
1027                                    } else {
1028                                         $(instance).closest('.panel_type_records_slider, .records_list_slider_wrapper').removeClass('slider_first');
1029                                         $(instance).closest('.records_list_slider').removeClass('slider_first');
1030                                         $(instance).closest('.area_wrapper').find('.pagination_controls_prev').prop("disabled", false);
1031                                    }
1032                                    if (current_index >= item_count-items_per_group) {
1033                                        $(instance).closest('.panel_type_records_slider, .records_list_slider_wrapper').addClass('slider_last');
1034                                         $(instance).closest('.records_list_slider').addClass('slider_last');
1035                                        $(instance).closest('.area_wrapper').find('.pagination_controls_next').prop("disabled", true);
1036                                    } else {
1037                                        $(instance).closest('.panel_type_records_slider, .records_list_slider_wrapper').removeClass('slider_last');
1038                                         $(instance).closest('.records_list_slider').removeClass('slider_last');
1039                                        $(instance).closest('.area_wrapper').find('.pagination_controls_next').prop("disabled", false);
1040                                    }
1041                                }
1042                                
1043                                if ($(instance).closest('.records_list_slider').hasClass('slider_infinite')) {
1044                                    // In an infinite slideshow, the end of the slider will include images from the beginning of the list
1045                                    // This means we need to check the height of the items at the beginning of the list.
1046                                    // Work out the deficit of items in the existing selector then add the items from the beginning of the slider to the end.
1047                                    if (items_in_viewport.length < items_per_group) {
1048                                        var item_deficit = (items_per_group - items_in_viewport.length);
1049                                        var additional_items_in_viewport = $(instance).find('.item').slice(0, item_deficit);
1050                                        if (additional_items_in_viewport.length) {
1051                                            var items_in_viewport = $(items_in_viewport).add(additional_items_in_viewport);
1052                                        }
1053                                    }
1054                                }
1055                            });
1056
1057                            // Event when slider stops moving completely
1058                            $(instance).on('settle.flickity', function() {
1059                                $('body').removeClass('slider-drag');
1060                                window.site.slideshow.slider.after_change($(this));
1061                            });
1062
1063                            // Event on a new slide being moved into view
1064                            $(instance).on('select.flickity', function() {
1065                                
1066                                var flkty = $(this).data('flickity');
1067                                var target = flkty.selectedCell.target;
1068                                var caption = $(flkty.selectedCell.element).attr('data-caption');
1069                                $(this).closest('.records_list_slider').find('.records_list_slider_caption').html('');
1070                                if (caption && typeof caption != 'undefined') {
1071                                    $(this).closest('.records_list_slider').find('.records_list_slider_caption').html(caption);
1072                                    window.site.overlays.enquire.setup();
1073                                    $.pageload.refresh('.records_list_slider_caption');
1074                                }
1075                                $(this).closest('.records_list_slider').find('.records_list_slider_caption > .image_caption_container > .image_caption').each(function() {
1076                                    window.site.layout.max_height_read_more(this, 4);
1077                                });
1078                                
1079                                window.site.slideshow.slider.after_change($(this));
1080                                
1081                            });
1082                            
1083                            // Allow horizontal scrolling with mousewheel
1084                            $(instance).wheel(function(e) {
1085                                var instance = $(this).closest('.panel_type_records_slider').find('.records_list_inner');
1086                                if ($('#container_outer').hasClass('not-scrolling')) {
1087                                    if (e.deltaX > 5) {
1088                                        if (!instance.hasClass('wheel-drag')) {
1089                                            instance.addClass('wheel-drag');
1090                                            instance.flickity('next').trigger('dragEnd');
1091                                            setTimeout(function() {
1092                                                instance.removeClass('wheel-drag');
1093                                            }, 800, instance);
1094                                        }
1095                                    } else if (e.deltaX < -5) {
1096                                        if (!instance.hasClass('wheel-drag')) {
1097                                            instance.addClass('wheel-drag');
1098                                            instance.flickity('previous').trigger('dragEnd');
1099                                            setTimeout(function() {
1100                                                instance.removeClass('wheel-drag');
1101                                            }, 800, instance);
1102                                        }
1103                                    }
1104                                }
1105                            });
1106
1107                            // Fire events once initially to make sure processes have been run on the initial view before a transition has been made
1108                            $(instance).trigger('dragEnd.flickity');
1109                            window.site.slideshow.slider.after_change($(instance), true);
1110                        }
1111
1112
1113                    });
1114
1115                    $('.records_list_slider.feature_list_slider .item').each(function() {
1116                        if ($('.content', this).index() == 0) {
1117                            $('.content', this).addClass('responsive-hidden');
1118                            $(this).append('<div class="content responsive-only">' + $('.content', this).html() + '</div>');
1119                        }
1120                    });
1121                },
1122                
1123                after_change: function(instance, forced) {
1124                    var $instance = $(instance);
1125                    var flkty = $instance.data('flickity');
1126                    var target = flkty.selectedCell.target;
1127                    
1128                    // Add the slide count numbers
1129                    var $progress_bar_counter = $instance.parent().find('.progress-bar-counter');
1130                    var progress_bar_counter_text = (flkty.selectedIndex + 1) + '/' + flkty.slides.length;
1131                    $progress_bar_counter.text(progress_bar_counter_text);
1132                    
1133                    if (false) {
1134            			// Get tallest height *in viewport* and apply to all items
1135        				tallest_height = -1;
1136    	        		$('.item.visible .image', instance).each(function() {
1137        				    $(this).css('height', '');
1138    						tallest_height = tallest_height < parseInt($(this).attr('data-proportional-height')) ? parseInt($(this).attr('data-proportional-height')) : tallest_height;
1139        				});
1140        				$('.item .image', instance).each(function() {
1141        				    $(this).css('height', tallest_height + 'px');
1142        				});
1143                    }
1144    				
1145                    if (false) {
1146                        // Not relevant because slider is continuous
1147                        if (!$(instance).closest('.records_list_slider').hasClass('slider_infinite')) {
1148                            if (target == flkty.cells[0].target) {
1149                                $(instance).closest('.records_list_slider').find('.pagination_controls .pagination_controls_prev').addClass('disabled');
1150                            } else if (target == flkty.getLastCell().target) {
1151                                $(instance).closest('.records_list_slider').find('.pagination_controls .pagination_controls_next').addClass('disabled');
1152                            } else {
1153                                // both buttons enabled
1154                                $(instance).closest('.records_list_slider').find('.pagination_controls .pagination_controls_prev').removeClass('disabled');
1155                                $(instance).closest('.records_list_slider').find('.pagination_controls .pagination_controls_next').removeClass('disabled');
1156                            }
1157                        }
1158                    }
1159                }
1160                
1161            },
1162
1163            header: function() {
1164                $('.full_feature_slideshow').each(function() {
1165                    if ($(this).find('> .item').length == 1) {
1166                        $(this).addClass('single-slide');
1167                    }
1168                    var mastersettings = {
1169                        fx:     'fade',
1170                        speed:    600,
1171                        timeout:  6000,
1172                        pause:   0,
1173                        slides: '> .item',
1174                        autoHeight: 'calc',
1175                        swipe: true
1176                    }
1177                    $(this).cycle(mastersettings);
1178                    $('.pagination_controls .pagination_controls_prev', this).unbind().bind('click', function() {
1179                        $(this).closest('.content_slideshow').cycle('pause').cycle('prev');
1180                        return false;
1181                    });
1182                    $('.pagination_controls .pagination_controls_next', this).unbind().bind('click', function() {
1183                        $(this).closest('.content_slideshow').cycle('pause').cycle('next');
1184                        return false;
1185                    });
1186                    if ($(this).hasClass('content_slideshow_paused')) {
1187                        $(this).cycle('pause');
1188                    }
1189                    
1190                    $('.full_feature_slideshow_pagination .prev').click(function() {
1191                        $(this).closest('.full_feature_slideshow').cycle('pause');
1192                        $(this).closest('.full_feature_slideshow').cycle('prev');
1193                    });
1194                    $('.full_feature_slideshow_pagination .next').click(function() {
1195                        $(this).closest('.full_feature_slideshow').cycle('pause');
1196                        $(this).closest('.full_feature_slideshow').cycle('next');
1197                    });
1198                });
1199                
1200                if ($('.full_feature_slideshow').length) {
1201                    $(document).one( 'keyup', function(e) {
1202                        if ( e.which == 9 && !e.target.form) {
1203                            $('.full_feature_slideshow').each(function() {
1204                                $(this).cycle('pause');
1205                            });
1206                        }
1207                    });
1208                }
1209            },
1210
1211            cascading: function() {
1212                $('.content_slideshow').each(function() {
1213                    
1214                    var $slideshow = $(this);
1215                    var slideshow = this;
1216                    
1217                    if ($(this).find('> .item').length == 1) {
1218                        $(this).addClass('single-slide');
1219                    }
1220                    var mastersettings = {
1221                        fx:     'fade',
1222                        speed:    500,
1223                        timeout:  1000,
1224                        pause:   0,
1225                        slides: '> .item',
1226                        autoHeight: 'calc',
1227                        swipe: true
1228                    }
1229                    $(this).cycle(mastersettings);
1230                    $('.pagination_controls .pagination_controls_prev', this).unbind().bind('click', function() {
1231                        $(this).closest('.content_slideshow').cycle('pause').cycle('prev');
1232                        return false;
1233                    });
1234                    $('.pagination_controls .pagination_controls_next', slideshow).unbind().bind('click', function() {
1235                        $(this).closest('.content_slideshow').cycle('pause').cycle('next');
1236                        return false;
1237                    });
1238                    if ($(this).hasClass('content_slideshow_paused')) {
1239                        $(this).cycle('pause');
1240                    }
1241                    
1242                   if ($('.slideshow_pager .slideshow-pager-item', slideshow).length ) {
1243                        $('.slideshow_pager .slideshow-pager-item', slideshow).unbind().click(function() {
1244                            
1245                            $('.slideshow_pager .slideshow-pager-item', slideshow).removeClass('pager-item-active');
1246                            $(this).addClass('pager-item-active');
1247                            $slideshow.cycle(parseInt($(this).attr('data-index')));
1248                            return false;
1249                        });
1250                   }
1251                   
1252                    $slideshow.on('cycle-before', function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
1253                        $('.area_inner', incomingSlideEl).addClass('block-entrance-animations');
1254                        // console.log($(incomingSlideEl).attr('data-slide-index'));
1255                        $slideshow.find('.slideshow_pager .slideshow-pager-item').removeClass('pager-item-active');
1256                        $slideshow.find('.slideshow_pager .slideshow-pager-item[data-index="'+parseInt($(incomingSlideEl).attr('data-sli
1256de-index'))+'"]').addClass('pager-item-active');
1257                    });
1258
1259                    $slideshow.on('cycle-after', function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
1260                     
1261                        $('.area_inner', slideshow).removeClass('block-entrance-animations');
1262                      
1263                    });
1264                });
1265                
1266                
1267                $('.introduction_slideshow').each(function() {
1268                    
1269                    var $slideshow = $(this);
1270                    var slideshow = this;
1271                    var $slideshow_pager = $slideshow.closest('.aside').find('.slideshow_pager');
1272                    
1273                    if ($(this).find('> .item').length == 1) {
1274                        $(this).addClass('single-slide');
1275                    }
1276                    var mastersettings = {
1277                        fx:     'fade',
1278                        speed:    500,
1279                        timeout:  3500,
1280                        pause:   0,
1281                        slides: '> .item',
1282                        autoHeight: 'calc',
1283                        swipe: true
1284                    }
1285                    $(this).cycle(mastersettings);
1286                    
1287                    $('.previous_slide_button', $slideshow.parent()).unbind().bind('click', function() {
1288                        $slideshow.cycle('pause').cycle('prev');
1289                        return false;
1290                    });
1291                    $('.next_slide_button', $slideshow.parent()).unbind().bind('click', function() {
1292                        $slideshow.cycle('pause').cycle('next');
1293                        return false;
1294                    });
1295                    
1296                    if ($(this).hasClass('introduction_slideshow_paused')) {
1297                        $(this).cycle('pause');
1298                    }
1299                    
1300                    $('.introduction_slideshow_caption.truncated-image-caption').each(function() {
1301                        window.site.layout.max_height_read_more(this, 4);
1302                    });
1303                    
1304                   if ($('.slideshow-pager-item', $slideshow_pager).length ) {
1305                        $('.slideshow-pager-item', $slideshow_pager).unbind().click(function() {
1306                            
1307                            $('.slideshow-pager-item', $slideshow_pager).removeClass('pager-item-active');
1308                            $(this).addClass('pager-item-active');
1309                            $slideshow.cycle(parseInt($(this).attr('data-index')));
1310                            return false;
1311                        });
1312                   }
1313                   
1314                    $slideshow.on('cycle-before', function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
1315                        $('.area_inner', incomingSlideEl).addClass('block-entrance-animations');
1316                        
1317                        $('.introduction_slideshow_caption.truncated-image-caption', $slideshow.closest('.text_columns')).removeClass('max_height_read_more').css({'max-height': '', '-webkit-line-clamp': '', 'line-clamp': '' });
1318                        if (!$('.introduction_slideshow_caption.truncated-image-caption', $slideshow.closest('.text_columns')).hasClass('max_height_read_more')) {
1319                            $('.introduction_slideshow_caption.truncated-image-caption', $slideshow.closest('.text_columns')).parent().find('.max_height_read_more_button').remove();
1320                        }
1321                        
1322                        var slide_caption = $(incomingSlideEl).attr('data-slide-caption')
1323                        if (slide_caption && typeof slide_caption != 'undefined') {
1324                            $('.introduction_slideshow_caption', $slideshow.closest('.text_columns')).html(slide_caption).removeClass('empty_caption');
1325                            $('.introduction_slideshow_caption.truncated-image-caption').each(function() {
1326                                window.site.layout.max_height_read_more(this, 4);
1327                            });
1328                        } else {
1329                            $('.introduction_slideshow_caption', $slideshow.closest('.text_columns')).html('').addClass('empty_caption');
1330                        }
1331                        
1332                        $('.slideshow-pager-item', $slideshow_pager).removeClass('pager-item-active');
1333                        $slideshow_pager.find('.slideshow-pager-item[data-index="'+parseInt($(incomingSlideEl).attr('data-sli
1333de-index'))+'"]').addClass('pager-item-active');
1334                    });
1335
1336                    $slideshow.on('cycle-after', function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
1337                     
1338                        $('.area_inner', slideshow).removeClass('block-entrance-animations');
1339                      
1340                    });
1341                });
1342            }
1343
1344        },
1345
1346        video: {
1347
1348        	init: function() {
1349                
1350                // Object-fit for IE/Edge
1351                objectFitVideos();
1352
1353                if ($('body').fitVids) {
1354                    $('body').fitVids({ ignore: '.video_inline'});
1355                }
1356
1357                if (window.site.device.video_inline()) {
1358                    $('body').addClass('device-video-inline-enabled');
1359                } else {
1360                    $('body').addClass('device-video-inline-disabled');
1361                }
1362
1363                if (!window.site.device.video_inline()) {
1364                    $('body').addClass('device-video-fallback');
1365                }
1366
1367               	$('.media_wrapper').each(function() {
1368	                var wrapper = $(this);
1369                    if (!$(this).hasClass('media_wrapper_has_canvas') || ($(this).hasClass('media_wrapper_has_canvas') && !window.site.device.canvas_enabled())){
1370                        // Each media wrapper may be disabled if there is an outside alternative which is currently active (in this case, video within canvas)
1371                        if ($(this).hasClass('media_has_video') && window.site.device.video_mode()) {
1372                            if ($('video', this).length) {
1373                                $(this).addClass('video_loading');
1374                                $('video', this).unbind().get(0).oncanplay = function() {
1375                                    var instance = $(this);
1376                                    window.setTimeout(function() {
1377                                        instance.closest('.media_wrapper').addClass('video_can_start');
1378                                        instance.closest('.media_wrapper').removeClass('video_loading');
1379                                        wrapper.closest('.media_wrapper').addClass('media_started');
1380                                    }, 000, instance);
1381                                };
1382                            }
1383                            window.setTimeout(function() {
1384                            	if (!wrapper.hasClass('video_can_start')) {
1385    	                        	wrapper.addClass('show_fallback');
1386                                    wrapper.closest('.media_wrapper').addClass('media_started');
1387    	                    	}
1388                            }, 1400, wrapper);
1389                        } else {
1390                            //wrapper.find('video').remove();
1391                        	if (wrapper.find('.slideshow').length) {
1392                        		wrapper.addClass('show_slideshow');
1393                        	} else {
1394                        		wrapper.addClass('show_fallback');
1395                        	}
1396                            wrapper.closest('.media_wrapper').addClass('media_started');
1397                        }
1398                    }
1399               	});
1400                
1401                if (!window.site.device.video_mode()) {
1402
1403                    video_fallback_html = '<div class="link video_fallback_button prevent_scroll"><span class="video_fallback_paused prevent_scroll">Play video</span><span class="video_fallback_play prevent_scroll">Stop video</span></div>';
1404                    if ($('.media_wrapper .video_background video').length) {
1405                        $('.media_wrapper').append(video_fallback_html);
1406                    }
1407                    $('.video_fallback_button').unbind('click').bind('click', function() {
1408                        if (window.site.device.video_mode()) {
1409                            var section_element = $(this).closest('.media_wrapper');
1410                            if (section_element.hasClass('video_fallback_playing')) {
1411                                section_element.find('.video_background video').get(0).pause();
1412                                section_element.removeClass('video_fallback_playing');
1413                            } else {
1414                                section_element.find('.video_background video').get(0).play();
1415                                section_element.addClass('video_fallback_playing');
1416                            }
1417                        } else {
1418                            var video_src = $(this).closest('.media_wrapper').find('.video_background video source').attr('src');
1419                            var video_data_src = $(this).closest('section').find('.video_background video source').attr('data-src');
1420                            if (video_src && typeof video_src != 'undefined') {
1421                                var video_file = video_src;
1422                            } else {
1423                                var video_file = video_data_src;
1424                            }
1425                            if (video_file && typeof video_file != 'undefined') {
1426                                window.open(video_file);
1427                            }
1428                        }
1429                    });
1430                } else {
1431                    video_loading_html = '<div class="video_loading_icon"><span class="loader"></span>Video loading</div>';
1432                    if ($('.media_wrapper .video_background video').length) {
1433                        $('.media_wrapper .video_background').append(video_loading_html);
1434                    }
1435                }
1436
1437                if (false) {
1438                    var vimeo_embeds = $('.video_embed_vimeo');
1439                    vimeo_embeds.each(function() {
1440                        var player = $f(this); // Froogaloop selector
1441    
1442                        $(this).closest('.video_embed_wrapper').find('.video_embed_play').click(function() {
1443                            var player = $f($(this).closest('.video_embed_wrapper').find('iframe').get(0)); // Froogaloop selector
1444                            player.api("play");
1445                        });
1446                        $(this).closest('.video_embed_wrapper').find('.video_embed_pause').click(function() {
1447                            var player = $f($(this).closest('.video_embed_wrapper').find('iframe').get(0)); // Froogaloop selector
1448                            player.api("pause");
1449                        });
1450                    });
1451                }
1452				
1453        	}
1454
1455        },
1456
1457        layout: {
1458
1459        	init: function() {
1460        		window.site.layout.textillate();
1461        		window.site.layout.textillate_homemade();
1462        		window.site.layout.flow_grid.init();
1463        		window.site.layout.grids.init();
1464        		window.site.layout.feature_panels();
1465        		window.site.layout.navigation();
1466                window.site.layout.hero.init();
1467                window.site.layout.shutter_hero.init();
1468                window.site.layout.hero.custom_color_off();
1469                
1470                $('.scroll-to-top button').unbind().click(function() {
1471                    var body = $("html, body");
1472                    body.stop().animate({scrollTop:0}, 800, 'easeInOutExpo', function() { 
1473                        
1474                    });
1475                });
1476                
1477                $('#hero.hero_full_width .hero-inner').css('cursor', 'pointer').click(function() {
1478                    window.site.commands.scrollto($('.scroll_section_panels:eq(0)').offset().top);
1479                });
1480                
1481                // $('#hero.hero_layout_fullbleed .hero-inner').css('cursor', 'pointer').click(function() {
1482                //     window.site.commands.scrollto($('.scroll_section_panels:eq(0)').offset().top);
1483                // });
1484
1485        		//$('#main_content').css('min-height', window.site.layout.window_height());
1486        		
1487                $('.notify_panel_mask').unbind().click(function() {
1488                    if ($('#store_quick_cart_widget').hasClass('active')) {
1489                        $('#sqcw_close').trigger('click');
1490                    }
1491                    if ($('#wishlist_quick_cart_widget').hasClass('active')) {
1492                        $('#wishlist_quick_cart_widget .notify_panel_close').trigger('click');
1493                    }
1494                    if ($('.content-overlay').hasClass('active')) {
1495                        $('.content-overlay .overlay-close-button').trigger('click');
1496                    }
1497                    if ($('.enquire-overlay').hasClass('active')) {
1498                        $('.enquire-overlay .enquire-close-button').trigger('click');
1499                    }
1500                    if ($('.nav-overlay').hasClass('active')) {
1501                        $('.nav-overlay .nav-close-button').trigger('click');
1502                    }
1503                    if ($('.filter-overlay').hasClass('active')) {
1504                        $('.filter-overlay .filter-close-button').trigger('click');
1505                    }
1506                    if ($('.artist-overlay').hasClass('active')) {
1507                        $('.artist-overlay .artist-close-button').trigger('click');
1508                    }
1509                });
1510                
1511                var timer, el = $('#container_outer'), flag = false;
1512                $(window).add('#popup_content').scroll(function() {
1513                    var scrolling_element = $(this);
1514                    if (!flag) {
1515                        flag = true;
1516                        //if (!$('body').hasClass('content-swipe')) {
1517                            el.addClass('scrolling').removeClass('not-scrolling');
1518                            $(scrolling_element).addClass('scrolling').removeClass('not-scrolling');
1519		                //}
1520                    }
1521                    clearTimeout(timer);
1522                    timer = setTimeout(function() {
1523                        el.removeClass('scrolling').addClass('not-scrolling');
1524                        $(scrolling_element).removeClass('scrolling').addClass('not-scrolling');
1525                        flag = false;
1526                    }, 300, scrolling_element);
1527                });
1528                $('#container_outer').removeClass('scrolling').addClass('not-scrolling');
1529
1530                $('#popup_content').bind('scroll', window.site.throttle(50, function() {
1531                    if ($('#popup_content').scrollTop() > 30) {
1532                        $('body').addClass('popup-scrolled');
1533                        $('body').removeClass('popup-not-scrolled');
1534                    } else {
1535                        $('body').removeClass('popup-scrolled');
1536                        $('body').addClass('popup-not-scrolled');
1537                    }
1538                }));
1539                $('#popup_content').bind('scroll', window.site.debounce(200, function() {
1540                    if ($('#popup_content').scrollTop() > 30) {
1541                        $('body').addClass('popup-scrolled');
1542                        $('body').removeClass('popup-not-scrolled');
1543                    } else {
1544                        $('body').removeClass('popup-scrolled');
1545                        $('body').addClass('popup-not-scrolled');
1546                    }
1547                }));
1548                
1549                $('.search-overlay .overlay-container-inner').bind('scroll', window.site.throttle(50, function() {
1550                    if ($('.search-overlay .overlay-container-inner').scrollTop() > 30) {
1551                        $('body').addClass('popup-scrolled');
1552                        $('body').removeClass('popup-not-scrolled');
1553                    } else {
1554                        $('body').removeClass('popup-scrolled');
1555                        $('body').addClass('popup-not-scrolled');
1556                    }
1557                }));
1558                $('.search-overlay .overlay-container-inner').bind('scroll', window.site.debounce(200, function() {
1559                    if ($('.search-overlay .overlay-container-inner').scrollTop() > 30) {
1560                        $('body').addClass('popup-scrolled');
1561                        $('body').removeClass('popup-not-scrolled');
1562                    } else {
1563                        $('body').removeClass('popup-scrolled');
1564                        $('body').addClass('popup-not-scrolled');
1565                    }
1566                }));
1567
1568                if (!$('.scroll-container .faux_footer').length && $('#footer').length) {
1569                	$('.scroll-container').append('<div class="faux_footer"></div>');
1570                }
1571                
1572                $('.truncated-image-caption:not(.art_fair_slideshow_caption)').each(function() {
1573                    window.site.layout.max_height_read_more(this, 4);
1574                });
1575                
1576                window.site.misc.extended_click_area();
1577                window.site.misc.fancybox_image_popup();
1578                
1579                $(window).resize(function() {
1580                	window.site.layout.resize();
1581                });
1582                window.site.layout.resize();
1583            },
1584            
1585            max_height_read_more: function(target, lines, read_more_label) {
1586                
1587                var $target = $(target);
1588                
1589                if($target.length) {
1590                
1591                    var initial_lines = lines;
1592                    if (!initial_lines || typeof initial_lines == 'undefined') {
1593                        initial_lines = 10;
1594                    }
1595                    
1596                    if (!read_more_label || typeof read_more_label == 'undefined') {
1597                        read_more_label = 'Read more';
1598                    }
1599                    
1600                    var line_height = $target.css('line-height');
1601                    // Double check this 0.3 addition, but seems to work better. Some lines were being cut in half before.
1602                    var target_height = (initial_lines + 0.3) * parseFloat(line_height);
1603                    
1604                    // Removed for now as it was breaking due to some text being on a single line and being a seperate paragraph
1605                    
1606                    // if ($target.find('p').length) {
1607                    //     first_paragraph_height = $target.find('p').first().height();
1608                    //     target_height = Math.min(target_height, first_paragraph_height);
1609                    // }
1610                    
1611                    if ($target.height() > (target_height + 2)) {
1612                        
1613                        //5 px buffer
1614                        
1615                        $target.addClass('max_height_read_more').css({'max-height': ((target_height - 3 )+'px'), '-webkit-line-clamp': initial_lines.toString(), 'line-clamp': initial_lines.toString() });
1616                        
1617                        
1618                        if ($target.hasClass('truncated-image-caption') || $target.hasClass('image_caption')) {
1619                            
1620                            // Image captions
1621                            var read_more_button_html = '<div class="max_height_read_more_button content_read_more_link image-caption-read-more ani-in"><span class="image-caption-read-more-label">Full caption<span class="plus-icon-container"><span class="plus-icon-horizontal-line"></span><span class="plus-icon-vertical-line"></span></span></span></div>'
1622                            
1623                            if ($target.next().hasClass('buttons')) {
1624                                $target.next().find('.max_height_read_more_button').remove();
1625                                $target.next().prepend(read_more_button_html);
1626                            } else {
1627                                $target.parent().find('.max_height_read_more_button').remove();
1628                                $target.after(read_more_button_html);
1629                            }
1630                            $('.max_height_read_more_button .image-caption-read-more-label', $target.parent()).off().on('click', function(e){
1631                                
1632                                $target.toggleClass('max_height_read_more');
1633                                
1634                                if ($target.hasClass('max_height_read_more')) {
1635                                    $('.plus-icon-container', this).removeClass('closed');
1636                                    $target.addClass('max_height_read_more').css({'max-height': ((target_height -1 )+'px'), '-webkit-line-clamp': initial_lines.toString(), 'line-clamp': initial_lines.toString() });
1637                                } else {
1638                                    $(target).css('max-height', '3000px');
1639                                    $('.plus-icon-container', this).addClass('closed');
1640                                }
1641                            });
1642                            
1643                        } else {
1644                            
1645                            if ($target.next().hasClass('buttons')) {
1646                                $target.next().find('.max_height_read_more_button').remove();
1647                                $target.next().prepend('<div class="max_height_read_more_button content_read_more_link"><span>' + read_more_label + '</span></div>');
1648                            } else {
1649                                $target.parent().find('.max_height_read_more_button').remove();
1650                                $target.after('<div class="max_height_read_more_button content_read_more_link">' + read_more_label + '</div>');
1651                            }
1652                            $('.max_height_read_more_button', $target.parent()).off().on('click', function(e){
1653                                $(target).css('max-height', '3000px');
1654                                $target.toggleClass('max_height_read_more');
1655                                $(this).hide();
1656                                $target.closest('.content_container').css('position', 'static')
1657                            });
1658                        }
1659                    }
1660                }
1661            },
1662            
1663            align_captions: function(context) {
1664                // Align captions with smaller images
1665                
1666                var default_context = '.panel_type_206';
1667                var context = context && typeof context != 'undefined' ? context : default_context;
1668                
1669                $(context).each(function() {
1670                    if ($('.image_lazy_load.loaded', this).length || $('.image', this).not('.image_lazy_load').length) {
1671                        
1672                        $('.caption', this).css({'margin-left': 'auto', 'margin-right': 'auto', 'max-width': ''});
1673                        if ($('img', this).width() < $('.caption', this).width() && $('img', this).width()  > 120) {
1674                            $('.caption', this).css({'margin-left': 'auto', 'margin-right': 'auto', 'max-width': $('img', this).width()});
1675                        }
1676                    }
1677                });
1678            },
1679
1680        	resize: function() {
1681    	    
1682                $('body').addClass('resizing');
1683                
1684                window.site.layout.align_captions();
1685                
1686                if (window.site.device.handheld()) {
1687                    
1688                    if ($('#hero').hasClass('hero_layout_fullbleed')) {
1689                        $('#hero.hero_layout_fullbleed').css('min-height', $(window).height());
1690                        $('#hero.hero_layout_fullbleed .hero-inner').css('min-height', $(window).height());
1691                        $('#hero.hero_layout_fullbleed .hero_slideshow_wrapper').css('height', $(window).height());
1692                    } else {
1693                        $('#hero').css('height', $(window).height());
1694                        $('#hero .hero-inner').css('height', $(window).height());
1695                        $('#hero .hero_slideshow_wrapper').css('height', $(window).height());
1696                    }
1697                }
1698                
1699                if ($('.subsection-store-basket').length) {
1700                	var new_min_height = $(window).height();
1701                	$('#content_module').css('min-height', '0');
1702                	$('#sidebar').css('min-height', '0');
1703                	if ($('#sidebar').outerHeight() > $('#content_module').outerHeight()) {
1704                		var sidebar_height = $('#sidebar').outerHeight();
1705                		if (sidebar_height > new_min_height) {
1706                			var sidebar_height = sidebar_height;
1707                		}
1708                	}
1709                	if ($('#content_module').outerHeight() > $('#sidebar').outerHeight()) {
1710                		var content_height = $('#content_module').outerHeight();
1711                		if (content_height > new_min_height) {
1712                			var new_min_height = content_height;
1713                		}
1714                	}
1715                	$('#content_module, #sidebar').css('min-height', new_min_height);
1716				}
1717				
1718				$('.feature_panels_sidebar_outer').each(function() {
1719				    if ($('.feature_panels_sidebar', this).outerHeight() > $(window).height()) {
1720				        $(this).closest('.scroll_section_panels').removeClass('feature_panels_sidebar_fixed');
1721				    } else {
1722				        $(this).closest('.scroll_section_panels').addClass('feature_panels_sidebar_fixed');
1723				    }
1724				});
1725                
1726                if (typeof resizing_timeout != 'undefined') {
1727                    clearTimeout(resizing_timeout);
1728                }
1729                resizing_timeout = setTimeout(function() {
1730                    $('body').removeClass('resizing');
1731                }, 600);
1732        	},
1733
1734            window_height: function() {
1735                var window_height = $(window).height();
1736                var toolbar_height = $('body').hasClass('cms-frontend-toolbar-active') ? 28 : 0;
1737                return window_height - toolbar_height;
1738            },
1739
1740            window_height_extended: function() {
1741                var extended_height = (window.site.layout.window_height() / 100) * 10;
1742                return window.site.layout.window_height() + extended_height;
1743            },
1744
1745        	feature_panels: function() {
1746        	    
1747        	    // Vertical slider
1748        	    $('.panel_type_232.slideshow-transition-2').each(function() {
1749        	        $(this).find('.vertical_slideshow_duplicate').remove();
1750        	        $(this).find('.area_wrapper > .area_mobile').remove();
1751        	        $(this).find('.area_wrapper').prepend('<div class="area_mobile mobile-only">' + $(this).find('.area').html() + '</div>')
1752        	        $(this).find('.area').addClass('desktop-only');
1753        	        $(this).find('.image').prepend('<div class="vertical_slideshow_duplicate">' + $(this).find('.image').html() + '</div>');
1754        	        $('.vertical_slideshow_duplicate .image_section:eq(0)').addClass('active');
1755        	    });
1756        	    
1757                $(window).bind('resize.panel_vertical_slideshow', window.site.debounce(200, function() {
1758                    $('.panel_type_232.slideshow-transition-2').each(function() {
1759            	        $(this).removeClass('initialised');
1760            	        $(this).find('.inner').css('min-height', $(this).find('.inner').height());
1761            	        $(this).addClass('initialised');
1762            	    });
1763                })).trigger('resize.panel_vertical_slideshow');
1764                
1765                $(window).bind('scroll', window.site.throttle(50, function() {
1766                    $('.panel_type_232.slideshow-transition-2').each(function() {
1767                        var panelscrolltop = $(window).scrollTop() - $(this).offset().top;
1768                        var panelscrollend = $(this).offset().top + $(this).height();
1769                        var item_count = $('.vertical_slideshow_duplicate .image_section').length + 1;
1770                        if (panelscrolltop >= 0 && $(window).scrollTop() < panelscrollend) {
1771                            var section_height_per_slide = $(this).height() / item_count;
1772                            var current_slide = Math.ceil(panelscrolltop / section_height_per_slide);
1773                            if (current_slide < 1) {
1774                                current_slide = 1;
1775                            } else if (current_slide > item_count-1) {
1776                                current_slide = $('.vertical_slideshow_duplicate .image_section').length;
1777                            }
1778                            $('.vertical_slideshow_duplicate .image_section').removeClass('active');
1779                            $('.vertical_slideshow_duplicate .image_section:eq(' + (current_slide-1) + ')').addClass('active');
1780                        }
1781            	    });
1782                }));
1783        	    
1784        		feature_panels_index = 0;
1785            	$('.scroll_section_panels section').each(function() {
1786        			feature_panels_index = feature_panels_index + 1;
1787            		$(this).attr('data-scrollinner-index', feature_panels_index);
1788            		$(this).addClass('panel_index_' + feature_panels_index);
1789            		if ($('.panel_heading', this).length && !$('.panel_heading', this).hasClass('visually-hidden')) {
1790            		    $(this).addClass('has_panel_heading');
1791            		}
1792            		$('.panel_heading', this).each(function() {
1793            		    if (!$('.panel_heading_inner', this).length) {
1794            		        $(this).wrapInner('<div class="panel_heading_inner"></div>');
1795            		    }
1796            		});
1797        		    if ($(this).next().hasClass('panel_type_214') || $(this).next().hasClass('panel_type_230')) {
1798        		        $(this).addClass('full-bleed-below');
1799        		    }
1800            	});
1801            	
1802            	///WHATS HAPPENING?
1803                $('.feature_panels section.panel_type_happening').each(function() {
1804                        
1805                    var $panel = $(this);
1806                    $panel.find('.panel_filters .panel_filter_option_all').hide();
1807                    $panel.find('.panel_filters .panel_filter_option .panel_filter_label').each(function() {
1808                        $(this).attr('data-original-label', $(this).text());
1809                    });
1810                    
1811                    $panel.find('.panel_filters .panel_filter_option ul li button, button.panel_filter_option_all').click(function() {
1812
1813                        $('body').addClass('filter-active')
1814
1815                        var buttonLabel = $(this).text();
1816                        if (buttonLabel == 'All') {
1817                            buttonLabel = 'News'
1818                        }
1819                        var panel_id = $(this).closest('section.panel_type_happening').attr('data-panel-id');
1820                        
1821                        if ($(this).hasClass('panel_filter_option_all')) {
1822                            
1823                            $(this).closest('section.panel_type_happening').find('.panel_filters .panel_filter_option_all').hide();
1824                            var filter_type = '';
1825                            var filter_id = '';
1826                            var filter_table = '';
1827                            
1828                        } else {
1829                            
1830                            $(this).closest('.panel_filters').find('li').removeClass('active');
1831                            $(this).closest('li').addClass('active');
1832                            $(this).closest('section.panel_type_happening').find('.panel_filters .panel_filter_option_all').show();
1833                            var filter_type = $(this).attr('data-filter-type');
1834                            var filter_id = $(this).attr('data-filter-id');
1835                            var filter_table = $(this).attr('data-filter-table');
1836                            
1837                        }
1838                        
1839                        var artist_auto  = ''
1840                        
1841                        if ($(this).hasClass('artist_latest_results_panel')) {
1842                            var incoming_url = '/feature_panels/single/?filter_type=' + filter_type + '&filter_table=' + filter_table + '&filter_id=' + filter_id + '&feature_panels=[["1","{\\"rec_id\\"
1842:\\"' + panel_id + '\\",\\"object_type\\":\\"gallery_feature_panels_custom\\"}"]]'
1843                        } else {
1844                            var incoming_url = window.location.pathname + '?filter_type=' + filter_type + '&filter_table=' + filter_table + '&filter_id=' + filter_id;
1845
1846                        }
1847                        
1848                        $(this).closest('.panel_filters').find('.panel_filter_label').each(function() {
1849                            $(this).text($(this).attr('data-original-label'));
1850                        });
1851                        $(this).closest('.panel_filter_option').find('.panel_filter_label').text($(this).text());
1852                        
1853                    var $list = $panel.find('.records_grid');
1854                    var incoming_content_type = 'inner';
1855                    var inner_content_selector = '.section.panel_type_happening[data-panel-id="'+panel_id+'"]';
1856                    
1857                    $.pageload.load(incoming_url, false, function(new_page_inner_content, element_href, new_page_main_content) {
1858                        
1859                        if (new_page_inner_content) {
1860                            
1861                            var $new_page_inner_content = $(new_page_inner_content);
1862                            $panel.find('.filter_results')
1863                                .addClass('filter_transition')
1864                                .delay(400)
1865                                .queue(function() {
1866                                    
1867                                    // history.replaceState({'ajaxPageLoad': true}, null, updated_url);
1868                                    
1869                                    // UPDATE TITLE...
1870                                    if ($('.panel_heading .prelude', $panel).siblings('h2').length) {
1871                                        $('.panel_heading .prelude + h2', $panel).text('Latest ' + (buttonLabel || 'news'));
1872                                    } else {
1873                                        $('.panel_heading .prelude', $panel).text('Latest ' + (buttonLabel || 'news'));
1874                                    }
1875                                    var full_html = $(new_page_main_content);
1876                                    var results_html = full_html.find('.filter_results').html();
1877                                    var pagestats_id = full_html.find('.filter_results').attr('data-pagestats-id');
1878                                    
1879                                    $('.filter_results').html(results_html);
1880                                    $('.filter_results').removeClass('filter_transition');
1881                                    $panel.find('.filters_inner').addClass('filter-results-loaded');
1882                    
1883                                    $(window).trigger('resize');
1884                                    $(window).trigger('scroll');
1885        
1886                                    window.site.layout.grids.init();
1887                                    window.site.lazy_load.setup();
1888                                    window.site.artlogic_inview.init();
1889                                    // $.pageload.refresh('.ajax-loaded-list-item:not(.pageload-refreshed)');
1890                                    // $('.ajax-loaded-list-item').addClass('pageload-refreshed');
1891        				            window.site.overlays.enquire.setup();
1892        				            window.cart.add_to_cart($list.find('.store_item .store_item_add_to_cart'));
1893                                    window.cart.add_to_wishlist($list.find('.add_to_wishlist'));
1894        				            window.cart.remove_from_wishlist($list.find('.store_item_remove_from_wishlist'));
1895                                    window.site.misc.init();
1896        
1897                                    if ($('body').hasClass('tabbing-detected')) {
1898                                        $list.find('.first_new_item a').focus();
1899                                    }
1900                                    window.site.misc.extended_click_area();
1901                                    window.site.misc.fancybox_image_popup();
1902                                    $.pageload.refresh();
1903                                    $(this).dequeue();
1904                                })
1905                            ;
1906                        }
1907                        
1908                    }, null, null, null, incoming_content_type);
1909                    });
1910                });
1911        	},
1912
1913        	navigation: function() {
1914
1915        	},
1916
1917        	grids: {
1918
1919        		init: function() {
1920
1921        			$('.column_list:not(.artist_column_list)').each(function() {
1922        				$(this).delay(500).queue(function() {
1923		                    $('.column_list ul:not(.visible)').each(function(i){
1924		                        var $item = $(this);
1925		                        setTimeout(function() {
1926		                            $item.addClass('visible');
1927		                        }, 200*i);
1928		                    });
1929        					$(this).clearQueue();
1930        				});
1931        			});
1932
1933        			$('.extended_text_wrapper').each(function() {
1934        				$('.content_extended_text', this).each(function() {
1935        				    if (!$(this).closest('.extended_text_wrapper').hasClass('extended_text_show')) {
1936            					$(this).closest('.extended_text_wrapper').addClass('extended_text_hidden');
1937        				    }
1938        					$(this).closest('.extended_text_wrapper').find('.content_reveal_more_link a, .content_reveal_more_link button').unbind().click(function() {
1939        					    $(this).closest('.extended_text_wrapper').removeClass('extended_text_hidden');
1940        						$(this).closest('.extended_text_wrapper').addClass('extended_text_show');
1941        						return false;
1942        					});
1943        					$(this).closest('.extended_text_wrapper').find('.content_close_more_text_button a').unbind().click(function() {
1944        					    var instance = this;
1945    					        $(instance).closest('.extended_text_wrapper').addClass('extended_text_closing');
1946        					    setTimeout(function() {
1947        					        $(instance).closest('.extended_text_wrapper').addClass('extended_text_hidden');
1948            						$(instance).closest('.extended_text_wrapper').removeClass('extended_text_show extended_text_closing');
1949        					    }, 400, instance);
1950        						window.site.commands.scrollto($(this).closest('.extended_text_wrapper').offset().top - 40);
1951        						return false;
1952        					});
1953        					
1954        				});
1955        			});
1956        			
1957        			// Gallery page accordion
1958                    $('.gallery-accordion-button').unbind().click(function() {
1959                        $accordion_panel = $(this).parent().next();
1960                        $accordion_container = $(this).closest('.gallery_details_accordion');
1961                        var panel_id = $(this).attr('aria-controls');
1962                        
1963                        if ($(this).hasClass('address')) {
1964        	                window.location.hash = 'address';
1965        	            } else if ($(this).hasClass('contact')) {
1966        	                window.location.hash = 'contact';
1967        	            } else if ($(this).hasClass('hours')) {
1968        	                window.location.hash = 'hours';
1969        	            } else if ($(this).hasClass('find-us')) {
1970        	                window.location.hash = 'find-us';
1971        	            }
1972                        
1973                        if ($(this).hasClass('active')) {
1974                            $accordion_panel.removeClass('panel-active').slideUp();
1975                            $(this).removeClass('active').attr('aria-expanded', false);
1976                            $('.plus-icon-container', this).removeClass('closed');
1977                        } else {
1978                            var panel_open_below = false;
1979                            $(this).parent().nextAll().each(function () {
1980                                if ($(this).hasClass('panel-active')) {
1981                                    panel_open_below = true;
1982                                }
1983                            });
1984                            
1985                            $accordion_panel.addClass('panel-active').slideDown();
1986                            $(this).addClass('active').attr('aria-expanded', true);
1987                            $('.plus-icon-container', this).addClass('closed');
1988                            
1989                            $('.gallery-accordion-button', $accordion_container).not(this).removeClass('active').attr('aria-expanded', false);
1990                            $('.plus-icon-container', $accordion_container).not($('.plus-icon-container', this)).removeClass('closed');
1991                            $('.gallery-accordion-panel:not(#' + panel_id + ')', $accordion_container).removeClass('panel-active').slideUp();
1992                            
1993                        }
1994                        return false;
1995                    });
1996                    
1997                    // Trigger click on accordion section based on hash in url
1998                    if ($('body').hasClass('section-gallery') && window.location.hash && typeof window.location.hash != 'undefined') {
1999                        if (window.location.hash.indexOf('#address') > -1) {
2000                            $('.gallery-accordion-button.address').click();
2001                        } else if (window.location.hash.indexOf('#contact') > -1) {
2002                            $('.gallery-accordion-button.contact').click();
2003                        } else if (window.location.hash.indexOf('#hours') > -1) {
2004                            $('.gallery-accordion-button.hours').click();
2005                        } else if (window.location.hash.indexOf('#find-us') > -1) {
2006                            $('.gallery-accordion-button.find-us').click();
2007                        }
2008            	    }
2009                        
2010	                $('.records_grid.tile_grid').each(function() {
2011	                	if (!$('.tile_grid_original', this).length) {
2012		                    var original_html = $(this).html();
2013		                    $(this).html('');
2014		                    $(this).append('<div class="tile_grid_formatted"></div>');
2015		                    $(this).append('<div class="tile_grid_original"></div>');
2016		                    $('.tile_grid_original', this).html(original_html).css('visibility', 'hidden');
2017	                	}
2018	                });
2019
2020        			window.site.layout.grids.resize();
2021        			$(window).bind('resize', function() {
2022	        			window.site.layout.grids.resize();
2023	        		});
2024
2025	        		$('.records_grid.tile_grid')
2026	                    .each(function() {
2027	                        if ($('.tile_grid_formatted .item.revealable', this).length) {
2028		                        if (!$(this).find('.panel_footer_revealable_link').length) {
2029		                            $(this).append('<div class="panel_footer panel_footer_revealable_link"><div class="link link_more"><a href="#">Load more</a></div></div>');
2030		                            $(this).find('.link_more a').click(function() {
2031		                            	// when view more is clicked we need to focus on the first new element
2032		                            	var $item_to_focus_on = $(this).closest('.tile_grid').find('.tile_grid_formatted > .group:first .item.revealable:first');
2033		                                var link_original_top_offset = $(this).offset().top - ($(window).height() / 2);
2034		                                var current_offset_top = $(window).scrollTop() - ($(window).height() / 2);
2035		                                var items_to_reveal = ($(this).closest('.records_grid').attr('data-rows-to-reveal') && typeof $(this).closest('.records_grid').attr('data-rows-to-reveal') != 'undefined' ? $(this).closest('.records_grid').attr('data-rows-to-reveal') : 2);
2036					                    if (window.site.device.breakpoint() <= 2) {
2037					                    	var items_to_reveal = parseInt(items_to_reveal) * 2;
2038					                    }
2039					                    $('body').addClass('scroll_event_disabled, window-forced-scroll-up');
2040		                                $(this).closest('.tile_grid').find('.tile_grid_formatted > .group').each(function() {
2041		                                    $('.item.revealable:lt(' + items_to_reveal + ')', this).removeClass('revealable');
2042		                                });
2043		                                var remaining_revealable_items = $(this).closest('.tile_grid').find('.tile_grid_formatted > .group .item.revealable', this).length;
2044		                                if (remaining_revealable_items == 0) {
2045		                                    $(this).closest('.panel_footer_revealable_link').addClass('disabled');
2046		                                }
2047		                                
2048		                                $('html,body').animate(
2049		                                    {scrollTop: link_original_top_offset},
2050		                                    650,
2051		                                    'easeInOutQuad',
2052		                                    function() {
2053		                                    	window.setTimeout(function() {
2054			                                        $('body').removeClass('scroll_event_disabled, window-forced-scroll-up');
2055			                                    }, 500);
2056		                                        $(window).trigger('scroll');
2057		                                    }
2058		                                );
2059		                                //checking for tabbing before focusing as the focus can mess up the smooth scrolling
2060		                                if ($('body.tabbing-detected').length) {
2061		                                	$item_to_focus_on.find('a:first').focus();
2062		                                }
2063		                                return false;
2064		                            });
2065		                        }
2066	                        }
2067	                    })
2068	                ;
2069
2070	                // Flow grid format
2071	                            
2072                    $('.records_grid.flow_grid')
2073                        .each(function() {
2074                            if ($('.flow_list_formatted .item.revealable', this).length) {
2075                                
2076                                //set to visually hidden, not display none - so that responsive image sizing can detect widths
2077                                $('.flow_list_formatted .item.revealable', this).addClass('initial');
2078                                
2079                                var flow_list = this;
2080                                
2081                                if (!$(this).find('.panel_footer_revealable_link').length) {
2082                                    
2083                                    var items = $('.flow_list_formatted .item', this).length;
2084                                    var rows_to_reveal = ($(this).attr('data-rows-to-reveal') && typeof $(this).closest('.records_grid').attr('data-rows-to-reveal') != 'undefined' ? $(this).closest('.records_grid').attr('data-rows-to-reveal') : 6);
2085                                    var total_blocks = Math.ceil(items / rows_to_reveal);
2086                                    
2087                                    $(this).append('<div class="panel_footer panel_footer_revealable_link inview_element ani-group"><div class="panel_footer_revealable_link_inner ani-in"><div class="button link_more"><button type="button" class="clear_button_styles">+</button></div><div class="load-more-progress-bar-outer"><div class="load-more-progress-bar"></div></div><div class="reveal-pagination"><span class="current-block">1</span>/<span class="total-blocks">'+total_blocks+'</span></div></div></div>');
2088                                    
2089                                    var remaining_revealable_items = $('.flow_list_formatted .item.revealable', this).length;
2090                                    var remaining_blocks = Math.ceil(remaining_revealable_items / rows_to_reveal);
2091                                    var percentage_complete = ((total_blocks - remaining_blocks) / total_blocks);
2092                                    $('.panel_footer_revealable_link .load-more-progress-bar', this).css('transform', 'scaleX(' + percentage_complete + ')');
2093                                    
2094                                    $(this).find('.link_more button').unbind('click.flow_grid_load_more').bind('click.flow_grid_load_more', function() {
2095                                        
2096                                        //set back to display none
2097                                        $('.flow_list_formatted .item.revealable', flow_list).removeClass('initial');
2098                                        
2099                                        var $button = $(this);
2100                                        
2101                                        window.setTimeout(function() {
2102                                            
2103                                            var link_original_top_offset = $button.offset().top - ($(window).height() / 4);
2104                                            var items_to_reveal = ($button.closest('.records_grid').attr('data-rows-to-reveal') && typeof $button.closest('.records_grid').attr('data-rows-to-reveal') != 'undefined' ? $button.closest('.records_grid').attr('data-rows-to-reveal') : 2);
2105                    	                    if (window.site.device.breakpoint() <= 2) {
2106                    	                    	var items_to_reveal = parseInt(items_to_reveal) * 2;
2107                    	                    }
2108                    	                    $('body').addClass('scroll_event_disabled, window-forced-scroll-up');
2109                    
2110                                            // Extend the height of the container for a smoother opening effect
2111                                            var containing_group = $button.closest('.records_grid').find('.flow_list_formatted');
2112                                            var new_row_to_be_revealed = $button.closest('.records_grid').find('.item.revealable').filter(':eq(0)');
2113                                            
2114                                            var containing_group_new_height = containing_group.height() + (new_row_to_be_revealed.height() * items_to_reveal);
2115                                            containing_group.css('height', containing_group.height());
2116                                            window.setTimeout(function() {
2117                                            	containing_group.css('height', containing_group_new_height);
2118                                            }, 20, containing_group);
2119                    
2120                                        	// Reveal the items
2121                                        	var fl_reveal_items_remaining = items_to_reveal
2122                                        	
2123                                            $button.closest('.flow_grid').find('.flow_list_formatted > .group').each(function() {
2124                                                
2125                                                var items_in_row = $('.item.revealable', this).length;
2126                                                fl_reveal_items_remaining = fl_reveal_items_remaining - items_in_row;
2127                                                if (fl_reveal_items_remaining >= 0) {
2128                                                    $('.item.revealable', this).removeClass('revealable');
2129                                                }
2130                                                
2131                                            });
2132                    
2133                                            var remaining_revealable_items = $button.closest('.flow_grid').find('.flow_list_formatted > .group .item.revealable').length;
2134                                            var remaining_blocks = Math.ceil(remaining_revealable_items / items_to_reveal);
2135                                            
2136                                            $button.closest('.panel_footer_revealable_link').find('.current-block').text(total_blocks - remaining_blocks);
2137                                            
2138                                            var percentage_complete = ((total_blocks - remaining_blocks) / total_blocks);
2139                                            $button.closest('.panel_footer_revealable_link').find('.load-more-progress-bar').
2139css('transform', 'scaleX(' + percentage_complete + ')');
2140                                            
2141                                            if (!remaining_revealable_items) {
2142                                                $button.closest('.panel_footer_revealable_link').addClass('disabled');
2143                                            }
2144                    
2145                                            $('html,body').animate(
2146                                                {scrollTop: link_original_top_offset},
2147                                                1200,
2148                                                'easeInOutExpo',
2149                                                function() {
2150                                                	window.setTimeout(function() {
2151                                                        $('body').removeClass('scroll_event_disabled, window-forced-scroll-up');
2152                                                    }, 500);
2153                                                    $(window).trigger('scroll');
2154                                                	containing_group.css('height', '');
2155                                                }
2156                                            );
2157                                            
2158                                            return false;
2159                                            
2160                                        }, 50);        
2161                                    });
2162                                }
2163                            }
2164                        })
2165                    ;
2166
2167	                // Aligned grid format
2168	        		$('.xxxrecords_grid.standard_grid').each(function() {
2169		        		if ($('.item.revealable', this).length) {
2170	                        if (!$(this).find('.panel_footer_revealable_link').length) {
2171	                            $(this).append('<div class="panel_footer panel_footer_revealable_link"><div class="button link_more"><a href="#">Load more</a></div></div>');
2172	                            $(this).find('.link_more a').unbind('click.records_grid').bind('click.records_grid', function() {
2173	                            	// when view more is clicked we need to focus on the first new element
2174		                            var $item_to_focus_on = $(this).closest('.records_grid.standard_grid').find('.group:first .item.revealable:first');
2175	                                var link_original_top_offset = $(this).offset().top - ($(window).height() / 4);
2176	                                var rows_to_reveal = ($(this).closest('.records_grid').attr('data-rows-to-reveal') && typeof $(this).closest('.records_grid').attr('data-rows-to-reveal') != 'undefined' ? $(this).closest('.records_grid').attr('data-rows-to-reveal') : 2);
2177	        						if (window.site.device.breakpoint() == 1) {
2178										var rows_to_reveal = rows_to_reveal * 2;
2179	        						}
2180	                                var current_visible_row = $(this).closest('.records_grid').find('.item').not('.revealable').last().attr('data-row-number');
2181	                                $('body').addClass('scroll_event_disabled');
2182	                                $(this).closest('.records_grid').each(function() {
2183	                                	for(var i=0; i < rows_to_reveal; i++){
2184										    var row_index = parseInt(current_visible_row) + (i + 1);
2185										    $('.item.revealable[data-row-number="' + row_index + '"]', this).addClass('revealed').removeClass('revealable');
2186										}
2187	                                });
2188	                                var remaining_revealable_items = $(this).closest('.records_grid').find('.item.revealable', this).length;
2189	                                if (remaining_revealable_items == 0) {
2190	                                    $(this).closest('.panel_footer_revealable_link').addClass('disabled');
2191	                                }
2192	                                $('html,body').animate(
2193	                                    {scrollTop: link_original_top_offset},
2194	                                    400,
2195	                                    'easeInOutExpo',
2196	                                    function() {
2197	                                        $('body').removeClass('scroll_event_disabled');
2198	                                        $(window).trigger('scroll');
2199	                                    }
2200	                                );
2201	                                $(window).trigger('resize');
2202	                                //checking for tabbing before focusing as the focus can mess up the smooth scrolling
2203	                                if ($('body.tabbing-detected').length) {
2204	                                	$item_to_focus_on.find('a:first').focus();
2205	                                }
2206	                                return false;
2207	                            });
2208	                        }
2209	                    }
2210	        		});
2211	        		
2212	        		// Artworks grid format
2213	        		$('.panel_type_202 .records_grid:not(.flow_grid), .panel_type_201 .records_grid, .records_grid.standard_grid').each(function() {
2214		        		if ($('.item.revealable', this).length) {
2215	                        if (!$(this).find('.panel_footer_revealable_link').length) {
2216	                            
2217	                            var items = $('.item', this).length;
2218	                            var rows_to_reveal = ($(this).attr('data-rows-to-reveal') && typeof $(this).closest('.records_grid').attr('data-rows-to-reveal') != 'undefined' ? $(this).closest('.records_grid').attr('data-rows-to-reveal') : 6);
2219	                            var total_blocks = Math.ceil(items / rows_to_reveal);
2220	                            
2221	                            $(this).append('<div class="panel_footer panel_footer_revealable_link inview_element ani-group"><div class="panel_footer_revealable_link_inner ani-in"><div class="button link_more"><button type="button" class="clear_button_styles">+</button></div><div class="load-more-progress-bar-outer"><div class="load-more-progress-bar"></div></div><div class="reveal-pagination"><span class="current-block">1</span>/<span class="total-blocks">'+total_blocks+'</span></div></div></div>');
2222	                            
2223	                            var remaining_revealable_items = $('.item.revealable', this).length;
2224	                            var remaining_blocks = Math.ceil(remaining_revealable_items / rows_to_reveal);
2225                                var percentage_complete = ((total_blocks - remaining_blocks) / total_blocks);
2226                                $('.panel_footer_revealable_link .load-more-progress-bar', this).css('transform', 'scaleX(' + percentage_complete + ')');
2227	                            
2228	                            $(this).find('.link_more button').unbind('click.records_grid').bind('click.records_grid', function() {
2229	                                
2230	                                var link_original_top_offset = $(this).offset().top - ($(window).height() / 4);
2231	                                var rows_to_reveal = ($(this).closest('.records_grid').attr('data-rows-to-reveal') && typeof $(this).closest('.records_grid').attr('data-rows-to-reveal') != 'undefined' ? $(this).closest('.records_grid').attr('data-rows-to-reveal') : 6);
2232	                                
2233	        						if (window.site.device.breakpoint() == 1) {
2234										var rows_to_reveal = rows_to_reveal * 2;
2235	        						}
2236	        						
2237	                                $('body').addClass('scroll_event_disabled');
2238	                                
2239                                    $(this).closest('.records_grid').each(function() {
2240                                        $('.item.revealable:lt(' + rows_to_reveal + '), .item.revealable-temp', this).removeClass('revealable revealable-temp');
2241                                    });
2242	                                
2243	                                var remaining_revealable_items = $(this).closest('.records_grid').find('.item.revealable', this).length;
2244	                                var remaining_blocks = Math.ceil(remaining_revealable_items / rows_to_reveal);
2245	                               // console.log(total_blocks - remaining_blocks);
2246	                                $(this).closest('.panel_footer_revealable_link').find('.current-block').text(total_blocks - remaining_blocks);
2247	                                
2248	                                var percentage_complete = ((total_blocks - remaining_blocks) / total_blocks);
2249	                                $(this).closest('.panel_footer_revealable_link').find('.load-more-progress-bar').css('transform', 'scaleX(' + percentage_complete + ')');
2250	                                
2251	                                if (remaining_revealable_items == 0) {
2252	                                    $(this).closest('.panel_footer_revealable_link').addClass('disabled');
2253	                                }         
2254	                                
2255                                    window.site.commands.scrollto(link_original_top_offset, function() {
2256                                        $('body').removeClass('scroll_event_disabled');
2257                                        $(window).trigger('scroll');
2258                                    });
2259                                    
2260	                                $(window).trigger('resize');
2261	                                return false;
2262	                            });
2263	                        }
2264	                    }
2265	        		});
2266
2267	        		window.site.layout.grids.filters();
2268        		},
2269
2270        		filters: function() {
2271        			$('.panel_filters').each(function() {
2272        				$('li a', this).unbind().click(function() {
2273        					$(this).closest('ul').find('li').removeClass('active');
2274        					$(this).closest('li').addClass('active');
2275        					var href = $(this).attr('href');
2276        					filter_panel_context = $(this).closest('section');
2277        					$.pageload.load(href, false, function(new_page_inner_content, element_href, new_page_main_content) {
2278		                        if (new_page_inner_content) {
2279		                            $('.filter_results', filter_panel_context)
2280		                                .addClass('filter_transition')
2281		                                .delay(400)
2282		                                .queue(function() {
2283		                                    history.replaceState({'ajaxPageLoad': true}, null, element_href);
2284
2285		                                    $('.filter_results', filter_panel_context).html(new_page_inner_content);
2286		                                    $('.filter_results', filter_panel_context).removeClass('filter_transition');
2287
2288		                                    window.site.layout.grids.init();
2289		                                    window.site.artlogic_inview.init();
2290		                                    $(window).trigger('resize');
2291		                                    $.pageload.refresh($('.filter_results', filter_panel_context));
2292
2293		                                    $(this).dequeue();
2294		                                })
2295		                            ;
2296		                        }
2297		                    });
2298        					return false;
2299        				});
2300        			});
2301        			
2302        		},
2303
2304        		resize: function() {
2305        		    
2306        		    // Esther Schipper magic grid
2307        		    
2308        		    if ($(window).width() > 459) {
2309        		        
2310            		    $('.records_grid.es_magic_columns_grid .group').each(function() {
2311                                
2312                            var $magic_grid = $(this);
2313                            var row_bottom_position = 0;
2314                            var offset_buffer = 50; // Offset buffer required as the pixel value wasn't always exact when checking the bottom values
2315                            var total_items = $('.item:not(.revealable) .list_caption_wrapper', $magic_grid).length;
2316                            var grid_rows = {};
2317                            
2318                            // Re add the force-transform class because this can get run multiple times on resize
2319                            $('.item:not(.revealable)', $magic_grid).addClass('force-transform');
2320                            
2321                            // Remove previous row classes which start with 'magic-row-'. Important for resize event
2322                            $('.item:not(.revealable)', $magic_grid).removeClass(function (index, className) {
2323                                return (className.match (/(^|\s)magic-row-\S+/g) || []).join(' ');
2324                            });
2325                            
2326                            // Reset styles - important for resize event
2327                            $('.item:not(.revealable) .list_caption_wrapper', $magic_grid).attr('style', '');
2328                            
2329                            
2330                            $('.item:not(.revealable)', $magic_grid).each(function( index ) {
2331                                
2332                                var bottom = Math.round($(this).position().top + $(this).outerHeight(true));
2333                                
2334                                // console.log(bottom + ': ' + $('.heading_title', this).text().substring(0,20));
2335                                
2336                                // Detect if item is on a new row or not by seeing if the bottom position is much larger (further down the page)
2337                                if (bottom > (row_bottom_position - offset_buffer) && bottom < (row_bottom_position + offset_buffer)) {
2338                                    
2339                                    // Add to current row
2340                                    grid_rows[row_bottom_position].push($(this));
2341                                    
2342                                } else {
2343                                    
2344                                    // New row
2345                                    
2346                                    // Before just assuming it's a  new row - check to see if the height matches any previous rows first.
2347                                    // Display grid may move the item out of it's logical sequence to fit items into available space
2347s.
2348                                    var item_height_matches_existing_row = false;
2349                                    for (var row in grid_rows) {
2350                                        if (bottom > (Number(row) - offset_buffer) && bottom < (Number(row) + offset_buffer)) {
2351                                            // Matches an existing row
2352                                            grid_rows[row].push($(this));
2353                                            item_height_matches_existing_row = true;
2354                                            break;
2355                                        }
2356                                    }
2357                                    
2358                                    if (!item_height_matches_existing_row) {
2359                                        // Confirmed as new row
2360                                        row_bottom_position = bottom;
2361                                        grid_rows[row_bottom_position] = [$(this)];
2362                                    }
2363                                }
2364                                
2365                                // Allow transforms to take place once the calculations have occured
2366                                $(this).removeClass('force-transform');
2367                            });
2368                            
2369                            // Loop through the rows, work out the row item with largest height and set each
2370                            // item to have a min height of the tallest item in that row.
2371                            
2372                            var container_width = $magic_grid.width();
2373                            // console.log(container_width);
2374                            
2375                            var row_number = 0;
2376                            
2377                            for (var row in grid_rows) {
2378                                
2379                                var last_row_width = 0;
2380                                
2381                                if (grid_rows.hasOwnProperty(row)) {
2382                                    
2383                                    var items_in_row = grid_rows[row];
2384                                    
2385                                    if (typeof items_in_row != 'undefined' && items_in_row.length) {
2386                                        
2387                                        row_number ++;
2388                                        var tallest_row_item_height = 0;
2389                                        var current_row_item_height = 0;
2390                                        
2391                                        
2392                                        // Work out the tallest item in the row and add row number class
2393                                        for (i = 0; i < items_in_row.length; i++) {
2394                                            
2395                                            var $item = $(items_in_row[i]);
2396                                            current_row_item_height = $('.list_caption_wrapper', $item).height();
2397                                            last_row_width += $item.width();
2398                                            
2399                                            $item.addClass(('magic-row-' + row_number));
2400                                            
2401                                            
2402                                            if (current_row_item_height > tallest_row_item_height) {
2403                                                tallest_row_item_height = current_row_item_height;
2404                                            }
2405                                            
2406                                        }
2407                                        
2408                                        // Set the min heights on each item on that row.
2409                                        $(('.magic-row-' + row_number + ' .list_caption_wrapper'), $magic_grid).css('min-height', tallest_row_item_height +'px');
2410                                        
2411                                    }
2412                                }
2413                            }
2414                            
2415                            //With all the random sizes applied (1 col, 2 col etc) does the last row finish neatly square? Work this out with a width check
2416                            var full_row = (container_width / last_row_width) < 1.2 ? true : false;
2417
2418
2419                            //Remove items in wonky last row, but only if there are subsiquent further rows to reveal.. otherwise leave alone as it's just how the grid happens to finish (wonky) and we don't want to permanently chop items off.
2420                            if (!full_row && $('.item:not(.revealable)', $magic_grid).length) {
2421                                
2422                                //get very last item in final row that is not 100% width. We need to know.. is thw width incomplete because there's just no more items in the grid?
2423                                //If so, leave the raggedy end as-is.
2424                                //OR is it incomplete due to a wonky grid reveal number cutoff. Is there buffer items and we can temporarily hide this ugly row till the next reveal? 
2425                                var lastrowitem = $(('.magic-row-' + row_number), $magic_grid).last();
2426                                lastrowitem.addClass('last_magic');
2427             
2428                                if (!lastrowitem.is(':last-child')) {
2429                                    
2430                                    $(('.magic-row-' + row_number), $magic_grid).addClass('revealable-temp');
2431                                }
2432                                
2433                                
2434                                
2435                            }
2436
2437            
2438                        });
2439                        
2440                        
2441                        
2442        		    } else {
2443        		        //  Remove any min heights previously set on larger screen sizes
2444        		        $('.es_magic_columns_grid .item .list_caption_wrapper').css('min-height', '');
2445        		    }
2446                    
2447                    
2448                    
2449        			$('.records_grid.medium_grid, .records_grid.large_grid, .records_grid.full_grid').each(function() {
2450	        			$('.item', this).each(function() {
2451	        				var item_width = $(this).find('.image').width();
2452	        				var image_width = $(this).attr('data-width');
2453	        				var image_height = $(this).attr('data-height');
2454	        				var image_width_proportional = 0;
2455	        				var image_height_proportional = 0;
2456	        				if (image_width && image_height) {
2457	        				    if ($(this).find('.panel_image_slideshow').length == 0) {
2458    	        				    if (image_height > image_width) {
2459    	        				        $(this).addClass('image_proportion_portrait');
2460    	        				    } else {
2461    	        				        $(this).addClass('image_proportion_landscape');
2462    	        				    }
2463    	        				}
2464	        					var image_width_proportional = item_width / image_width;
2465	        					var image_height_proportional = image_height * image_width_proportional;
2466	        					$(this).find('.image').not('.has_video').find('img').css('max-height', '');
2467	        					if (image_height_proportional > item_width && $(this).closest('.full_grid').length == 0) {
2468	        						// Set a maximum height based on a square proportion
2469	        						var image_height_proportional = item_width;
2470	        						$(this).find('.image').not('.has_video').css('max-height', image_height_proportional);
2471	        						$(this).find('.image').not('.has_video').find('img').css('max-height', image_height_proportional);
2472	        					}
2473	        					if (image_height_proportional) {
2474	        						$(this).find('.image').not('.has_video').css('min-height', image_height_proportional);
2475	        					}
2476	        				}
2477	        			});
2478	        		});
2479	        		
2480	        		$('.panel_image_text_adjacent').each(function() {
2481        				var item_width = $(this).find('.image').width();
2482        				var image_width = $(this).attr('data-width');
2483        				var image_height = $(this).attr('data-height');
2484        				var image_width_proportional = 0;
2485        				var image_height_proportional = 0;
2486        				if (image_width && image_height) {
2487        				    if ($(this).find('.panel_image_slideshow').length == 0) {
2488        				    if (image_height > image_width) {
2489        				        $(this).addClass('image_proportion_portrait');
2490        				    } else {
2491        				        $(this).addClass('image_proportion_landscape');
2492        				    }
2493        				    }
2494        				}
2495	        		});
2496
2497					$('.records_grid.tile_grid').each(function() {
2498
2499	                    if ($('.tile_grid_original .group', this).length) {
2500
2501	                        // Check if the script has already been run before and set variables
2502	                        if ($(this).hasClass('initialised')) {
2503	                            init_rerun = true;
2504	                            existing_formatted_list_column_count = $('.tile_grid_formatted .group', this).length;
2505	                        } else {
2506	                            $(this).addClass('initialised');
2507	                            init_rerun = false;
2508	                        }
2509
2510	                        // Start initialising the new list
2511	                        init_allowed = true;
2512
2513	                        $('.tile_grid_original', this).removeClass('hidden');
2514
2515	                        tile_list_instance = $(this);
2516	                        tile_list_width = $(this).width();
2517	                        tile_list_column_width = Math.floor($('.tile_grid_original .group', this)[0].getBoundingClientRect().width + parseInt($('.tile_grid_original .group', this).css('margin-left')) + parseInt($('.tile_grid_original .group', this).css('margin-right')));
2518	                        var column_count = 3;
2519	                        var column_count_calculated = Math.floor(tile_list_width / tile_list_column_width);
2520	                        if (column_count_calculated < 7) {
2521	                            var column_count = column_count_calculated;
2522	                        }
2523
2524	                        if (init_rerun) {
2525	                            // If the script is being run again, check if the column count is different to before. If not, stop the list from being rebuilt.
2526	                            if (existing_formatted_list_column_count == column_count) {
2527	                                init_allowed = false;
2528	                            }
2529	                        }
2530
2531	                        $('.tile_grid_original', this).addClass('hidden');
2532
2533	                        if (init_allowed) {
2534	                            var columns = {}
2535	                            var fixed_list_order = $(this).closest('.tile_grid').attr('data-list-order') == 'fixed' ? true : false;
2536	                            column_loop = 0;
2537	                            column_count = Array(column_count).length;
2538	                            $.each(Array(column_count), function(index, value) {
2539	                                columns[index] = {'height': 0, 'objects': []};
2540	                            });
2541	                            $('.tile_grid_original .item', this).each(function() {
2542	                                if (!$(this).attr('data-width') || !$(this).attr('data-height')) {
2543	                                	$(this).attr('data-width', '400');
2544	                                	$(this).attr('data-height', '400');
2545	                                }
2546                                    var height_to_width_factor = parseInt($(this).attr('data-width')) / tile_list_column_width;
2547                                    var relative_item_height = Math.ceil(parseInt($(this).attr('data-height')) / height_to_width_factor);
2548                                    
2549                                    if (fixed_list_order) {
2550                                    	// Fixed order, do not automatically find lowest height
2551	                                    lowest_height_index = column_loop;
2552                                    	column_loop = column_loop + 1;
2553	                                    if (column_loop >= column_count) {
2554                                    		column_loop = 0;
2555	                                    }
2556                                    } else {
2557                                    	// Dynamic order based on shortest column height
2558	                                    lowest_height_index = 0;
2559	                                    loop_current_lowest_height = columns[0]['height'];
2560	                                    $.each(columns, function(index, value) {
2561	                                        if ((value.height < loop_current_lowest_height)) {
2562	                                            lowest_height_index = index;
2563	                                            loop_current_lowest_height = value.height;
2564	                                        }
2565	                                    });
2566                                    }
2567                                    columns[lowest_height_index]['height'] = columns[lowest_height_index]['height'] + relative_item_height;
2568                                    columns[lowest_height_index]['objects'].push($(this).clone().find('.video_inline').remove().end());
2569	                            });
2570
2571	                            $('.tile_grid_formatted', tile_list_instance).html('');
2572	                            $.each(columns, function(index, value) {
2573	                                $('.tile_grid_formatted', tile_list_instance).append('<div class="group"></div>');
2574	                                $('.tile_grid_formatted', tile_list_instance).find('.group:last-child').append(value.objects);
2575	                            });
2576	                            $('.tile_grid_formatted', tile_list_instance).find('.group:last-child').addClass('last');
2577
2578					            $('.tile_grid_formatted', tile_list_instance).find('.group').each(function() {
2579					                if ($(this).closest('.tile_grid').attr('data-initial-items') == '0') {
2580
2581					                } else if (parseInt($(this).closest('.tile_grid').attr('data-initial-rows'))) {
2582					                    var initial_items_per_column = $(this).closest('.tile_grid').attr('data-initial-rows');
2583					                    if (window.site.device.breakpoint() <= 2) {
2584					                    	var initial_items_per_column = parseInt(initial_items_per_column) * 3;
2585					                    }
2586					                    $('.item', this).addClass('revealable');
2587					                    $('.item:lt(' + initial_items_per_column + ')', this).removeClass('revealable');
2588					                } else {
2589					                    var initial_items_per_column = window.site.lists.tile_list_options().initial_items_per_column;
2590					                    if (window.site.device.breakpoint() <= 2) {
2591					                    	var initial_items_per_column = parseInt(initial_items_per_column) * 3;
2592					                    }
2593					                    $('.item', this).addClass('revealable');
2594					                    $('.item:lt(' + initial_items_per_column + ')', this).removeClass('revealable');
2595					                }
2596					            });
2597
2598					            // Re-initialise functions necessary on the newly created tile list
2599					            window.site.artlogic_inview.init();
2600					            $.pageload.refresh(tile_list_instance);
2601					            window.site.overlays.enquire.setup();
2602					            window.cart.add_to_cart($(tile_list_instance).find('.store_item .store_item_add_to_cart'));
2603	                        }
2604	                    }
2605
2606						// Set the heights of each image based on the proportion, this defines the available area before the images have loaded
2607	        			$('.tile_grid_formatted .item', this).each(function() {
2608	        				var item_width = $(this).find('.image').width();
2609	        				var image_width = $(this).attr('data-width');
2610	        				var image_height = $(this).attr('data-height');
2611	        				var image_width_proportional = 0;
2612	        				var image_height_proportional = 0;
2613	        				if (image_width && image_height) {
2614	        					var image_width_proportional = item_width / image_width;
2615	        					var image_height_proportional = image_height * image_width_proportional;
2616	        					if (image_height_proportional) {
2617	        						$(this).find('.image').css('min-height', image_height_proportional);
2618	        					}
2619	        				}
2620	        			});
2621
2622						// If there are as many or less items than there are columns, align the items by the bottom of each image
2623						if ($('.tile_grid_formatted .group', this).length >= $('.tile_grid_formatted .item', this).length) {
2624			        		$('.tile_grid_formatted .item', this).each(function() {
2625		        				var this_image_height = $(this).find('.image').height();
2626		        				$(this).closest('.tile_grid_formatted').find('.item').each(function() {
2627	        						if ($(this).find('.image').height() < this_image_height) {
2628	        							$(this).find('.image').css('min-height', this_image_height);
2629	        						}
2630		        				});
2631		        			});
2632						}
2633	                });
2634
2635
2636					// Aligned grid format
2637
2638	        		$('.records_grid.standard_grid').each(function() {
2639
2640	        			initial_rows = $(this).attr('data-initial-rows') && typeof $(this).attr('data-initial-rows') != 'undefined' ? $(this).attr('data-initial-rows') : false;
2641	        			
2642	                    if (window.site.device.breakpoint() <= 2) {
2643	                    	initial_rows = parseInt(initial_rows) * 3;
2644	                    }
2645	                    
2646	                    row_number = 0;
2647	        			row_offset = 0;
2648	        			
2649		        		$('.item', this).each(function() {
2650		        		    // $(this).removeClass('revealable');
2651	        				// Find adjacent elements
2652	        				var offset_top = $(this).offset().top;
2653	        				var this_image_height = $(this).find('.image').height();
2654	        				if (offset_top > row_offset) {
2655	        					row_number = row_number + 1;
2656	        					row_offset = offset_top;
2657	        				}
2658	        				$(this).parent().find('.item').each(function() {
2659	        					if ($(this).offset().top == offset_top) {
2660	        			// 			$(this).attr('data-row-number', row_number);
2661	        						if ($(this).find('.image').height() < this_image_height) {
2662	        							$(this).find('.image').css('min-height', this_image_height);
2663	        						}
2664	        					}
2665	        				});
2666	        			});
2667	        			$('.item', this).not('.revealed').each(function() {
2668	        				// Hide revealable elements
2669
2670	        				var row_number = $(this).attr('data-row-number');
2671	        				if (false && row_number && parseInt(row_number) > parseInt(initial_rows)) {
2672    							$(this).addClass('revealable');
2673    						}
2674    						if (row_number) {
2675    						    prelude_tallest_height = 0;
2676    						    h3_tallest_height = 0;
2677    						    subtitle_tallest_height = 0;
2678    						    caption_tallest_height = 0;
2679    						    this_instance = $(this);
2680    						    $(this).closest('.records_grid').find('.item[data-row-number="' + row_number + '"] .list_caption_wrapper').find('h3, div').css('min-height', '');
2681    						    
2682            				    if (false && window.site.device.breakpoint() > 2) {
2683            						$(this).closest('.records_grid').find('.item[data-row-number="' + row_number + '"] .list_caption_wrapper').each(function() {
2684            						    if ($(this).find('.prelude').height() > prelude_tallest_height) {
2685            						        prelude_tallest_height = $(this).find('.prelude').height();
2686            						    }
2687            						    if ($(this).find('h3').height() > h3_tallest_height) {
2688                						    h3_tallest_height = $(this).find('h3').height();
2689            						    }
2690            						    if ($(this).find('.subtitle').height() > h3_tallest_height) {
2691                						    subtitle_tallest_height = $(this).find('.subtitle').height();
2692            						    }
2693            						    if ($(this).find('.caption').height() > caption_tallest_height) {
2694            						        caption_tallest_height = $(this).find('.caption').height();
2695            						    }
2696            						}).promise().done(function() {
2697            						    $(this_instance).closest('.records_grid').find('.item[data-row-number="' + $(this_instance).attr('data-row-number') + '"] .list_caption_wrapper').each(function() {
2698            						        $(this).find('.prelude').css('min-height', prelude_tallest_height);
2699            						        $(this).find('h3').css('min-height', h3_tallest_height);
2700            						        $(this).find('.subtitle').css('min-height', subtitle_tallest_height);
2701            						        $(this).find('.caption').css('min-height', caption_tallest_height);
2702            						    });
2703            						});
2704            				    }
2705    						}
2706	        			});
2707	        		});
2708	        		
2709					$('.works_grid .item, .standard_grid .item, .medium_grid .item, .large_grid .item').unbind()
2710						// tile mouse actions
2711						.each(function() {
2712	        				var item_width = $(this).find('.image').width();
2713	        				var image_width = $(this).attr('data-width');
2714	        				var image_height = $(this).attr('data-height');
2715	        				var image_width_proportional = item_width / image_width;
2716	        				var image_height_proportional = image_height * image_width_proportional;
2717	        				var aspect_ratio = image_height / image_width;
2718	        				
2719	        				if ( $('.image img', this).css('object-fit') != 'cover') {
2720	        			        $('.image img', this).css("min-height", image_height_proportional);
2721	        				}
2722	        				
2723            				if (image_width && image_height) {
2724            				    if (image_height > image_width) {
2725            				        $(this).addClass('image_proportion_portrait');
2726            				    } else {
2727            				        $(this).addClass('image_proportion_landscape');
2728            				    }
2729            				}
2730						})
2731						.on('mouseover', function(){
2732							var image_width = $(this).find('.image').width();
2733							var scale = '1.02';
2734							if (image_width > 400) {
2735								var scale = '1.01';
2736							}
2737							if (image_width > 600) {
2738								var scale = '1.05';
2739							}
2740							//$(this).find('.image img').css({'transform': 'scale(' + scale + ')'});
2741						})
2742						.on('mouseout', function(){
2743							//$(this).find('.image img').css({'transform': 'scale(1)'});
2744						})
2745						.on('mousemove', function(e){
2746							// Move image around when moving the mouse $(this).find('.image img').css({'transform-origin': ((e.pageX - $(this).offset().left) / $(this).width()) * 100 + '% ' + ((e.pageY - $(this).offset().top) / $(this).height()) * 100 +'%'});
2747						})
2748					;
2749        		}
2750        	},
2751        	
2752        	flow_grid: {
2753        	    
2754        	    init: function() {
2755                    
2756                    window.site.layout.flow_grid.flow_list_setup();
2757                    var resize_timeout;
2758                    var last_window_width = $(window).width();
2759                    $(window).resize(function() {
2760                        clearTimeout(resize_timeout);
2761                        resize_timeout = setTimeout(function() {
2762                            if ($(window).width() !== last_window_width) {
2763                                last_window_width = $(window).width();
2764                                window.site.layout.flow_grid.flow_list_init();
2765                                window.site.layout.flow_grid.flow_list_after_resize($('.flow_grid'));
2766                            }
2767                        },400);
2768                    });
2769        	    },
2770                
2771                flow_list_setup: function(context) {
2772                    if (context && typeof context != 'undefined') {
2773                        var context = context;
2774                    } else {
2775                        var context = 'body';
2776                    }
2777                    $('.flow_grid:not(.flow_grid_setup_initialised)', context).each(function() {
2778                        $(this).addClass('flow_grid_setup_initialised');
2779                        var original_html = $(this).html();
2780                        $(this).html('');
2781                        $(this).append('<div class="flow_list_formatted"></div>');
2782                        $(this).append('<div class="flow_list_original"></div>');
2783                        $('.flow_list_original', this).html(original_html).css('visibility', 'hidden');
2784                    });
2785                    window.site.layout.flow_grid.flow_list_init(context);
2786                },
2787                
2788                flow_list_format: function($flow_list_formatted,target_height,column_count,row_class_to_target) {
2789                    
2790                    var row_heights = [];
2791                    var tallest_height = 0;
2792                    var cur_tallest_height = 0;
2793                    var row_count = 0;
2794                    
2795                    // row_class_to_target is a class which has been added to specific rows and only those rows should be formatted
2796                    // For example when ajax load more button is pressed we only want to format the new/modified rows.
2797                    row_class_to_target = (typeof row_class_to_target !== 'undefined') ?  row_class_to_target : '.flow_list_row';
2798                    
2799                    // Process formatted flow list
2800                    $flow_list_formatted.find(row_class_to_target).each(function() {
2801        
2802                        var $this = $(this);
2803                        row_count += 1;
2804                        var items = $this.find(".item");
2805                        var total_margin = 0;
2806                        var items_array = items.get();
2807                        var combinedWidth = items_array.reduce(function(sum, item) {  // .get returns the jQuery object's elements as an array
2808                        
2809                            var scaled_width;
2810                            if ("width" in item.dataset && "height" in item.dataset) {
2811                                var data_width = item.dataset.width;
2812                                var data_height = item.dataset.height;
2813                                var scale_ratio = target_height / data_height;
2814                                var scaled_width = data_width * scale_ratio;
2815                                var style = window.getComputedStyle(item);
2816                                var marginLeft = parseInt(style.getPropertyValue('margin-left'));
2817                                var marginRight = parseInt(style.getPropertyValue('margin-right'));
2818                                
2819                                total_margin += (marginLeft + marginRight);
2820                                
2821                            } else {
2822                                console.warn('flow_list_init: Width and height of each image is required as a data attribute for this script to work.');
2823                            }
2824                            
2825                            return sum + scaled_width;
2826                            
2827                        }, 0);
2828                        
2829                        var diff = ($this.width() - total_margin) / combinedWidth;
2830                        var final_item_height = (target_height - 1) * diff; // 999 allows 1 px of wiggle room, in case it's too wide by subpixels
2831                        
2832                        // Add all of the rows except the last one to the row_heights list.
2833                        // When we calculate the average row height later, we don't want to use the last row as it can be an anomaly
2834                        if (row_count != $flow_list_formatted.find(row_class_to_target).length) {
2835                            row_heights.push(final_item_height);
2836                        }
2837                        
2838                        // Get the current tallest height or if no current tallest - get target height
2839                        var cur_tallest_height = ((tallest_height) ? tallest_height : target_height);
2840                        if (((items_array.length < (column_count - 1) && items_array.length == 1) && (final_item_height > cur_tallest_height)) || (items_array.length == 1 && $(this).closest('.flow_grid').hasClass('disable-expand-single-item'))) { 
2841                            
2842                            // - For the last row, use the average height of the other rows to determine the height if there are not enough items to fill all the columns
2843                            // - We check against (column_count - 1) because we want the items to fill the full width of the row if there is only one less item.
2844                            // - If the column number is set to 2, we don't want a singular item on the last row to go full width because it would be too big. Therefore we use the average height.
2845                            
2846                            var total = 0;
2847                            for(var i = 0; i < row_heights.length; i++) {
2848                                total += row_heights[i];
2849                            }
2850                            var average_row_height = total / row_heights.length;
2851                            final_item_height = average_row_height
2852                            
2853                        } else {
2854                            if (final_item_height > tallest_height){
2855                                tallest_height = final_item_height;
2856                            }
2857                        }
2858                        
2859                        items.find('.image').height(final_item_height); 
2860                        items_array.forEach(function(item, index) {
2861                            var final_height_scale = final_item_height / item.dataset.height;
2862                            $(item).width(item.dataset.width * final_height_scale);
2863                        });
2864        
2865                        $this.find('ul:last-child').addClass('last');
2866                        // Video inline not currently supported
2867                        $this.find('.video_inline').remove();
2868                        $this.removeClass('row_requires_formatting');
2869                    });
2870                    
2871                },
2872                
2873                flow_list_create_rows: function(flow_list_formatted_instance, list_items_to_be_added, column_count) {
2874                    
2875                    var column_count_default = column_count;
2876                    var dynamic_columns = typeof $(flow_list_formatted_instance).closest('.flow_grid').attr('data-advanced-layout') != 'undefined' ? $(flow_list_formatted_instance).closest('.flow_grid').attr('data-advanced-layout') : false;
2877                    var dynamic_columns_format = [];
2878                    if (dynamic_columns && window.site.device.breakpoint() > 2) {
2879                        var dynamic_columns_split = dynamic_columns.split('-');
2880                        var loopcount = 0;
2881                        var i;
2882                        for (i = 0; i < dynamic_columns_split.length; i++) {
2883                            var iterations = Array(parseInt(dynamic_columns_split[i])).fill();
2884                            for (i2 = 0; i2 < iterations.length; i2++) {
2885                                dynamic_columns_format.push(parseInt(dynamic_columns_split[i]));
2886                                var loopcount = loopcount + 1;
2887                            }
2888                        }
2889                    }
2890                    
2891                    var columns = {}
2892                    var column_split = Math.ceil(list_items_to_be_added.length / column_count) + 10;
2893                    $.each(Array(column_split), function(index, value) {
2894                        columns[index] = {'objects': [], 'full': false};
2895                    });
2896                    list_items_to_be_added.each(function(item_index) {
2897                        var lowest_height_index = 0;
2898                        if (dynamic_columns) {
2899                            if (dynamic_columns_format.length > item_index) {
2900                                column_count = parseInt(dynamic_columns_format[item_index]);
2901                            } else {
2902                                column_count = parseInt(column_count_default);
2903                            }
2904                        }
2905                        if (columns[0] && typeof columns[0] != 'undefined') {
2906                            column_full = false;
2907                            $.each(columns, function(index, value) {
2908                                if (this.objects.length < column_count && !this.full) {
2909                                    lowest_height_index = index;
2910                                    if (this.objects.length+1 == column_count) {
2911                                        column_full = true;
2912                                    }
2913                                    return false;
2914                                } 
2915                            });
2916                            columns[lowest_height_index]['objects'].push($(this).clone().find('.video_inline').remove().end());
2917                            if (column_full) {
2918                                columns[lowest_height_index]['full'] = true;
2919                            }
2920                        }
2921                    });
2922                    $.each(columns, function(index, value) {
2923                        flow_list_formatted_instance.append('<div class="group flow_list_row row_requires_formatting"></div>');
2924                        flow_list_formatted_instance.find('.group:last-child').append(value.objects);
2925                    });
2926                    
2927                },
2928                
2929                flow_list_init: function(context) {
2930                    
2931                    if (context && typeof context != 'undefined') {
2932                        var context = context;
2933                    } else {
2934                        var context = 'body';
2935                    }
2936                    
2937                    $('.flow_grid', context).each(function() {
2938                        
2939                        var $flow_list = $(this);
2940                        var $flow_list_original = $('.flow_list_original .group', this);
2941                        var init_rerun
2942                        var existing_formatted_list_column_count
2943                        
2944                        if ($flow_list_original.length) {
2945                            
2946                            $('img.click_event_added', $flow_list_original).removeClass('click_event_added');
2947                            
2948                            // Check if the script has already been run before and set variables
2949                            if ($(this).hasClass('initialised')) {
2950                                init_rerun = true;
2951                                
2952                                existing_formatted_list_column_count = $('.flow_list_formatted .group.flow_list_row:first .item', this).length;
2953    
2954                            } else {
2955                                $(this).addClass('initialised');
2956                                init_rerun = false;
2957                            }
2958        
2959                            // Start initialising the new list
2960                            var init_allowed = true;
2961                            $flow_list_original.removeClass('hidden');
2962                            var flow_list_instance = $(this);
2963                            var $flow_list_formatted = $('.flow_list_formatted', flow_list_instance);
2964                            var flow_list_width = $flow_list.outerWidth();
2965                            var item_widths = $flow_list_original.find('.item').first().outerWidth();
2966                            var number_of_items_in_grid = $flow_list_original.find('.item').length;
2967                            var column_count_calculated = Math.round((flow_list_width / item_widths) * 10) / 10;
2968                            var column_count = Math.floor(column_count_calculated);
2969                            
2970                            // If we can't detect any columns, do not initialise
2971                            if (!column_count) {
2972                                init_allowed = false
2973                            }
2974    
2975                            // If there are less items in the grid that the number of columns, set the column number to the number of items
2976                            // This needs to be done to stop the grid from trying to be formatted on resize etc
2977                            if (column_count > number_of_items_in_grid) {
2978                                column_count = number_of_items_in_grid
2979                            }
2980                            $flow_list_formatted.attr('data-column-count', column_count);
2981                            
2982                            if (init_rerun) {
2983                                // If the script is being run again, check if the column count is different to before. If not, stop the list from being rebuilt.
2984                                if (existing_formatted_list_column_count == column_count) {
2985                                    init_allowed = false;
2986                                }
2987                            }
2988        
2989                            $flow_list_original.addClass('hidden');
2990        
2991                            var target_height = 600; //MOSTLY ARBITRARY - JUST A UNIFYING NUMBER. IS THE MAX HEIGHT OF 
2992        
2993                            if (init_allowed) {
2994                                
2995                                $flow_list_formatted.html('');
2996                                
2997                                window.site.layout.flow_grid.flow_list_create_rows($flow_list_formatted, $flow_list_original.find('.item'), column_count);
2998                                window.site.layout.flow_grid.flow_list_format($flow_list_formatted,target_height,column_count);
2999                                window.site.layout.flow_grid.flow_list_after_init($(this));
3000                                
3001                            } else {
3002                                //just run the formatting to ensure the sizes are correct
3003                                window.site.layout.flow_grid.flow_list_format($flow_list_formatted,target_height,column_count);
3004                            }
3005                        }
3006                    });
3007                    
3008                },
3009                
3010                flow_list_append_refresh: function(flow_list_instance) {
3011                    
3012                    // This function gets called when new items get appended to the list - for example when the ajax load more button gets pressed.
3013                    
3014                    var $flow_list_original = $('.flow_list_original', flow_list_instance);
3015                    var $flow_list_formatted = $('.flow_list_formatted', flow_list_instance);
3016                    var column_count = $flow_list_formatted.attr('data-column-count');
3017                    var last_row_column_count = $flow_list_formatted.find('.group:last .item').length;
3018                    var $last_row_before_new_content = $flow_list_formatted.find('.group:last');
3019                    var $ajax_loaded_list_items = $flow_list_original.find('.group .item.ajax-loaded-list-item').not(".pageload-refreshed");
3020                    
3021                    // Work out if the last row before adding the new items needs new items added to it to fill the row and then adds them.
3022                    // For example if the last row had 2 items and the column count was 4, we would need to add 2 of the new ajax loaded items into that already existing row to fill it.
3023                    if (last_row_column_count < column_count) {
3024                        
3025                        // Don't scroll list position if we are adding new items to the last row.
3026                        flow_list_instance.addClass('no_scroll_after_load');
3027                        // Add class so width & height of existing items in the last row can be transitioned
3028                        $last_row_before_new_content.find('.item').addClass('transition_size');
3029                        // Calculate how many new items need to be added to the previously last row.
3030                        var number_of_items_required_to_complete_last_row 
3030= column_count - last_row_column_count;
3031                        // Get the required amount of items from the new ajax loaded items list.
3032                        var items_to_fill_spaces = $ajax_loaded_list_items.slice(0,number_of_items_required_to_complete_last_row);
3033                        
3034                        // Insert the new items into what previously was the existing last row.
3035                        items_to_fill_spaces.clone().insertAfter($last_row_before_new_content.find('.item:last'));
3036                        
3037                        // Add a class to this row so we know it requires reformatting it because the items within it have changed.
3038                        $last_row_before_new_content.addClass('row_requires_formatting');
3039                        
3040                        // Set the ajax loaded list of items to not include the ones which have just been added to the existing row.
3041                        $ajax_loaded_list_items = $ajax_loaded_list_items.slice(number_of_items_required_to_complete_last_row);
3042                        
3043                        // Remove class once size has transitioned
3044                        setTimeout(function(){
3045                            $flow_list_formatted.find('.item.transition_size').removeClass('transition_size');
3046                        }, 1500);
3047                    }
3048                    
3049                    window.site.layout.flow_grid.flow_list_create_rows($flow_list_formatted, $ajax_loaded_list_items, column_count);
3050                    window.site.layout.flow_grid.flow_list_format($flow_list_formatted,600,column_count,'.flow_list_row.row_requires_formatting');
3051                    
3052                },
3053                
3054                flow_list_after_init: function(context) {
3055		            window.site.artlogic_inview.init();
3056		            $.pageload.refresh($(context));
3057		            window.site.overlays.enquire.setup();
3058		            window.cart.add_to_cart($(context).find('.store_item .store_item_add_to_cart'));
3059                },
3060                flow_list_after_resize: function(context) {
3061		            window.site.artlogic_inview.init();
3062		            $.pageload.refresh($(context));
3063		            window.site.overlays.enquire.setup();
3064		            window.cart.add_to_cart($(context).find('.store_item .store_item_add_to_cart'));
3065		            window.site.misc.extended_click_area();
3066                    $(window).trigger('resize');
3067                },
3068    
3069                set_item_min_height: function($element) {
3070                    // Set the size of the image container as a placeholder for lazyload
3071                    var item_width = $element.find('.image').width();
3072    				var image_width = $element.attr('data-width');
3073    				var image_height = $element.attr('data-height');
3074    				var image_width_proportional = 0;
3075    				var image_height_proportional = 0;
3076    				if (image_width && image_height) {
3077    					var image_width_proportional = item_width / image_width;
3078    					var image_height_proportional = image_height * image_width_proportional;
3079    					if (image_height_proportional) {
3080    						$element.find('.image').css('min-height', image_height_proportional);
3081    					}
3082    				}
3083                }
3084        	    
3085        	},
3086
3087        	textillate: function() {
3088
3089        		$('.text_animate').textillate({
3090	              // the default selector to use when detecting multiple texts to animate
3091	              selector: '.texts',
3092
3093	              // enable looping
3094	              loop: false,
3095
3096	              // sets the minimum display time for each text before it is replaced
3097	              minDisplayTime: 2000,
3098
3099	              // sets the initial delay before starting the animation
3100	              // (note that depending on the in effect you may need to manually apply
3101	              // visibility: hidden to the element before running this plugin)
3102	              initialDelay: 0,
3103
3104	              // set whether or not to automatically start animating
3105	              autoStart: true,
3106
3107	              // in animation settings
3108	              in: {
3109	                // set the effect name
3110	                effect: 'fadeInLeft',
3111
3112	                // set the delay between each character
3113	                delay: 12,
3114
3115	                // set to true to animate all the characters at the same time
3116	                sync: false,
3117
3118	                // randomize the character sequence
3119	                // (note that shuffle doesn't make sense with sync = true)
3120	                shuffle: false,
3121
3122	                // reverse the character sequence
3123	                // (note that reverse doesn't make sense with sync = true)
3124	                reverse: false,
3125
3126	                // callback that executes once the animation has finished
3127	                callback: function () {}
3128	              },
3129
3130	              // out animation settings.
3131	              out: {
3132	                // set the effect name
3133	                effect: 'fadeOutDown',
3134
3135	                // set the delay between each character
3136	                delay: 2,
3137	                sync: false,
3138	                shuffle: false,
3139	                reverse: false,
3140	                callback: function () {}
3141	              },
3142
3143	              // callback that executes once textillate has finished
3144	              callback: function () {},
3145
3146	              // set the type of token to animate (available types: 'char' and 'word')
3147	              type: 'char'
3148	            });
3149
3150        	},
3151        	
3152        	textillate_homemade: function() {
3153        	    
3154        	    
3155        	    $(".fancy_title").each(function(){
3156        	        var animationDelay = 600;
3157        	        $this = $(this);
3158        	        $this.lettering().lettering('words');
3159        	        
3160        	        var length = $this[0].children.length;
3161        	        
3162        	        //timing option
3163        	       // var animation_length = 900;
3164        	       // var animationGap = animation_length / length;
3165        	        
3166        	        //standard option
3167        	        var animationGap = 70;
3168        	        
3169                    for(var i = 0; i < length; i++) {
3170                        $this[0].children[i].style['transition-delay'] = animationDelay + (animationGap * i) + 'ms';
3171                    }
3172        	    });
3173        	},
3174
3175            shutter_hero: {
3176                
3177                loaded: function() {
3178                    
3179                    // $('#wipe_slideshow_wrapper').find('img').load(function() {
3180                    //   $('#wipe_slideshow_wrapper').addClass('initialised');
3181                    // });
3182                    
3183                    // setTimeout(function() {
3184                    //     $('#wipe_slideshow_wrapper').addClass('initialised');
3185                    // }, 1000);
3186                    
3187                },
3188                init: function() {
3189                    
3190                    // window.site.layout.shutter_hero.loaded();
3191                    var timer;
3192                    var last_item = 1;
3193                    var direction_class = '';
3194                    $('.wipe-slideshow ul li').first().addClass('active');
3195                    
3196                    var $wrapper = $('#wipe_slideshow_wrapper');
3197                    var active_width = $('.wipe-slideshow ul li.active').width();
3198                    var active_height = $('.wipe-slideshow ul li.active').height();
3199                 
3200                    $('#hero #wipe_slideshow_wrapper .shutter-image').width(active_width).height(active_height);
3201                    
3202                    var resizeTimer;
3203                    var previous_width = $(window).width();
3204                    
3205                    $(window).on('resize', function(e) {
3206                      clearTimeout(resizeTimer);
3207                      resizeTimer = setTimeout(function() {
3208                        if ($(window).width() != previous_width)  {
3209                            var active_width = $('.wipe-slideshow ul li.active').width();
3210                            var active_height = $('.wipe-slideshow ul li.active').height();
3211                           $('#hero #wipe_slideshow_wrapper .shutter-image').width(active_width).height(active_height);
3212                        }
3213                      }, 250);
3214                    
3215                    });
3216                    
3217                    setTimeout(function() {
3218                        $wrapper.removeClass('block-interaction');
3219                    }, 1500);
3220                 
3221                 
3222                    // $('.wipe-slideshow ul li img').width(active_width + 120).height(active_height);
3223                    
3224                    // $wrapper.addClass('block-interaction');
3225                    
3226                    // $('.wipe-slideshow ul li:first-child').addClass('active from_left');
3227                    
3228                    if ( typeof ontransitionend != 'undefined' ){
3229                        $('.wipe-slideshow').addClass('transitionend-supported');
3230                    }
3231                    
3232                    
3233                    $('.wipe-slideshow ul li').on('click mouseover', function () {
3234                        
3235                        if ( $('.wipe-slideshow').hasClass('transitionend-supported') ) {
3236                            $wrapper.addClass('block-links');
3237                        }
3238                        var $item = $(this);
3239                        
3240                        
3241                        if (!$wrapper.hasClass('block-interaction')) {
3242                            
3243                            clearTimeout(timer);
3244                            timer = setTimeout(function(){
3245            
3246                                var this_item = $item.attr('data-rel');
3247                                if (this_item > last_item) {
3248                                   direction_class = 'from_left'     
3249                                } else if (this_item < last_item){
3250                                    direction_class = 'from_right'        
3251                                }
3252                                var last_item_elem = $('.wipe-slideshow ul li').index(last_item - 1)
3253                                
3254                                last_item = this_item; 
3255                                
3256                                $item.addClass('active').addClass(direction_class).siblings().removeClass('active from_left from_right');
3257                                
3258                                $('.wipe-slideshow li:not(.active)').find('.text_animated').removeClass('text_animated');
3259                              
3260                                if ( $('.wipe-slideshow').hasClass('transitionend-supported') ) {
3261                                    
3262                                    $item[0].addEventListener('transitionend', function() {
3263                                        
3264                                        $wrapper.addClass('block-links');
3265                                    });
3266                                }
3267                            }, 300);
3268                        }
3269                    });
3270                }
3271            },
3272            
3273            hero: {
3274
3275                init: function() {
3276
3277                    $('#hero, .hero_header').each(function() {
3278
3279                        $('#hero .slide .image').each(function() {
3280                            var related_link = $(this).closest('.slide').find('a:eq(0)');
3281                            if (related_link && typeof related_link != 'undefined' && related_link.length) {
3282                                $(this).css('cursor', 'pointer').unbind('click').bind('click', function() {
3283                                    related_link.trigger('click');
3284                                });
3285                            }
3286                        });
3287                        
3288                        $('#hero .content .content_header h1 .h1_heading, #hero .content .content_header .faux_h1 .h1_heading').each(function() {
3289                            if (!$('#hero, .hero_header').hasClass('hero_text_size_1') && !$('#hero, .hero_header').hasClass('hero_text_size_2') && !$('#hero, .hero_header').hasClass('hero_text_size_3') && !$('#hero, .hero_header').hasClass('hero_text_size_4')) {
3290                                var context = $('a', this).length ? $('a', this) : $(this);
3291                                var trimmed_text = $.trim($(context).text().replace(/ /g, '').replace(/(\r\n|\n|\r)/gm, ""));
3292                                if (trimmed_text.length > 62) {
3293                                    $(this).parent().addClass('text-length-4 text-length-limit-active');
3294                                } else if (trimmed_text.length > 42) {
3295                                    $(this).parent().addClass('text-length-3 text-length-limit-active');
3296                                } else if (trimmed_text.length > 20) {
3297                                    $(this).parent().addClass('text-length-2 text-length-limit-active');
3298                                }
3299                            }
3300                        });
3301
3302                        scroll_to_content = function() {
3303                            var scroll_offset = $('.scroll_section').not('.scroll_section_top').filter(':eq(0)').offset().top - ($(window).height() * 0.05);
3304                            setTimeout(function() {
3305                                $('html, body').on('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function(){
3306                                    $('html, body').stop();
3307                                });
3308                            }, 400);
3309                            $('html, body').animate({'scrollTop': scroll_offset}, 1200, 'easeInOutExpo', function() {
3310                                $('html, body').off('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove');
3311                            });
3312                        };
3313                        $('#hero .scroll').click(function() {
3314                            scroll_to_content();
3315                            return false;
3316                        });
3317
3318                        $('#hero .arrow').click(function() {
3319                            scroll_to_content();
3320                            return false;
3321                        });
3322                    });
3323                
3324                },
3325                
3326                custom_color_on: function() {
3327                    if (typeof $('#hero, .hero_header').attr('data-custom-ui-color') != 'undefined') {
3328                        var ui_color = $('#hero, .hero_header').attr('data-custom-ui-color')
3329                        $('#logo svg *').css('fill', ui_color).addClass('custom-fill');
3330                        $('#main_nav a').css('color', ui_color).addClass('custom-fill');
3331                        $('#menu svg *').css('fill', ui_color).css('stroke', ui_color).addClass('custom-fill');
3332                    }
3333                },
3334                
3335                custom_color_off: function() {
3336                    if ($('#logo .custom-fill').length > 0) {
3337                        $('#logo svg .custom-fill').css('fill', '').removeClass('custom-fill');
3338                        $('#main_nav .custom-fill').css('color', '').removeClass('custom-fill');
3339                        $('#menu svg .custom-fill').css('fill', '').css('stroke', '').removeClass('custom-fill');
3340                    }
3341                }
3342            }
3343
3344        },
3345
3346        scroll: {
3347
3348            smooth_scroll_enabled: false, // true
3349            smooth_scroll_active: false,
3350
3351            settings: {
3352                'scroll_section_elements': '.scroll-section',
3353                'scroll_parallax_elements': '.scroll-parallax', // Enable parallax functionality on these elements
3354                'scroll_parallax_overflow_elements': '.scroll-parallax-overflow' // List parallax elements which need to overflow e.g. full screen backgrounds
3355            },
3356
3357            init: function() {
3358                window.site.scroll.layout();
3359                window.site.scroll.smooth_scroll.init();
3360                window.site.scroll.events.init();
3361                window.site.scroll.navigation();
3362                window.site.scroll.dropdown_navigation.init();
3363            },
3364
3365            layout: function() {
3366
3367	            curslide = 0;
3368
3369                last_scroll_position = $(window).scrollTop();
3370            	$('#container_outer').removeClass('scrolling-down scrolling-up');
3371
3372                $('.pageload-content-area').each(function() {
3373                    scroll_section_index = 0;
3374                	$('.scroll_section', this).each(function() {
3375                		//$(this).css('min-height', window.site.layout.window_height());
3376            			scroll_section_index = scroll_section_index + 1;
3377                		$(this).attr('data-scrollinner-index', scroll_section_index);
3378                		$(this).addClass('section_index_' + scroll_section_index);
3379                	});
3380                });
3381
3382	            if (typeof page_intro_timeout != 'undefined') {
3383	            	clearTimeout(page_intro_timeout);
3384	            	clearTimeout(page_intro_timeout2);
3385	            }
3386	            $('#container_outer').addClass('page-intro page-intro-start');
3387	            page_intro_timeout = setTimeout(function() {
3388					$('#container_outer').addClass('page-intro-1');
3389	            }, 400);
3390	            page_intro_timeout = setTimeout(function() {
3391					$('#container_outer').removeClass('page-intro-start');
3392	            }, 1800);
3393	            page_intro_timeout2 = setTimeout(function() {
3394					$('#container_outer').removeClass('page-intro page-intro-1 page-intro-start');
3395	            }, 2800);
3396
3397	            $('#container')
3398	            	.addClass('scroll-section-setup')
3399	            	.delay(1000)
3400	            	.queue(function () {
3401			            $('#container')
3402			            	.removeClass('scroll-section-setup')
3403			            ;
3404			            $(this).dequeue();
3405	            	})
3406	            ;
3407	            
3408	            loopcount = 0;
3409	            $('.scroll_section').each(function(i) {
3410	                $(this).attr('data-scroll-index', i+1);
3411	                if (parseInt($(this).offset().top) == $(window).scrollTop()) {
3412	                    $(this).addClass('active active_completed');
3413	                }
3414	                if ($(this).find('.panel_filter_results_pending').length > 0) {
3415	                    $(this).addClass('has_pending_filters_area');
3416	                }
3417	            });
3418            },
3419
3420            events: {
3421
3422                init: function() {
3423                    
3424                    $('#container_outer').removeClass('page-top-proximity');
3425                    
3426                    last_scroll_position = 0;
3427                    scrolling_down_offset = 50;
3428                    // This improves scroll performance in chrome, why?
3429                    $(window).bind('scroll', function() {
3430	                    if ($('.artwork_hero_image_container_outer').length && !$('#popup_content .artwork_hero_image_container_outer').length) {
3431	                    	var hero_max_height = ($(window).height() - $(window).scrollTop()) + 200;
3432	                    	if (hero_max_height < 0) {
3433	                    		var hero_max_height = 0;
3434	                    	}
3435	                    	$('.artwork_hero_image_container_outer').css('max-height', hero_max_height);
3436	                    }
3437                    });
3438                    $(window).bind('scroll', window.site.throttle(50, function() {
3439                        window.site.scroll.events.run();
3440                    }));
3441                    $(window).bind('scroll', window.site.debounce(200, function() {
3442                        window.site.scroll.events.run();
3443                    }));
3444                    window.site.scroll.events.run();
3445                },
3446
3447                run: function() {
3448                    if ($(window).scrollTop() > 0) {
3449                        if (last_scroll_position > $(window).scrollTop()) {
3450                            if (last_scroll_position - 30 > $(window).scrollTop()) {
3451                                if (!$('body').hasClass('window-forced-scroll-up')) {
3452                                    if (!$('body').hasClass('page-popup-active') && !$('body').hasClass('overlay-open')) {
3453                                        $('#container_outer').addClass('scrolling-up');
3454                                        $('#container_outer').removeClass('scrolling-down');
3455                                    }
3456                                }
3457                            }
3458                        } else {
3459                            if ($(window).scrollTop() > last_scroll_position) {
3460                                if ($(window).scrollTop() > scrolling_down_offset) {
3461                                    if (!$('body').hasClass('page-popup-active') && !$('body').hasClass('overlay-open')) {
3462                                        $('#container_outer').removeClass('scrolling-up');
3463                                        $('#container_outer').addClass('scrolling-down');
3464                                        if ($('body').hasClass('dropdown-nav-active')) {
3465                                            window.site.scroll.dropdown_navigation.close();
3466                                        }
3467                                        if ($('body').hasClass('header-dropdown-active')) {
3468                                            window.site.misc.hideDropdown();
3469                                        }
3470                                    }
3471                                }
3472                            }
3473                        }
3474                    } else {
3475                        $('#container_outer').removeClass('scrolling-down scrolling-up');
3476                    }
3477                    if ($('body').hasClass('page-popup-visible')) {
3478                        $('#container_outer').removeClass('page-top');
3479                        $('body').removeClass('page-top');
3480                    } else {
3481                        if ($(window).scrollTop() > 20) {
3482                            if (!$('#container_outer').hasClass('page-scrolled')) {
3483                                $('#container_outer').addClass('page-scrolled');
3484                            }
3485                            if ($('#container_outer').hasClass('page-top')) {
3486                                $('#container_outer').removeClass('page-top');
3487                                $('body').removeClass('page-top');
3488                            }
3489                        } else {
3490                            if (!$('#container_outer').hasClass('page-top')) {
3491                                $('#container_outer').removeClass('page-scrolled');
3492                                $('#container_outer').addClass('page-top');
3493                                $('body').addClass('page-top');
3494                            }
3495                            if ($('.hero_layout_fullbleed').length) {
3496                                // $('body').addClass('content-type-reversed');
3497                                window.site.layout.hero.custom_color_on();
3498                            }
3499                            if ($('#container_outer').hasClass('page-scrolled')) {
3500                                $('#container_outer').removeClass('page-scrolled');
3501                            }
3502                        }
3503                        if ($('#hero, .hero_header').length) {
3504                            if ($(window).scrollTop() > $(window).height() / 2) {
3505                                if ($('#container_outer').hasClass('page-top-proximity')) {
3506                                    $('#container_outer').removeClass('page-top-proximity');
3507                                    $('body').removeClass('content-type-reversed');
3508                                    
3509                                    window.site.layout.hero.custom_color_off();
3510                                }
3511                            } else {
3512                                if (!$('#container_outer').hasClass('page-top-proximity')) {
3513                                    $('#container_outer').addClass('page-top-proximity');
3514                                    if ($('.hero_layout_fullbleed').length) {
3515                                        // $('body').addClass('content-type-reversed');
3516                                        window.site.layout.hero.custom_color_on();
3517                                    }
3518                                }
3519                            }
3520                        } else {
3521                            if ($(window).scrollTop() > $('.header_translations_nav_inner').outerHeight()) {
3522                                $('#container_outer').addClass('scrolled-past-translation-nav');
3523                            } else {
3524                                $('#container_outer').removeClass('scrolled-past-translation-nav');
3525                            }
3526                        }
3527                    }
3528                    window.site.scroll.subnav_active_change();
3529                    last_scroll_position = $(window).scrollTop();
3530                }
3531                    
3532            },
3533            
3534            dropdown_navigation: {
3535                init: function() {
3536            		if ($('#dropdown_nav').length) {
3537            		    $('#main_nav li').each(function() {
3538            		        var this_path_name = $(this).find('a').attr('href').replace('/', '').replace('/', '');
3539            		        $(this).attr('data-dropdown-id', this_path_name);
3540            		        if ($('#dropdown_nav .dropdown_nav_item[data-related-nav-item="' + this_path_name + '"]').length) {
3541            		            $(this).addClass('has_dropdown');
3542            		        }
3543            		    });
3544            		    
3545            		    $('.dropdown_menu_mask').unbind().bind('click', function() {
3546            		         window.site.scroll.dropdown_navigation.close();
3547            		    });
3548            		    
3549                        $('#header').addClass('dropdown-nav-not-hover');
3550                        $('#main_nav li.has_dropdown, #dropdown_nav').each(function() {
3551                            $(this).unbind('mouseover.dropnav, mouseout.dropnav').bind('mouseover.dropnav', function() {
3552                                if (!$('body').hasClass('page-transition-delay') && !$('body').hasClass('page-transition') && !$('body').hasClass('scrolling-down')) {
3553                                    
3554                                    var instance = $(this);
3555                                    
3556                                    if (typeof dropdown_nav_hover_initial_display_timeout != 'undefined') {
3557                                        clearTimeout(dropdown_nav_hover_initial_display_timeout);
3558                                    }
3559                                    if (typeof dropdown_nav_close_timeout != 'undefined') {
3560                                        clearTimeout(dropdown_nav_close_timeout);
3561                                    }
3562                                    
3563                                    var hover_open_delay = 300;
3564                                    if ($('body').hasClass('dropdown-nav-active')) {
3565                                        var hover_open_delay = 100;
3566                                    }
3567                                        
3568                                    dropdown_nav_hover_initial_display_timeout = setTimeout(function() {
3569                                
3570                                        if (typeof previous_item_timeout != 'undefined') {
3571                                            clearTimeout(previous_item_timeout);
3572                                            $('#dropdown_nav .dropdown_nav_item.active').removeClass('active animate animate-out');
3573                                            previous_item_timeout = undefined;
3574                                        }
3575                                        
3576                                        var this_dropdown_id = $(instance).attr('data-dropdown-id');
3577                                        if (this_dropdown_id && typeof this_dropdown_id != 'undefined') {
3578                                            var dropdown_element = $('#dropdown_nav .dropdown_nav_item[data-related-nav-item="' + this_dropdown_id + '"]');
3579                                            if (dropdown_element.length) {
3580                                                
3581                                                if ($('#dropdown_nav .dropdown_nav_item.active').length && this_dropdown_id != $('#dropdown_nav .dropdown_nav_item.active').attr('data-related-nav-item')) {
3582                                                    var previous_active_item = $('#dropdown_nav .dropdown_nav_item.active');
3583                                                    previous_active_item.removeClass('animate').addClass('animate-out');
3584                                                    previous_item_timeout = setTimeout(function() {
3585                                                         previous_active_item.removeClass('active animate-out');
3586                                                         previous_item_timeout = undefined;
3587                                                    }, 400, previous_active_item);
3588                                                }
3589                                                
3590                                                dropdown_element.addClass('active');
3591                                                var dropdown_element_height = dropdown_element.height();
3592                                                setTimeout(function() {
3593                                                    dropdown_element.addClass('animate');
3594                                                    $('#dropdown_nav').height(dropdown_element_height);
3595                                                }, 50, dropdown_element);
3596                                            } else {
3597                                                $('#dropdown_nav .dropdown_nav_item.animate').removeClass('animate');
3598                                                $('#dropdown_nav').height('0');
3599                                                dropdown_nav_close_timeout = setTimeout(function() {
3600                                                    $('#dropdown_nav .dropdown_nav_item.active').removeClass('active');
3601                                                }, 800);
3602                                            }
3603                                        }
3604                                     
3604       
3605                                        $(instance).addClass('hovering');
3606                                        $('body').addClass('dropdown-nav-active');
3607                                        if (typeof dropdown_nav_hover_timeout != 'undefined') {
3608                                            clearTimeout(dropdown_nav_hover_timeout);
3609                                        }
3610            
3611                                        if (typeof dropdown_nav_hover_over_timeout != 'undefined') {
3612                                            clearTimeout(dropdown_nav_hover_over_timeout);
3613                                        }
3614                                        dropdown_nav_hover_over_timeout = setTimeout(function() {
3615                                            $('body').addClass('dropdown-nav-animate');
3616                                            $('#header').addClass('dropdown-nav-hover');
3617                                            $('#header').removeClass('dropdown-nav-not-hover');
3618                                        }, 10);
3619                                        
3620                                    }, hover_open_delay, instance);
3621                                }
3622                            }).bind('mouseout.dropnav', function() {
3623                                if (window.location.search == '?fixnav=1') {
3624                                    return;
3625                                }
3626                                $(this).removeClass('hovering');
3627                                if (!$('#header.hovering').length) {
3628                                    if (typeof dropdown_nav_hover_over_timeout != 'undefined') {
3629                                        clearTimeout(dropdown_nav_hover_over_timeout);
3630                                    }
3631                                    if (typeof dropdown_nav_hover_timeout != 'undefined') {
3632                                        clearTimeout(dropdown_nav_hover_timeout);
3633                                    }
3634                                    dropdown_nav_hover_timeout = setTimeout(function() {
3635                                        window.site.scroll.dropdown_navigation.close();
3636                                    }, 1000);
3637                                }
3638                                
3639                                if (typeof dropdown_nav_hover_initial_display_timeout != 'undefined') {
3640                                    clearTimeout(dropdown_nav_hover_initial_display_timeout);
3641                                }
3642                            });
3643                        });
3644            		}
3645                },
3646                
3647                close: function() {
3648                    $('#header').removeClass('dropdown-nav-hover');
3649                    $('#header').addClass('dropdown-nav-not-hover');
3650                    $('body').removeClass('dropdown-nav-animate');
3651                    
3652                    $('#dropdown_nav .dropdown_nav_item.animate').removeClass('animate');
3653                    $('#dropdown_nav').height('0');
3654                    dropdown_nav_close_timeout = setTimeout(function() {
3655                        $('#dropdown_nav .dropdown_nav_item.active').removeClass('active');
3656                        $('body').removeClass('dropdown-nav-active');
3657                    }, 800);
3658                }
3659            },
3660
3661            navigation: function() {
3662            
3663        		$('#header #page_header').remove();
3664        		$('#header').removeClass('page-header-subsections');
3665        		$('#hero, .hero_header').removeClass('page-hero-subsections');
3666        		
3667                if ($('.scroll_section_panels').hasClass('scroll_section_panels_has_nav')) {
3668                        
3669                    if (!$('#feature_panel_section_nav').length) {
3670                        $('.scroll_section_panels:last').after('<div id="feature_panel_section_nav"><h2></h2><ul></ul></div><div id="feature_panel_section_heading"><div id="feature_panel_section_heading_content" class="splash_heading"></div></div>')
3671                    }
3672                    
3673                    if ($('#main_content h1').length) {
3674                        var page_heading_element = $('#main_content h1:eq(0)');
3675                        if ($('body').hasClass('section-home')) {
3676                            var page_heading = 'Home';
3677                        } else if (page_heading_element.find('.text_animate .texts li').length) {
3678                            var page_heading = page_heading_element.find('.text_animate .texts li:eq(0)').text();
3679                        } else {
3680                            if ($('#main_content h1:eq(0) a').length) {
3681                                var page_heading = $('#main_content h1:eq(0) a').text();
3682                            } else {
3683                                var page_heading = $('#main_content h1:eq(0)').text();
3684                            }
3685                        }
3686                        $('#feature_panel_section_nav h2').html(page_heading);
3687                    }
3688    
3689                    if ($('#feature_panel_section_nav').length && !$('#feature_panel_section_nav').hasClass('side_nav_filters')) {
3690                        jQuery.fn.reverse = [].reverse;
3691                        $('.feature_panels section').each(function() {
3692                            if (!$(this).hasClass('mobile-small-only')) {
3693                                var this_label = $(this).attr('data-label');
3694                                var this_index = $(this).attr('data-scrollinner-index');
3695                                if (this_label && this_index && typeof this_label != 'undefined' && typeof this_index != 'undefined') {
3696                                    $('#feature_panel_section_nav ul').append('<li class="ani-in" data-index="' + this_index + '"><button class="clear_button_styles" aria-label="Scroll to the ' + this_label +' section of the page">' + this_label + '</button></li>');
3697                                } else {
3698                                    $('#feature_panel_section_nav ul').append('<li class="ani-in no-label" data-index="' + this_index + '"></li>');
3699                                }
3700                                if ($('body').hasClass('section-artists') && $('body').hasClass('page-param-type-artist_id') && this_label == 'Overview' && $('.text_columns a[href^="/gallery-documents/"]').length) {
3701                                    $('#feature_panel_section_nav ul').append('<li class="ani-in no-scroll""><a href="' + $('.text_columns a[href^="/gallery-documents/"]').attr('href') + '">CV</a></li>');
3702                                }
3703                            }
3704                        });
3705    
3706                        if ($('#feature_panel_section_nav ul li').not('.no-label').length <= 1) {
3707                            $('#feature_panel_section_nav').addClass('nav-hidden');
3708                        } else {
3709                            $('#feature_panel_section_nav').removeClass('nav-hidden');
3710                        }
3711                    }
3712                    
3713                    if ($('#feature_panel_section_nav ul li:not(.no-label)').length > 1) {
3714                		var new_page_header_content = $('#feature_panel_section_nav').length ? $('#feature_panel_section_nav').html() : '';
3715                		var new_page_hero_nav = $('#feature_panel_section_nav ul').length ? '<ul class="inview_element ani-group">' + $('#feature_panel_section_nav ul').html() + '</ul>' : '';
3716                		
3717                		if (!$('#header #page_header').length) {
3718                			$('#header_main_inner').append('<div id="page_header"></div>')
3719                		}
3720                		
3721                		$('#header #page_header').html(new_page_header_content);
3722                		if (new_page_header_content != '') {
3723                			$('#header').addClass('page-header-subsections');
3724                		}
3725                		
3726                		$('.page_navigation_within_content').html(new_page_hero_nav);
3727                		$('.page_navigation_within_content li.no-label').remove();
3728                		
3729                		
3730                		$('#hero .hero_nav').html(new_page_hero_nav);
3731                		$('#hero .hero_nav li.no-label').remove();
3732                		if (new_page_hero_nav != '') {
3733                			$('#hero, .hero_header').addClass('page-hero-subsections');
3734                		}
3735                    }
3736                }
3737                
3738                
3739                if ($('#gallery_page_location_nav ul li:not(.no-label)').length > 1) {
3740                    
3741                    
3742            		var new_page_hero_nav = $('#gallery_page_location_nav ul').length ? '<ul class="inview_element ani-group">' + $('#gallery_page_location_nav ul').html() + '</ul>' : '';
3743            		
3744            		$('.hero_content_additional').addClass('show');
3745            		$('#hero .hero_nav').html(new_page_hero_nav);
3746            		
3747            		$('#hero .hero_nav li.no-label').remove();
3748            		if (new_page_hero_nav != '') {
3749            			$('#hero, .hero_header').addClass('page-hero-subsections');
3750            		}
3751                }
3752                
3753                
3754                
3755                $('.panel_filters_exhibition_status ul li a').unbind().click(function() {
3756                    $(this).parent().trigger('click');
3757                    return false;
3758                });
3759                
3760                $('#feature_panel_section_nav ul li, #page_header ul li:not(.no-scroll), .hero_nav ul li, .page_navigation_within_content ul li, .panel_filters_exhibition_status ul li, .gallery_locations_nav ul li').unbind().click(function(e) {
3761                    $('body').addClass('window-forced-scroll-up');
3762                    var this_index = $(this).attr('data-index');
3763                    
3764                    if ($('.gallery_details_wrapper').length) {
3765                        var related_item = $('.gallery_details_wrapper[data-scrollinner-index="' + this_index + '"]');
3766                    } else {
3767                        var related_item = $('.feature_panels section[data-scrollinner-index="' + this_index + '"]');
3768                    }
3769                    
3770                    
3771                    if (related_item.length) {
3772                        var direction = (related_item.offset().top > $(window).scrollTop() ? 'down' : 'up');
3773                        if (false && $('#header').length > 0 && direction == 'up') {
3774                            var offset = 100;
3775                            var offset = offset + $('#header').outerHeight();
3776                        } else {
3777                            var offset = 40;
3778                        }
3779                        if ($('body').hasClass('layout-hero-active') && $('#container_outer').hasClass('page-top-proximity')) {
3780                            var translation_nav_height = $('#container > #translations_nav .header_translations_nav_inner').outerHeight();
3781                            offset = offset - translation_nav_height;
3782                        }
3783                        if ($('#cms-frontend-toolbar-container').length > 0) {
3784                            var offset = offset + $('#cms-frontend-toolbar-container').outerHeight();
3785                        }
3786                        var related_item_offset = related_item.offset().top - offset;
3787                        var related_item_offset = (related_item_offset < 1 ? 0 : related_item_offset);
3788                        window.site.commands.scrollto(related_item_offset, function() {
3789                            $('body').delay(100).queue(function() {
3790                                $(this).removeClass('window-forced-scroll-up');
3791                                $(this).dequeue();
3792                            });
3793                            window.site.scroll.subnav_active_change();
3794                        });
3795                        
3796                        if ($('body').hasClass('tabbing-detected')) {
3797                            setTimeout(function(){ $(related_item)[0].focus(); }, 1000);
3798                        }
3799                    }
3800                    return false;
3801                });
3802
3803            },
3804
3805            subnav_active_change: function() {
3806                var windowPos = $(window).scrollTop(); // get the offset of the window from the top of page
3807                var windowHeight = $(window).height(); // get the height of the window
3808                var docHeight = $(document).height();
3809                $('#feature_panel_section_nav ul li, #page_header ul li:not(.no-scroll), .panel_filters_exhibition_status ul li')
3810                    .each(function() {
3811                        var this_index = $(this).attr('data-index');
3812                        var related_item = $('.feature_panels section[data-scrollinner-index="' + this_index + '"]');
3813                        if (related_item.length) { 
3814                            var item_theme = related_item.attr('data-theme');
3815                            var offset = windowHeight/2;
3816                            if ($('#cms-frontend-toolbar-container').length > 0) {
3817                                var offset = offset + $('#cms-frontend-toolbar-container').outerHeight();
3818                            }
3819                            var divPos = related_item.offset().top - offset; // get the offset of the div from the top of page
3820                            var divHeight = related_item.outerHeight(); // get the height of the div in question
3821                            if (windowPos >= divPos && windowPos < (divPos + divHeight)) {
3822                                // This item is active
3823                                if (!$("#feature_panel_section_nav ul li[data-index='" + this_index + "']").hasClass('active')) {
3824                                    $("#feature_panel_section_nav ul li[data-index='" + this_index + "']").closest('li').addClass("active");
3825                                    $("#page_header ul li[data-index='" + this_index + "']").closest('li').addClass("active");
3826                                    $(".panel_filters_exhibition_status ul li[data-index='" + this_index + "']").closest('li').addClass("active");
3827                                    
3828                                    var link_text = $(".panel_filters_exhibition_status ul li[data-index='" + this_index + "']").find('a').text();
3829                                    $(".panel_filters_exhibition_status ul li[data-index='" + this_index + "']").find('a').attr("aria-label", link_text + " (Selected)");
3830                                }
3831                            } else {
3832                                // This item is not active
3833                                $("#feature_panel_section_nav ul li[data-index='" + this_index + "']").closest('li').removeClass("active");
3834                                $("#page_header ul li[data-index='" + this_index + "']").closest('li').removeClass("active");
3835                                $(".panel_filters_exhibition_status ul li[data-index='" + this_index + "']").closest('li').removeClass("active");
3836                                $(".panel_filters_exhibition_status ul li[data-index='" + this_index + "']").find('a').removeAttr("aria-label");
3837                            }
3838                        }
3839                    })
3840                    .promise()
3841                    .done(function() {
3842                        
3843                    })
3844                ;
3845
3846                // General events - revert or figure out what to do if no items are active
3847                if ($('#feature_panel_section_nav li').length > 1 && $('#feature_panel_section_nav .active').length < 1) {
3848                    var first_item = $('#feature_panel_section_nav li').filter(':eq(0)');
3849                    var first_item_index = first_item.attr('data-index');
3850                    var related_item = $('.feature_panels section[data-scrollinner-index="' + first_item_index + '"]').length ? $('.feature_panels section[data-scrollinner-index="' + first_item_index + '"]') : false;
3851                    var related_item_below_scroll = false;
3852                    if (related_item) {
3853                        if (related_item.offset().top > $(window).scrollTop()) {
3854                            var related_item_below_scroll = true;
3855                        }
3856                    }
3857                    if (related_item_below_scroll) {
3858                        // We are above the first item, the initial theme should be set as the first item theme
3859                        var item_theme = related_item.attr('data-theme');
3860                        if (item_theme == 'reversed') {
3861                            $('body').addClass('content-type-reversed');
3862                            window.site.layout.hero.custom_color_on();
3863                        } else {
3864                            $('body').removeClass('content-type-reversed');
3865                            window.site.layout.hero.custom_color_off();
3866                        }
3867                    } else {
3868                        // No items are active, revert theme
3869                        $('body').removeClass('content-type-reversed');
3870                        window.site.layout.hero.custom_color_off();
3871                        $('#feature_panel_section_heading').removeClass('visible');
3872                        if (typeof section_intro_timeout != 'undefined') {
3873                            clearTimeout(section_intro_timeout);
3874                            clearTimeout(section_intro_timeout2);
3875                        }
3876                    }
3877                }
3878
3879                if(windowPos + windowHeight == docHeight) {
3880                    if (!$("#feature_panel_section_nav ul li:last-child").closest('li').hasClass("active")) {
3881                        var navActiveCurrent = $(".active").attr("href");
3882                        $("#feature_panel_section_nav ul li[href='" + navActiveCurrent + "']").closest('li').removeClass("active");
3883                        $("#feature_panel_section_nav ul l li:last-child").closest('li').addClass("active");
3884                    }
3885                }
3886            },
3887
3888            smooth_scroll: {
3889
3890                init: function() {
3891                    $(window).bind('resize', window.site.scroll.smooth_scroll.resize);
3892                    window.site.scroll.smooth_scroll.scroll_init();
3893                    if (window.site.scroll.smooth_scroll.device_enabled()) {
3894                        window.site.scroll.smooth_scroll.setup();
3895                        window.site.scroll.smooth_scroll.resize_container();
3896	                    $(window).load(function() {
3897	                        window.site.scroll.smooth_scroll.resize_container();
3898	                    });
3899                    } else {
3900                        window.site.scroll.smooth_scroll.fallback();
3901                    }
3902                },
3903
3904                setup: function() {
3905                    $('.scroll-container').addClass('active');
3906                    $('body').addClass('smooth-scroll-enabled');
3907                    window.site.scroll.smooth_scroll_active = true;
3908                    requestAnimationFrame(window.site.scroll.smooth_scroll.loop);
3909                },
3910
3911                fallback: function() {
3912                    $('.scroll-container').addClass('standard');
3913                    $('body').addClass('smooth-scroll-fallback');
3914                    window.site.scroll.smooth_scroll_active = false;
3915                },
3916
3917                resize: function() {
3918                    $(window).trigger('scroll');
3919                    if (window.site.scroll.smooth_scroll_active) {
3920                        window.site.scroll.smooth_scroll.resize_container();
3921                    }
3922                    window.site.scroll.smooth_scroll.resize_elements();
3923                },
3924
3925                scroll_init: function() {
3926                    var scrollElements = $(window.site.scroll.settings.scroll_parallax_elements);
3927                    scrollElements.each(function() {
3928                        if (!$(this).attr('data-level') || typeof $(this).attr('data-level') == 'undefined') {
3929                            var level = $(this).css('zIndex');
3930                            if (level == 0) {
3931                                var level = 1;
3932                            }
3933                            $(this).attr('data-level', level);
3934                        }
3935                    });
3936                    window.site.scroll.smooth_scroll.resize_elements();
3937                },
3938
3939                resize_elements: function() {
3940                	if (window.site.scroll.smooth_scroll_active) {
3941	                    $(window.site.scroll.settings.scroll_parallax_elements + ', ' + window.site.scroll.settings.scroll_section_elements).each(function() {
3942	                        var element = $(this);
3943	                        var transform = element.css('transform');
3944	                        element.addClass('parallax-resizing');
3945	                        element.attr('data-top', element.offset().top);
3946	                        element.attr('data-scrollheight', window.site.layout.window_height());
3947	                        element.attr('data-bottom', element.offset().top + element.outerHeight());
3948	                        element.attr('data-start', element.offset().top - window.site.layout.window_height());
3949	                        element.attr('data-stop', element.offset().top + element.outerHeight());
3950	                        element.css({
3951	                            transform: transform,
3952	                            backgroundColor: 'transparent'
3953	                        });
3954	                        element.removeClass('parallax-resizing');
3955	                    });
3956	                    $(window.site.scroll.settings.scroll_parallax_overflow_elements).each(function() {
3957	                        var element = $(this);
3958	                        var wh = $(window).height();
3959	                        var offsetTop = element.attr('data-top');
3960	                        var offsetBottom = element.attr('data-bottom');
3961	                        var level = Number(element.attr('data-level'));
3962	                        var amplitude = -wh;
3963	                        var movement = amplitude / (5 / level);
3964	                        var start = element.attr('data-start');
3965	                        var stop = element.attr('data-stop');
3966	                        var percent = (start - start) / (stop - start);
3967	                        percent = percent - 0.5;
3968	                        var maximum_offset = movement * percent;
3969	                        var maximum_offset_top = maximum_offset;
3970	                        if (element.offset().top < 20) {
3971	                            var maximum_offset_top = 0;
3972	                        }
3973	                        element.css({'top': -maximum_offset_top + 'px', 'bottom': -maximum_offset + 'px'});
3974	                    });
3975                	}
3976                },
3977
3978                translate_y: function(element) {
3979                    var style = window.getComputedStyle(element.get(0));
3980                    var matrix = style.getPropertyValue("-webkit-transform") || style.getPropertyValue("-moz-transform") || style.getPropertyValue("-ms-transform") || style.getPropertyValue("-o-transform") || style.getPropertyValue("transform");
3981                    if (matrix === 'none') {
3982                        matrix = 'matrix(0,0,0,0,0)';
3983                    }
3984                    var values = matrix.match(/([-+]?[\d\.]+)/g);
3985                    return values[14] || values[5] || 0;
3986                },
3987
3988                new_translate_y: function(element) {
3989                    var computed_style = window.getComputedStyle(element.get(0));
3990                    var position = computed_style.getPropertyValue('-webkit-transform') || computed_style.getPropertyValue('-moz-transform') || computed_style.getPropertyValue('-ms-transform') || computed_style.getPropertyValue('-o-transform') || computed_style.getPropertyValue('transform');
3991                    if (!position || typeof position == 'undefined' || position === 'none') {
3992                        return 0;
3993                    } else {
3994                        var split_position_keys = position.replace(/matrix(3d)?\(|\)/g, '').split(',');
3995                        if (split_position_keys[14]) {
3996                            return split_position_keys[14];
3997                        } else if (split_position_keys[5]) {
3998                            return split_position_keys[5];
3999                        } else {
4000                            return 0;
4001                        }
4002                    }
4003                },
4004
4005                loop: function() {
4006                    var container = $('.scroll-container');
4007                    var wh = $(window).height();
4008                    var windowScrollTop = $(window).scrollTop();
4009                    var activeOffset = $(window).height() / 2;
4010                    var windowScrollTopActiveOffset = windowScrollTop + activeOffset;
4011                    var destY = windowScrollTop;
4012                    var currentY = -window.site.scroll.smooth_scroll.translate_y(container);
4013                    var containerY = -window.site.scroll.smooth_scroll.translate_y(container);
4014
4015                    if (Math.round(currentY) != Math.round(destY)) {
4016                        var newY = Math.round(currentY + ((destY - currentY) * 0.1));
4017                        container.css({
4018                            transform: 'translate3d(0, -' + newY + 'px, 0)'
4019                        });
4020                        $(window).trigger('smoothscroll');
4021                    }
4022                    var parallax_elements = $(window.site.scroll.settings.scroll_parallax_elements);
4023                    if (parallax_elements != null) {
4024                        parallax_elements.each(function() {
4025                            var element = $(this);
4026                            var offsetTop = element.attr('data-top');
4027                            var offsetBottom = element.attr('data-bottom');
4028                            var level = Number(element.attr('data-level'));
4029                            var amplitude = -wh;
4030                            var movement = amplitude / (5 / level);
4031                            if (offsetTop > (windowScrollTop + (wh * 1.3))) {
4032                                element.css({
4033                                    transform: 'translate3d(0, ' + (-movement * 0.5) + 'px, 0)'
4034                                });
4035                            } else if (offsetBottom < (windowScrollTop * 0.7)) {
4036                                element.css({
4037                                    transform: 'translate3d(0, ' + (movement * 0.5) + 'px, 0)'
4038                                });
4039                            } else {
4040                                var start = element.attr('data-start');
4041                                var stop = element.attr('data-stop');
4042                                var percent = (windowScrollTop - start) / (stop - start);
4043                                percent = percent - 0.5;
4044                                var destY = movement * percent;
4045                                var currentY = 0;
4046                                var transform = element.css('transform');
4047                                if (transform != 'none')
4048                                    currentY = parseFloat(element.css('transform').split(',')[5]);
4049                                if (level > 0)
4050                                    var newY = currentY + ((destY - currentY) * 0.1);
4051                                else
4052                                    var newY = currentY + ((destY - currentY) * 0.5);
4053                                element.css({
4054                                    transform: 'translate3d(0, ' + (newY) + 'px, 0)'
4055                                });
4056                                var image = element.find('> .image, .image-container > .image').not('.fixed');
4057                                if (image.length == 1) {
4058                                    image.css({
4059                                        top: 100 * percent
4060                                    });
4061                                }
4062                            }
4063                        });
4064                    }
4065
4066                    requestAnimationFrame(window.site.scroll.smooth_scroll.loop);
4067                },
4068
4069                resize_container: function() {
4070                    var container = $('.scroll-container');
4071                    $('body').css({
4072                        height: container.outerHeight()
4073                    });
4074                },
4075
4076                device_enabled: function() {
4077                    if (window.site.scroll.smooth_scroll_enabled) {
4078                        var mobile_version = window.site.device.handheld() || $(window).width() < 900 || ($.browser.msie && $.browser.version < 10);
4079                        return !mobile_version;
4080                    } else {
4081                        return false;
4082                    }
4083                }
4084
4085            }
4086        },
4087
4088        pageload: {
4089
4090            splash_dev_mode: false, 
4091            splash_act_as_server: false,
4092
4093            init: function() {
4094            	if ($('body').hasClass('section-error')) {
4095            		$('body').addClass('first-load-complete');
4096            		return false;
4097            	}
4098                if ('scrollRestoration' in history) {
4099                	if (window.site.scroll.smooth_scroll_enabled) {
4100                    	history.scrollRestoration = 'manual';
4101                    } else {
4102                    	history.scrollRestoration = 'auto';
4103                    }
4104                }
4105                $('a[href^="/shop/artworks/"], a[href^="/video/"], a[href^="/shop/publications/"], a[href^="/publications/"], a[href^="/news/"]').each(function() {
4106                    // a[href^="/news/"], 
4107                    if (!$(this).closest('.artwork_detail').length && $(this).attr('href') != '/store/artworks/' && $(this).attr('href') != '/news/' && $(this).attr('href') != '/video/') {
4108                        if (!$(this).hasClass('pageload-link-type-popup-enabled-content')) {
4109                            $(this).addClass('pageload-link-type-popup-enabled-content');
4110                        }
4111                    }
4112                });
4113                $('a[href^="/content/feature/"]').each(function() {
4114                    if ($(this).attr('href').indexOf('/detail/') > -1) {
4115                        if (!$(this).closest('.artwork_detail').length) {
4116                            if (!$(this).hasClass('pageload-link-type-popup-enabled-content')) {
4117                                $(this).addClass('pageload-link-type-popup-enabled-content');
4118                            }
4119                        }
4120                    }
4121                });
4122
4123                $('a.pageload-link-type-popup-enabled-content').click(function() {
4124                    // Assume background will be reversed - popups are reversed by default
4125                    //$('body').addClass('content-type-reversed-popup');
4126                });
4127
4128                $.pageload({
4129                    
4130                    ///////////////////////////////////
4131                    // Ajax navigation removed for development
4132                    ///////////////////////////////////
4133                    'ajax_navigation_enabled': true,
4134
4135                    'splash_screen_enabled': false, // $('#cms-frontend-toolbar').length > 0 ? false : true
4136                    
4137                    	// 'splash_screen_always_enabled': $('body').hasClass('site-version-development-mode') || $('#cms-frontend-toolbar').length > 0 ? false : (true || !$('body').hasClass('site-version-development-mode') || window.site.pageload.splash_dev_mode || window.site.pageload.splash_act_as_server ? true : false),
4138                    	'splash_screen_always_enabled': false,
4139                        'development_mode': window.site.pageload.splash_dev_mode ? true : false,
4140                        'development_mode_pause_splash_screen': window.site.pageload.splash_dev_mode ? true : false,
4141                        'development_mode_show_splash_screen_on_refresh': false,
4142
4143           			'splash_screen_cookie_expiry': 300, // 5m
4144                    'splash_screen_delay_after_complete': 0,
4145                    'splash_screen_auto_delays_enabled': false,
4146                    //'page_transition_delay': 1200,
4147                    'page_transition_delay': 400, // 810,
4148                    'popup_content_enabled': true,
4149                    'popup_content_force_open': true,
4150                    'verbose': false,
4151                    'content_area_selector': '.pageload-content-area',
4152                    'content_load_adjacent': false,
4153                    
4154                    'body_classes_to_retain': 'page-transition-custom',
4155                    
4156                    'disable_ajax_param': true,
4157                    
4158                    'splash_screen_primary_preload_images_selector': '',
4159                    'preload_images_selector': '',
4160                    'preload_videos_selector': '',
4161                    'x_popstate_custom_functions': {
4162                        '/artworks/': function(e) {
4163                            var relative_id = e.originalEvent.state.customArtworksDefaultCategory;
4164                            $('.artworks-overlay-button:eq(0)').trigger('click');
4165                            if (relative_id) {
4166                                $('.artworks-overlay .artwork-nav-top-level[data-id="' + relative_id + '"]').trigger('click');
4167                            }
4168                        }
4169                    },
4170                    'after_load_complete': function(something) {
4171                        //update link active class and aria labels in mobile nav after load
4172                        var element_href = window.location.pathname.replace(window.archimedes.proxy_dir, '');
4173                        if (element_href == '/') {
4174                            var target_top_level = '[href="' + element_href + '"]';
4175                        } else {
4176                            target_top_level = element_href.split('/')[1];
4177                            target_top_level = '/' + target_top_level + '/';
4178                            target_top_level = '[href^="' + target_top_level + '"]';
4179                        }
4180                        
4181                        $('.nav-overlay .nav-wrapper ul li a, #main_nav a').each(function() {
4182                            $(this).attr('href', $(this).attr('href').replace(window.archimedes.proxy_dir, ''));
4183                        });
4184                        
4185                        $('.nav-overlay .nav-wrapper ul li a, #main_nav a').removeClass('active').removeAttr('aria-label');
4186                        $('.nav-overlay .nav-wrapper ul li a' + target_top_level + ', #main_nav a' + target_top_level + '').addClass('active');
4187                        var nav_label = $('.nav-overlay .nav-wrapper ul li a' + target_top_level + '').text();
4188                        $('.nav-overlay .nav-wrapper ul li a' + target_top_level + ', #main_nav a' + target_top_level + '').attr('aria-label', ( nav_label + ' (current nav item)' ));
4189                        
4190                        $('.nav-overlay .nav-wrapper ul li a, #main_nav a').each(function() {
4191                            if (typeof window.archimedes.proxy_dir != 'undefined') {
4192                                $(this).attr('href', window.archimedes.proxy_dir + $(this).attr('href'));
4193                            }
4194                        });
4195                        
4196                        $('#translations_nav a').each(function() {
4197                            var current_path = window.location.pathname.replace(window.archimedes.proxy_dir, '');
4198                            if (typeof $(this).attr('data-lang') != 'undefined') {
4199                                $(this).attr('href', '/' + $(this).attr('data-lang') + current_path);
4200                            } else {
4201                                $(this).attr('href', current_path);
4202                            }
4203                        });
4204                    },
4205                    'destroy_after_load': function() {
4206                        $('.filter-wrapper').removeClass('initialised');
4207                        if ($('.artworks-overlay').hasClass('active')) {
4208                            var default_category = false;
4209                            if ($('.artwork-navigation .artwork-nav-top-level.active').length) {
4210                                var default_category = $('.artwork-navigation .artwork-nav-top-level.active').attr('data-id');
4211                            }
4212                            history.pushState({'ajaxPageLoad': true, 'customArtworksDefaultCategory': default_category}, null, '/artworks/');
4213                        }
4214
4215                        if ($('body').hasClass('page-popup-active')) {
4216                            // A popup is open, close it
4217                            $.pageload.popup_close(true);
4218                        }
4219                        
4220                        if ($('body').hasClass('dropdown-nav-active')) {
4221                            window.site.scroll.dropdown_navigation.close();
4222                        }
4223                        
4224                        
4225	                    if ($('.artworks-overlay').hasClass('active')) {
4226	                    	$('.artworks-overlay-close-button').trigger('click');
4227	                    }
4228
4229                        $('video').remove();
4230                        $('.image_gallery_multiple').cycle('destroy');
4231                        $('#hero_slideshow').cycle('destroy');
4232                        $('.content_slideshow').cycle('destroy');
4233                        $('#main_slideshow, .main_slideshow').cycle('destroy');
4234                        $('#hero_slideshow').stop().clearQueue().unbind();
4235                        $('body').removeClass('page-transition-delay');
4236                        window.site.artlogic_inview.destroy();
4237                    },
4238                    'popup_before': function() {
4239                        window.site.pageload.popup_after_open('before');
4240                    },
4241                    'popup_after': function() {
4242                        window.site.pageload.popup_after_open('after');
4243                    },
4244                    'popup_after_close': function() {
4245                        window.site.pageload.popup_after_close();
4246                    },
4247                    'before_load': function() {
4248                        if (typeof mailings_popup_timeout != 'undefined') {
4249                            clearTimeout(mailings_popup_timeout);
4250                        }
4251                        if ($('.search-overlay').hasClass('active') && !$('.search-overlay').hasClass('search-loading')) {
4252                    		window.site.overlays.search.close();
4253                    	}
4254                        if ($('.enquire-overlay').hasClass('active')) {
4255                    		window.site.overlays.enquire.close();
4256                    	}
4257                        if ($('.content-overlay').hasClass('active')) {
4258                            window.site.overlays.content.close();
4259                        }
4260                        if ($('#main_slideshow, .main_slideshow').length) {
4261                            if (window.window.canvasSlideshowInitialized) {
4262                                window.canvasPauseVideo(parseInt($('#main_slideshow .slide.cycle-slide-active').attr('data-index'))-1);
4263                            }
4264                        }
4265                        if ($('#store_quick_cart_widget').hasClass('active')) {
4266                            $('#store_quick_cart_widget .notify_panel_close').trigger('click');
4267                        }
4268                        if ($('#wishlist_quick_cart_widget').hasClass('active')) {
4269                            $('#wishlist_quick_cart_widget .notify_panel_close').trigger('click');
4270                        }
4271                        if ($('body').hasClass('header-dropdown-active')) {
4272                            window.site.misc.hideDropdown();
4273                        }
4274                        
4275                    },
4276                    'preloader_in': function(short_load) {
4277                        if (!short_load) {
4278                            // window.site.splash_screen.init();
4279                            console.log('Splash screen disabled')
4280                        } else {
4281                            // Start the homepage slideshow (can be done anywhere in the code, e.g. after the splash screen has finished)
4282                            window.site.home.start_slideshow();
4283                        }
4284                    },
4285                    'splash_screen_in': function() {
4286                    },
4287                    'splash_screen_out': function() {
4288                        window.site.splash_screen.splash_screen_end();
4289                    },
4290                    'init_after_splash_screen': function() {
4291                    },
4292                    'page_transition_start': function(event) {
4293                        if (typeof custom_page_transition_in != 'undefined') {
4294                            clearTimeout(custom_page_transition_in);
4295                        }
4296                        if (typeof custom_page_transition_out != 'undefined') {
4297                            clearTimeout(custom_page_transition_out);
4298                        }
4299                        custom_page_transition_in = setTimeout(function() {
4300                            $('body').addClass('page-transition-custom');
4301                        }, 50);
4302                    },
4303                    'page_transition_end': function() {
4304                        custom_page_transition_out = setTimeout(function() {
4305                            $('body').removeClass('page-transition-custom');
4306                            window.site.layout.resize();
4307                        }, 400);
4308                    }
4309                });
4310                $('.nav-overlay .nav-wrapper ul li a').unbind().click(function() {
4311                    if (!$(this).hasClass('link-no-ajax')) {
4312                        $('.nav-close-button').trigger('click');
4313                        $.pageload.load($(this).attr('href'), true, false);
4314                    }
4315                	return false;
4316                });
4317                $('.artist-overlay .artist-wrapper ul li a').unbind().click(function() {
4318                    if (!$(this).hasClass('link-no-ajax')) {
4319                        $('.artist-close-button').trigger('click');
4320                        $.pageload.load($(this).attr('href'), true, false);
4321                    }
4322                	return false;
4323                });
4324                $('#sqcw_checkout a').unbind().click(function() {
4325                	$.pageload.load($(this).attr('href'), true, function() {
4326	                    $('#sqcw_close').trigger('click');
4327                	});
4328                	return false;
4329                });
4330                window.site.pageload.load_more_pagination.init();
4331            },
4332
4333            close_popup: function() {
4334                window.history.back();
4335                //$('#popup_box > .inner > .close').trigger('click');
4336                $('body').removeClass('content-reversed content-not-reversed content-type-reversed-popup');
4337                $('body').removeClass('user-distraction-free')
4338                $('body').removeClass('page-artwork-detail-standard');
4339                $('#popup_box').animate({'scrollTop': 0}, 600);
4340                $('#popup_content').html('');
4341            },
4342
4343            popup_after_open: function(type) {
4344                
4345                // Logic to move legacy news detail content into correct positions as before both the image caption and news content were in the same field
4346                if ($('.news_detail_popup.record_detail_simple .image_container .images > .caption .image_caption').length || $('.news_detail_popup.advanced_page_layout #hero .hero_image_wrapper .image > .caption .image_caption').length) {
4347                    
4348                    if ($('#popup_content .news_detail_popup').hasClass('advanced_page_layout')) {
4349                        var $new_image_caption_container = $('.news_detail_popup.advanced_page_layout #hero .hero_image_wrapper .image > .caption');
4350                    } else {
4351                        var $new_image_caption_container = $('.news_detail_popup.record_detail_simple .image_container .images > .caption');
4352                    }
4353                    
4354                    var $legacy_image_caption = $('<div class="legacy_image_caption"></div>');
4355                    
4356                    // Clone the legacy image caption and add it to the newly created legacy_image_caption element varaiable, then remove it from its current position in DOM
4357                    $('.image_caption', $new_image_caption_container).each(function() {
4358                    	$legacy_image_caption.append($(this).clone().removeClass('image_caption'));
4359                    	$(this).remove();
4360                    });
4361                    
4362                    // add the additional_information element if it doesn't already exist
4363                    if (!$('.news_detail_popup.record_detail_simple .content_container .additional_information').length) {
4364                        $('<div class="additional_information"></div>').insertBefore($('.news_detail_popup.record_detail_simple .content_container .news_details .divider'))
4365                    }
4366                    
4367                    // Append the contents and image caption to correct places
4368                    $new_image_caption_container.contents().appendTo($('.news_detail_popup.record_detail_simple .content_container .additional_information'));
4369                    $new_image_caption_container.append($legacy_image_caption);
4370                    
4371                    // Check to see if the first element in the content is just a spacer and remove it if so
4372                    var $first_content_element = $('.news_detail_popup.record_detail_simple .content_container .additional_information > *').first();
4373                    var first_content_element_text = $first_content_element.text();
4374                    if (first_content_element_text && first_content_element_text == '\u00a0') {
4375                        $first_content_element.remove();
4376                    }
4377                    
4378                    // Check to see if the last element in the caption is just a spacer and remove it if so
4379                    var $last_content_element = $('.legacy_image_caption > *', $new_image_caption_container).last();
4380                    var last_content_element_text = $last_content_element.text();
4381                    if (last_content_element_text && last_content_element_text == '\u00a0') {
4382                        $last_content_element.remove();
4383                    }
4384                    
4385                }
4386                
4387                if ($('.record_detail_simple:not(.artwork_detail_variant_store_detail) .additional_information').length) {
4388                    window.site.layout.max_height_read_more('.record_detail_simple .additional_information', 9, '+');
4389                }
4390                
4391                if ($('.record_detail_simple.artwork_detail_variant_store_detail .additional_information').length) {
4392                    window.site.layout.max_height_read_more('.record_detail_simple.artwork_detail_variant_store_detail .additional_information', 5, '+');
4393                }
4394                
4395                if ($('#popup_content .artwork_detail_variant_artwork .additional_information').length) {
4396                    window.site.layout.max_height_read_more('#popup_content .artwork_detail_variant_artwork .additional_information', 5, '+');
4397                }
4398                
4399                if ($('#popup_content #hero_detail').length) {
4400                    window.site.pageload.popup_hero();
4401                }
4402                
4403                $('body').addClass('popup-not-scrolled');
4404                
4405                if ($('body').hasClass('dropdown-nav-active')) {
4406                    window.site.scroll.dropdown_navigation.close();
4407                }
4408                
4409                if ($('body').hasClass('header-dropdown-active')) {
4410                    window.site.misc.hideDropdown();
4411                }
4412                
4413                if (type == 'after' && $('#popup_content .content-reversed').length) {
4414                    $('#popup_container').addClass('popup-content-reversed');
4415                    $('body').addClass('content-type-reversed-popup');
4416                }
4417                
4418                if (type == 'after' && $('#popup_content .artwork_detail_variant_store_detail').length) {
4419                    $('body').addClass('store-detail-popup-active');
4420                }
4421                if (type == 'after' && $('#popup_content .art_fair_detail_popup').length) {
4422                    window.site.quick_enquiry.init();
4423                }
4424                
4425                $('body').removeClass('user-inactive user-idle window-scrolled');
4426            	$('#container_outer').removeClass('scrolling-down scrolling-up');
4427                // window.cart.init();
4428                // window.cart.cart_summary.get_summary(false);
4429            
4430                window.site.social_media.init();
4431                window.site.overlays.enquire.init();
4432                window.site.slideshow.slider.init();
4433                window.site.slideshow.cascading();
4434                if (type == 'after') {
4435                    $('#popup_content').animate({'scrollTop': 0}, 0, 'easeInOutExpo');
4436                    window.site.layout.flow_grid.flow_list_setup('#popup_content');
4437                    window.site.lazy_load.setup();
4438                    window.site.lazy_load.fire('#popup_box .inview_element');
4439    
4440                    window.site.misc.extended_click_area();
4441                    $.pageload.refresh('#popup_content');
4442                    window.site.artworks.setup();
4443                    window.site.video.init();
4444                    window.site.misc.fancybox_image_popup();
4445                    
4446                }
4447                
4448                $(window).trigger('resize');
4449                window.site.misc.init('popup');
4450                window.site.artlogic_inview.init();
4451            },
4452
4453            popup_after_close: function() {
4454                
4455                $('body').removeClass('content-type-reversed-popup');
4456                $('body').removeClass('popup-hidable-content user-distraction-free');
4457                $('body').removeClass('content-reversed content-not-reversed');
4458                $('body').removeClass('zoom-active user-distraction-free');
4459                $('body').removeClass('popup-scrolled popup-not-scrolled');
4460                $('body').removeClass('store-detail-popup-active');
4461                $('#popup_content').html('');
4462                $('#popup_box .artwork_detail.artwork_detail_variant_video .video').html('');
4463                $('.image_gallery_multiple').cycle('destroy');
4464                if ($('#popup_content #hero_detail').length) {
4465                    $('#popup_content #hero_detail').cycle('destroy');
4466                }
4467                window.site.scroll.events.run();
4468                $('#popup_content').scrollTop(0);
4469            },
4470            
4471            popup_hero: function() {
4472                
4473                $('#main_slideshow_detail').each(function() {
4474                    var cycle_timeout = 4500;
4475                    cycle_timeout_type = 'standard';
4476                    
4477                    var cycle_settings = {
4478                        fx:       'fade',
4479                        speed:    800,
4480                        timeout:  cycle_timeout,
4481                        paused:   false,
4482                        slides: '> .slide',
4483                        autoHeight: 'container',
4484                        swipe: true
4485                    };
4486                    
4487                    $(this).unbind().cycle(cycle_settings);
4488                });
4489                
4490            },
4491
4492            load_more_pagination: {
4493                
4494                // Dynamically loads in new items into a records_list, rather than traditional pagination
4495    
4496                init: function() {
4497                    
4498                    var verbose_mode = true;
4499                    
4500                    /////////////////////////////////////////
4501                    /////////////////////////////////////////
4502                    // WHY DOESNT THIS GET REMOVED....
4503                    /////////////////////////////////////////
4504                    /////////////////////////////////////////
4505                    $('.list-ajax-load-previous-wrapper').remove();
4506                    window.site.pageload.load_more_pagination.setup(verbose_mode);
4507                },
4508                
4509                setup: function (verbose_mode) {
4510      
4511                    $('.page_stats').each(function(i, element) {
4512                        
4513                        var $this = $(this),
4514                            incoming_url = $this.find('.ps_next').attr('href');
4515                            page_stats_id = $this.attr('id'),
4516                            corresponding_list_ref = $this.attr('id'),
4517                            $list = $('[data-pagestats-id="'+corresponding_list_ref+'"]');
4518     
4519                            if (!$list.length && verbose_mode){
4520                                console.log("Can't find a corresponding list that relates to your pagination. Supply 'data-
4520pagestats-id' to list that matches your page_stats_id.")
4521                            }
4522                            
4523                        if (typeof incoming_url !== 'undefined' && typeof page_stats_id !== 'undefined' && $list.length){
4524                            
4525                            //Hide the original pagination 
4526                            $this.addClass('hidden');
4527                            
4528                            var number_of_pages = $('.ps_pages_indented .left:last-of-type', this).text();
4529                            
4530                            // strip everything other than numbers - usually would return of&nbsp;13
4531                            if (number_of_pages || typeof number_of_pages !== 'undefined') {
4532                                number_of_pages = number_of_pages.replace(/\D/g, '');
4533                            } else {
4534                                number_of_pages = '';
4535                            }
4536                            
4537                            //Create our new dynamic button
4538                            $this.after('<div class="list-ajax-load-more-wrapper clearwithin inview_element ani-group"><div class="ani-in panel_footer_revealable_link_inner list-ajax-load-more button" data-list="'+page_stats_id+'" data-url="'+incoming_url+'" aria-label="Load more items"><button href="#" class="button_inner list-ajax-load-more-label clear_button_styles">+</button><div class="loader"></div><div class="load-more-progress-bar-outer"><div class="load-more-progress-bar"></div></div><div class="reveal-pagination"><span class="current-block">1</span>/<span class="total-blocks">'+number_of_pages+'</span></div></div></div>');
4539                            
4540                            var percentage_complete = 0;
4541                            if (number_of_pages || isNaN(number_of_pages)) {
4542                                number_of_pages = parseInt(number_of_pages)
4543                                percentage_complete = (1 / number_of_pages);
4544                            }
4545                            $this.parent().find('.panel_footer_revealable_link_inner .load-more-progress-bar').css('transform', 'scaleX(' + percentage_complete + ')');
4546                            
4547                            $this.closest('.panel_footer').addClass('panel_footer_revealable_link');
4548                            
4549                            // $(this).append('<div class="panel_footer panel_footer_revealable_link inview_element ani-group"><div class="panel_footer_revealable_link_inner ani-in"><div class="button link_more"><button type="button" class="clear_button_styles">+</button></div><div class="load-more-progress-bar-outer"><div class="load-more-progress-bar"></div></div><div class="reveal-pagination"><span class="current-block">1</span>/<span class="total-blocks">'+total_blocks+'</span></div></div></div>');
4550                            
4551                            $('.list-ajax-load-more button').unbind().bind("click", function(e) { 
4552                                e.preventDefault();
4553                                var $button = $(this).closest('.button');
4554                                var incoming_url = $button.attr('data-url'); // URL detected at this level, later may be data-attr or any value
4555                                var corresponding_list_ref = $(this).closest('.list-ajax-load-more').attr('data-list');
4556                                            
4557                                var dynamic_related_pagestats_element = $button.closest('section').find('.records_grid[data-pagestats-id]');
4558                                if (dynamic_related_pagestats_element.length > 0) {
4559                                    if (typeof dynamic_related_pagestats_element.attr('data-pagestats-id') != 'undefined') {
4560                                        corresponding_list_ref = dynamic_related_pagestats_element.attr('data-pagestats-id');
4561                                    }
4562                                }
4563                                
4564                                var list = $('[data-pagestats-id="'+corresponding_list_ref+'"]');
4565                                if (!list.length && verbose_mode){
4566                                    console.log("Can't find a corresponding list that relates to your pagination. Supply 'data-
4566pagestats-id' to list that matches your page_stats_id.")
4567                                }
4568                                window.site.pageload.load_more_pagination.load_content($button, incoming_url, list, verbose_mode, number_of_pages);
4569                                
4570                                return false;
4571                            });
4572    
4573                        } else {
4574                            $this.addClass('hidden'); 
4575                        }
4576                            
4577                        // If this URL already has a skip value, prepend a load previous button
4578                        if (window.location.search && typeof window.location.search != 'undefined') {
4579                            if (window.location.search.indexOf('skip=') != -1) {
4580                                $list.before('<div class="list-ajax-load-previous-wrapper clearwithin"><div class="list-ajax-load-previous button button_compact" data-list="'+page_stats_id+'" aria-label="Load previous items"><span class="list-ajax-load-previous-label">Load previous items</span></div></div>');
4581                                    
4582                                $('.list-ajax-load-previous').bind("click", function(e) { 
4583                                    e.preventDefault();
4584                                    //Load the initial records list
4585                                    $.pageload.load(window.location.pathname, true);
4586                                });
4587                            }
4588                        }
4589                    });
4590                },
4591    
4592                load_content: function ($button, incoming_url, $list, verbose_mode, number_of_pages) {
4593                    
4594                    var incoming_content_type = 'inner',
4595                        current_button_offset = $button.offset().top - ($(window).height() / 3),
4596                        corresponding_list_ref = $list.data('pagestats-id'),
4597                        inner_content_selector = '[data-pagestats-id="'+corresponding_list_ref+'"]';
4598                    
4599                    var dynamic_related_pagestats_element = $list.closest('section').find('.records_grid[data-pagestats-id]');
4600                    if (dynamic_related_pagestats_element.length > 0) {
4601                        if (typeof dynamic_related_pagestats_element.attr('data-pagestats-id') != 'undefined') {
4602                            corresponding_list_ref = dynamic_related_pagestats_element.attr('data-pagestats-id');
4603                        }
4604                    }
4605                    
4606                    $button.addClass('loading');
4607                    
4608                    $.pageload.load(incoming_url, false, function() {
4609                        
4610                        $button.removeClass('loading');
4611                        
4612                        if (new_page_inner_content) {
4613    
4614                            $new_page_inner_content = $(new_page_main_content);
4615                            
4616                            var updated_url = $new_page_inner_content.find('.page_stats#'+corresponding_list_ref).find('.ps_next').attr('href'),
4617                                $new_list = $new_page_inner_content.find('[data-pagestats-id="'+corresponding_list_ref+'"]'),
4618                                $new_list_items = $new_list.find('.item').addClass('ajax-loaded-list-item');
4619                            
4620                            if ($list.hasClass('tile_grid')){
4621                                $list.find('.tile_grid_original .group').append($new_list_items);
4622                            } else if ($list.find('.group').length) {
4623                                $list.find('.group').append($new_list_items);
4624                            } else {
4625                                $list.append($new_list_items);
4626                            }
4627                            
4628                            // Increase the pagination number by 1
4629                            var current_page_number = parseInt($.trim($('.current-block', $button).html()));
4630                            var new_page_number = ++current_page_number;
4631                            
4632                            $('.current-block', $button).html(new_page_number);
4633                            
4634                            var percentage_complete = 0;
4635                            if (number_of_pages || isNaN(number_of_pages)) {
4636                                number_of_pages = parseInt(number_of_pages)
4637                                percentage_complete = (new_page_number / number_of_pages);
4638                            }
4639                            $button.parent().find('.panel_footer_revealable_link_inner .load-more-progress-bar').
4639css('transform', 'scaleX(' + percentage_complete + ')');
4640                            
4641                            if (updated_url){
4642                                $button.attr('data-url', updated_url);
4643                            } else {
4644                                $button.attr('data-url', '');
4645                                $button.addClass('disabled');
4646                                $button.closest('.list-ajax-load-more-wrapper').addClass('disabled').remove();
4647                            }
4648                            $('.first_new_item').removeClass('first_new_item');
4649                            $($new_list_items[0]).addClass('first_new_item');
4650    
4651                            // General resets
4652                            $(window).trigger('resize');
4653                            $(window).trigger('scroll');
4654                            
4655                            window.site.layout.grids.init();
4656                            window.site.lazy_load.setup();
4657                            window.site.artlogic_inview.init();
4658                            $.pageload.refresh('.ajax-loaded-list-item:not(.pageload-refreshed)');
4659                            $('.ajax-loaded-list-item').addClass('pageload-refreshed');
4660				            window.site.overlays.enquire.setup();
4661				            window.cart.add_to_cart($list.find('.store_item .store_item_add_to_cart'));
4662                            window.cart.add_to_wishlist($list.find('.add_to_wishlist'));
4663				            window.cart.remove_from_wishlist($list.find('.store_item_remove_from_wishlist'));
4664                            window.site.misc.init();
4665                            if (($(window).scrollTop()) < current_button_offset) {
4666                                setTimeout(function() {
4667                                    window.site.commands.scrollto(current_button_offset, function() {});
4668                                }, 10);
4669                            }
4670                            
4671                            if ($('body').hasClass('tabbing-detected')) {
4672                                $list.find('.first_new_item a').focus();
4673                            }
4674                            window.site.misc.extended_click_area();
4675                            $('.list-ajax-load-more').removeClass('triggered');
4676                        }
4677                        
4678                    }, null, null, null, incoming_content_type, inner_content_selector);
4679                }
4680    
4681            }
4682
4683        },
4684
4685        splash_screen: {
4686            init: function() {
4687
4688                $('body').addClass('main-content-hide');
4689                window.setTimeout(function() {
4690                    $('body').addClass('active-init');
4691                    $('body').addClass('splash-init');
4692                }, 10);
4693                window.setTimeout(function() {
4694                    $('.splash-bg').addClass('open start');
4695                    $('body').addClass('splash-open');
4696                    $('.hero video').each(function() {
4697                    	$(this).get(0).pause();
4698                    });
4699                }, 300);
4700                window.setTimeout(function() {
4701                    window.site.splash_screen.splash_screen_start();
4702                }, 200);
4703                
4704                if ($(window).width() <= 767) {
4705                    $('#splash_images .image_container .image_desktop').remove();
4706                } else {
4707                    $('#splash_images .image_container .image_mobile').remove();
4708                }
4709            },
4710
4711            splash_screen_start: function() {
4712                setTimeout(function() {
4713                	$('.splash-container').addClass('start');
4714                }, 0);
4715                
4716                var excluded_images = '';
4717                if (g.has_local_storage_test() && typeof localStorage != 'undefined') {
4718                    if (localStorage.getItem('splash_screen_images_shown')) {
4719                        // If protected_paths storage already exists
4720                        var images_shown = JSON.parse(localStorage.getItem('splash_screen_images_shown'));
4721                        for (var i = 0; i < images_shown.length; i ++) {
4722                            var excluded_images = excluded_images + ':not([data-splash-image-id="' + (images_shown[i]) + '"])';
4723                        }
4724                    } else {
4725                        var images_shown = [];
4726                    }
4727                }
4728                
4729                if ($('#splash_images .image_container' + excluded_images).length == 0) {
4730                    // Reset the list if all images have been shown
4731                    var excluded_images = '';
4732                    var images_shown = [];
4733                }
4734                
4735                var random = Math.floor(Math.random()*$('#splash_images .image_container' + excluded_images).length);
4736                $('#splash_images .image_container' + excluded_images).eq(random).addClass('active');
4737                $('.splash-container').addClass($('#splash_images .image_container.active' + excluded_images).attr('data-container-classes'));
4738                
4739                images_shown.push($('#splash_images .image_container.active').attr('data-splash-image-id'));
4740                
4741                if (g.has_local_storage_test() && typeof localStorage != 'undefined') {
4742                    localStorage.setItem('splash_screen_images_shown', JSON.stringify(images_shown));
4743                }
4744            },
4745            
4746            splash_screen_end: function() {
4747                setTimeout(function() {
4748
4749
4750                    // Start the homepage slideshow
4751                    setTimeout(function() {
4752                        window.site.home.start_slideshow_pre_init();
4753                        main_slideshow_cycle_first_slide_change = false;
4754                        $('.splash-container').addClass('end-begin');
4755                    }, 1000);
4756                    setTimeout(function() {
4757                        window.site.home.start_slideshow(false);
4758                    }, 1200);
4759
4760                    setTimeout(function() {
4761                        $('body').removeClass('main-content-hide');
4762                        $('.splash-container').addClass('end');
4763                        window.site.splash_screen.hide_splash();
4764                    }, 1200);
4765                }, 1000);
4766            },
4767
4768            hide_splash: function() {
4769                $('.splash-bg').removeClass('open start');
4770                // stop letter transition
4771                $('body').removeClass('splash-open');
4772
4773                $('body').delay(1200).queue(function() {
4774                    $('body').removeClass('active-init');
4775                    $('body').removeClass('splash-init');
4776                    
4777                    window.site.overlays.mailings.auto();
4778                    
4779                    $(window).trigger('resize');
4780                    $(this).dequeue();
4781                });
4782            }
4783
4784        },
4785
4786        overlays: {
4787
4788            init: function() {
4789                window.site.overlays.content.init();
4790                window.site.overlays.search.init();
4791                window.site.overlays.enquire.init();
4792                window.site.overlays.gallery_contact.init();
4793                window.site.overlays.mailings.init();
4794                window.site.overlays.navigation();
4795                window.site.overlays.artworks();
4796            },
4797
4798	        search: {
4799
4800	            init: function() {
4801                	window.site.overlays.search_form.init();
4802	                window.site.overlays.search.setup();
4803                    window.site.overlays.search.filters();
4804	            },
4805	            
4806	            filters: function() {
4807	                
4808	                $('.panel_filters_search_sections li button').unbind().click(function() {
4809	                    $(this).closest('.panel_filters_search_sections').find('li').removeClass('active');
4810	                    $(this).closest('li').addClass('active');
4811	                    if ($(this).attr('data-section') == '') {
4812	                        $('.panel_filters_search_section_results .item').removeClass('hidden');
4813	                    } else if ($(this).attr('data-section') != '' && typeof $(this).attr('data-section') != '' != 'undefined') {
4814	                        $('.panel_filters_search_section_results .item').removeClass('hidden');
4815	                        $('.panel_filters_search_section_results .item[data-section!="' + $(this).attr('data-section') + '"]').addClass('hidden');
4816	                    }
4817	                });
4818	                  
4819	            },
4820
4821	            setup: function() {
4822                    
4823	                //window.site.overlays.search.open($('#search'));
4824
4825	                $('#search_menu, .search-close-button').unbind().click(function() {
4826	                    // For accessibility - tracks which element to refocus on
4827                        try {
4828                            h.accessibility.global_variables.element_to_refocus_to = $(this);
4829                        } catch(error) {
4830                            console.error(error);
4831                        }
4832	                	var clicked_element = $(this);
4833	                    $('body').addClass('active-init search-overlay-open');
4834	                    window.setTimeout(function() {
4835	                        if ($('.search-overlay').hasClass('active')) {
4836                        		window.site.overlays.search.close();
4837                        		h.accessibility.on_popup_closing('#search_menu');
4838	                        } else {
4839                        		window.site.overlays.search.open(clicked_element);
4840                        		h.accessibility.on_popup_opening('.search-overlay', 'input#sw_field_search', '.search-close-button');
4841	                        }
4842	                    }, 50, clicked_element);
4843	                    return false;
4844	                });
4845
4846	                $('#sw_form').each(function() {
4847	                	if (!$(this).find('.form_row .loader').length) {
4848	                		$(this).find('.form_row').append('<span class="loader"></span>');
4849	                	}
4850	                });
4851
4852	                $('#quick_search_widget .button a').unbind().click(function() {
4853	                    window.site.overlays.search.submit_form($(this).closest('#quick_search_widget').find('form'));
4854	                    return false;
4855	                });
4856
4857	            },
4858
4859	            close: function() {
4860                    window.setTimeout(function() {
4861                        $('body').removeClass('active-init');
4862                    }, 600);
4863                    $('body').removeClass('search-overlay-open');
4864                    $('.search-overlay .overlay-bg').removeClass('open');
4865                    $('.search-overlay').removeClass('active');
4866                    $('body, html').removeClass('overlay-open');
4867                    $('.search-wrapper.visible').removeClass('visible');
4868	            },
4869
4870	            open: function(clicked_element, data) {
4871                	$('#container_outer').removeClass('scrolling-down scrolling-up');
4872                    $('.search-overlay .overlay-bg').addClass('open');
4873                    $('.search-overlay').addClass('active');
4874                    $('body, html').addClass('overlay-open');
4875                    
4876                    $('.search-wrapper:not(.visible)').each(function(i) {
4877                        var $item = $(this);
4878                        setTimeout(function() {
4879                            $item.addClass('visible')
4880                        }, 300*i);
4881                    });
4882
4883	                if (window.ga) {
4884	                    // Track the click in Analytics
4885                        analytics_params = {
4886                          'hitType': 'event',
4887                          'eventCategory': 'Search form opened',
4888                          'eventAction': window.location.pathname,
4889                          'eventLabel': $(document).attr('title')
4890                        };
4891                        ga('send', analytics_params);
4892                        ga('tracker2.send', analytics_params);
4893	                }
4894	                $('input#sw_field_search')[0].focus();
4895
4896	            },
4897
4898	            clear_form: function() {
4899	                window.site.overlays.search_form.reset_form();
4900	            },
4901
4902	            submit_form: function(instance) {
4903
4904	            },
4905
4906	            after_submit: function() {
4907
4908	            }
4909
4910	        },
4911
4912	        search_form: {
4913
4914	            init: function() {
4915
4916	                window.site.overlays.search_form.setup();
4917
4918	            },
4919
4920	            setup: function() {
4921
4922
4923	                $('input#sw_field_search')
4924	                    .unbind()
4925	                    .each(function() {
4926
4927	                    })
4928	                    .blur(function() {
4929	                        if ($(this).val() == '') {
4930	                            $(this).removeClass('active');
4931	                        }
4932	                    })
4933	                    .focus(function() {
4934	                        if ($(this).val() == '') {
4935	                            $(this).addClass('active');
4936	                        }
4937	                    })
4938	                    .keypress(function(e) {
4939	                        window.site.overlays.search_form.form_submit();
4940	                    })
4941	                ;
4942
4943	                $('#sw_field_search_button').unbind().bind('click', function() {
4944	                    window.site.overlays.search_form.form_submit();
4945	                    return false;
4946	                });
4947
4948	                $('input#sw_field_search').closest('form').submit(function() {
4949	                    return false;
4950	                });
4951
4952	                $('#sw_more').unbind('click.search_view_more_actions').bind('click.search_view_more_actions', function() {
4953	                    
4954	                });
4955	                
4956	            },
4957
4958	            form_submit: function() {
4959	                var search_value = $('input#sw_field_search').val();
4960	                if (search_value && search_value.length >= 2) {
4961	                    $('input#sw_field_search').stop().clearQueue();
4962	                    $('.search-overlay').addClass('search-loading');
4963	                    $('input#sw_field_search')
4964	                        .animate({'opacity': '1'}, 600, function() {
4965	                            var element_href = '/search/results/?s=' + search_value + '&instant=1';
4966	                            $.pageload.load(element_href, true, function() {
4967	                                if (new_page_inner_content) {
4968	                                    $('#quick_search_widget .notify_panel_content').scrollTop(0);
4969	                                    $('#sw_results').html(new_page_inner_content);
4970	                                    $('.search-overlay').removeClass('search-loading search-results-active').addClass(' search-first-interaction');
4971	                                    if ($('#sw_results .item').not('.search-grid-no-results').length) {
4972	                                        $('.search-overlay').addClass('search-results-active');
4973	                                        $('#sw_more').attr('href', element_href.replace('&instant=1', ''));
4974	                                    }
4975	                                    window.site.overlays.search.filters();
4976	                                    window.site.layout.grids.init();
4977                                        window.site.lazy_load.setup();
4978                                        //window.site.lazy_load.fire($('#sw_results .image_lazy_load'));
4979	                                    window.site.artlogic_inview.init();
4980	                                    $(window).trigger('resize');
4981	                                    $.pageload.refresh($('#quick_search_widget'));
4982	                                }
4983	                            }, null, null, null, 'inner', '.site-ajax-enabled-inner-content');
4984	                        })
4985	                    ;
4986	                }
4987	            },
4988
4989	            reset_form: function(instance) {
4990	                $('input#sw_field_search').val($('input#sw_field_search').attr('data-default-value'));
4991	                $('#sw_results').html('');
4992	            }
4993
4994	        },
4995	        
4996            mailings: {
4997
4998                init: function() {
4999                    window.site.overlays.mailings.setup();
5000                },
5001
5002                setup: function() {
5003
5004                    $('#mailinglist_signup_button, .mailing-close-button').unbind().click(function() {
5005                        var clicked_element = $(this);
5006                        $('body').addClass('active-init');
5007                        window.setTimeout(function() {
5008                            if ($('.mailing-overlay').hasClass('active')) {
5009                                window.site.overlays.mailings.close();
5010                            } else {
5011                                window.site.overlays.mailings.open(clicked_element);
5012                            }
5013                        }, 50, clicked_element);
5014                        return false;
5015                    });
5016                    
5017                    window.site.overlays.mailings.auto();
5018
5019                },
5020                
5021                auto: function() {
5022                    
5023                    // Do not automatically open
5024                    return false;
5025                    
5026                    // Auto open on all pages other than the homepage
5027                    if (window.location.pathname != '/') {
5028                        
5029                        var cookie_info = h.getCookie('mailinglist_signup_generic_shown');
5030                        var popup_shown = cookie_info && typeof cookie_info != 'undefined' ? true : false;
5031                        
5032                        if (!popup_shown) {
5033                            mailings_popup_timeout = setTimeout(function() {
5034                                if (!$('body').hasClass('loader-active') && !$('body').hasClass('splash-init') && !$('body').hasClass('splash-open')) {
5035                                    window.site.scroll.dropdown_navigation.close();
5036                                    
5037                                    if ($('body').hasClass('header-dropdown-active')) {
5038                                        window.site.misc.hideDropdown();
5039                                    }
5040                                    
5041                                    $('body').addClass('active-init');
5042                                    window.setTimeout(function() {
5043                                        if (window.location.pathname == '/store/') {
5044                                            window.site.overlays.mailings.open(null, null, 'prints');
5045                                        } else {
5046                                            window.site.overlays.mailings.open();
5047                                        }
5048                                    }, 50);
5049                                    h.setCookie('mailinglist_signup_generic_shown', true, 30);
5050                                }
5051                            }, 2000);
5052                        }
5053                        
5054                    }
5055                    
5056                },
5057
5058                close: function() {
5059                    window.setTimeout(function() {
5060                        if (!$('.overlay.active').not('.mailing-overlay').length) {
5061                            $('body').removeClass('active-init');
5062                        }
5063                    }, 600);
5064
5065                    if (!$('.overlay.active').not('.mailing-overlay').length) {
5066                        $('body, html').removeClass('overlay-open');
5067                    }
5068
5069                    //$('body').removeClass('quick_contact_widget_active');
5070                    $('.mailing-overlay .overlay-bg').removeClass('open');
5071                    $('.mailing-overlay').removeClass('active');
5072
5073                    $(".mailing-input-wrapper.visible, .mailing-contact-wrapper.visible").removeClass('visible');
5074                },
5075
5076                open: function(clicked_element, data, form_type) {
5077                    $('#container_outer').removeClass('scrolling-down scrolling-up');
5078                    $('.mailing-overlay .overlay-bg').addClass('open');
5079                    $('.mailing-overlay').addClass('active');
5080                    $('body, html').addClass('overlay-open');
5081                    
5082                    $(".mailing-input-wrapper:not(.visible),.mailing-contact-wrapper:not(.visible)").each(function(i){
5083                        var $item = $(this);
5084                        setTimeout(function() {
5085                            $item.addClass('visible')
5086                        }, 300);
5087                    });
5088
5089                    if (window.ga) {
5090                        // Track the click in Analytics
5091                        analytics_params = {
5092                          'hitType': 'event',
5093                          'eventCategory': 'Mailing list form opened',
5094                          'eventAction': window.location.pathname,
5095                          'eventLabel': $(document).attr('title')
5096                        };
5097                        ga('send', analytics_params);
5098                        ga('tracker2.send', analytics_params);
5099                    }
5100
5101                    var form_type = form_type && typeof form_type != 'undefined' ? form_type : 'standard';
5102                    var data = data && typeof data != 'undefined' ? data : {};
5103                
5104                    // Reset form
5105                    $('#mailinglist_signup .form_checkboxes input').prop('checked', false);
5106                    $('#mailinglist_signup').removeClass('variant_prints variant_collector');
5107                    
5108                    // Load fields as required
5109                    if (form_type == 'prints') {
5110                        $('#mailinglist_signup').addClass('variant_prints');
5111                        $('#mailinglist_signup .form_checkboxes input.checkbox_required_prints').prop('checked', true);
5112                    } else if (form_type == 'collector') {
5113                        $('#mailinglist_signup').addClass('variant_collector');
5114                        $('#mailinglist_signup .form_checkboxes input.checkbox_required_collector').prop('checked', true);
5115                    } else {
5116                        $('#mailinglist_signup .form_checkboxes input').prop('checked', false);
5117                        $('#mailinglist_signup .form_checkboxes input.checkbox_required_standard').prop('checked', true);
5118                    }
5119
5120                }
5121
5122            },
5123
5124            enquire: {
5125
5126                init: function() {
5127                    window.site.overlays.enquire.setup();
5128                    if ($('.contact_form_captcha_enabled').length > 0) {
5129                        if (typeof google_captcha_onload != 'undefined') {
5130                            google_captcha_onload();
5131                        }
5132                    }
5133                },
5134
5135                setup: function() {
5136                    
5137                    $('input, textarea', '#artlogic_mailinglist_signup_form')
5138                        .each(function() {
5139                            $(this).attr('default-value', $(this).parent().find('> label').text());
5140                            $(this).attr('placeholder', $(this).parent().find('> label').text());
5141                            if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
5142                                $(this).addClass('active');
5143                            } else {
5144                                $(this).val($(this).attr('default-value'));
5145                            }
5146                        })
5147                        .change(function() {
5148                            $(this).closest('.form_row').removeClass('error');
5149                        })
5150                        .focus(function() {
5151                            $(this).closest('.form_row').removeClass('error');
5152                            if ($(this).val() == $(this).attr('default-value')) {
5153                                $(this).addClass('active');
5154                                $(this).val('');
5155                            }
5156                        })
5157                        .blur(function() {
5158                            $(this).attr('default-value', $(this).parent().find('label').text());
5159                            if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
5160                                $(this).val($(this).attr('default-value'));
5161                                $(this).removeClass('active');
5162                            }
5163                        })
5164                    ;
5165
5166                    $('.enquire_link, .website_contact_form, .enquire-close-button').unbind().click(function() {
5167                        
5168                        var clicked_element = $(this);
5169                        $('body').addClass('active-init');
5170                        window.setTimeout(function() {
5171                            if ($('.enquire-overlay').hasClass('active')) {
5172                                window.site.overlays.enquire.close();
5173                            } else {
5174                                // For accessibility - tracks which element to refocus on
5175                                try {
5176                                    h.accessibility.global_variables.element_to_refocus_to = clicked_element;
5177                                } catch(error) {
5178                                    console.error(error);
5179                                }
5180                                window.site.overlays.enquire.open(clicked_element, {}, clicked_element.attr('data-type'));
5181                            }
5182                        }, 50, clicked_element);
5183                        return false;
5184                    });
5185
5186                    $('input, textarea', '#quick_contact_widget')
5187                        .each(function() {
5188                            $(this).attr('default-value', $(this).parent().find('> label').text());
5189                            $(this).attr('placeholder', $(this).parent().find('> label').text());
5190                            if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
5191                                $(this).addClass('active');
5192                            } else {
5193                                $(this).val($(this).attr('default-value'));
5194                            }
5195                        })
5196                        .change(function() {
5197                            $(this).closest('.form_row').removeClass('error');
5198                        })
5199                        .focus(function() {
5200                            $(this).closest('.form_row').removeClass('error');
5201                            if ($(this).val() == $(this).attr('default-value')) {
5202                                $(this).addClass('active');
5203                                $(this).val('');
5204                            }
5205                            var field_offset_top = $(this).offset().top - 200;
5206                            $('#quick_contact_widget .notify_panel_content').animate({'scrollTop': field_offset_top}, 0);
5207                        })
5208                        .blur(function() {
5209                            $(this).attr('default-value', $(this).parent().find('label').text());
5210                            if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
5211                                $(this).val($(this).attr('default-value'));
5212                                $(this).removeClass('active');
5213                            }
5214                        })
5215                    ;
5216
5217                    $('select', '#quick_contact_widget')
5218                        .each(function() {
5219                            $(this).attr('default-value', $(this).val());
5220                        })
5221                        .change(function() {
5222                            if ($(this).val() != '') {
5223                                $(this).addClass('active');
5224                            } else {
5225                                $(this).removeClass('active');
5226                            }
5227                        })
5228                    ;
5229
5230                    $('#quick_contact_widget .notify_panel_close').unbind().click(function() {
5231                        window.site.enquiry.close();
5232                    });
5233
5234                    $('#quick_contact_widget .button a, #quick_contact_widget button').unbind().click(function() {
5235                        window.site.overlays.enquire.submit_form($(this).closest('#quick_contact_widget').find('form'));
5236                        return false;
5237                    });
5238
5239                    $('#quick_contact_widget').each(function() {
5240                        if (!$(this).hasClass('initialized')) {
5241                            if (false) {
5242                                $.ajax({
5243                                    url: "/custom/get_user_data/",
5244                                    cache: false,
5245                                    method: 'POST',
5246                                    success: function(data) {
5247                                        if (data) {
5248                                            var parsed_data = JSON.parse(data);
5249                                            $.each(parsed_data, function(k, v) {
5250                                                if (v && v != '') {
5251                                                    $('#quick_contact_widget').find('input[name="' + k + '"]').val(v).addClass('active');
5252                                                }
5253                                            });
5254                                        }
5255                                    }
5256                                });
5257                            }
5258                        }
5259                        $(this).addClass('initialized');
5260                    });
5261
5262                },
5263
5264                close: function() {
5265                    window.setTimeout(function() {
5266                        if (!$('.overlay.active').not('.enquire-overlay').length) {
5267                            $('body').removeClass('active-init');
5268                        }
5269                    }, 600);
5270
5271                    if (!$('.overlay.active').not('.enquire-overlay').length) {
5272                        $('body, html').removeClass('overlay-open');
5273                    }
5274
5275                    $('body').removeClass('quick_contact_widget_active');
5276                    $('.enquire-overlay .overlay-bg').removeClass('open');
5277                    $('.enquire-overlay').removeClass('active');
5278
5279                    $(".enquire-input-wrapper.visible, .enquire-contact-wrapper.visible").removeClass('visible');
5280                    h.accessibility.on_popup_closing();
5281                },
5282
5283                open: function(clicked_element, data, form_type) {
5284                    $('#container_outer').removeClass('scrolling-down scrolling-up');
5285                    $('.enquire-overlay .overlay-bg').addClass('open');
5286                    $('.enquire-overlay').addClass('active');
5287                    $('body, html').addClass('overlay-open');
5288                    
5289                    $('#qcw_field_item').val('');
5290                    $('#quick_contact_widget form #qcw_field_artist_interest').val('');
5291                    $('#quick_contact_widget form #qcw_field_artwork_interest').val('');
5292                    $('#quick_contact_widget form #qcw_field_email_to').val('');
5293                    
5294                    $('#quick_contact_widget form #qcw_field_message').val($('#quick_contact_widget form #qcw_field_message').attr('default-value'));
5295                    
5296                    if ($('#quick_contact_widget #qcw_main_header[data-default-label]').length == 0) {
5297                        $('#quick_contact_widget #qcw_main_header').attr('data-default-label', $('#quick_contact_widget #qcw_main_header').text());
5298                    }
5299                    $('#quick_contact_widget #qcw_main_header').text($('#quick_contact_widget #qcw_main_header').attr('data-default-label'));
5300                    $('#quick_contact_widget #qcw_main_subheader').show();
5301            
5302                    
5303                    
5304                    $(".enquire-input-wrapper:not(.visible),.enquire-contact-wrapper:not(.visible)").each(function(i){
5305                        var $item = $(this);
5306                        setTimeout(function() {
5307                            $item.addClass('visible')
5308                        }, 500);
5309                    });
5310
5311                    if (window.ga) {
5312                        // Track the click in Analytics
5313                        analytics_params = {
5314                          'hitType': 'event',
5315                          'eventCategory': 'Enquiry form opened',
5316                          'eventAction': window.location.pathname,
5317                          'eventLabel': $(document).attr('title')
5318                        };
5319                        ga('send', analytics_params);
5320                        ga('tracker2.send', analytics_params);
5321                    }
5322
5323                    var form_type = form_type && typeof form_type != 'undefined' ? form_type : 'standard';
5324                    var data = data && typeof data != 'undefined' ? data : {};
5325                    var item_table = '';
5326                    var item_id = '';
5327                    
5328
5329                    $('body').addClass('quick_contact_widget_active');
5330                    $('#quick_contact_widget').addClass('active');
5331                    $('#quick_contact_widget').clearQueue().delay(10).queue(function() {
5332                        $(this).addClass('animate').dequeue();
5333                    });
5334                    $('#quick_contact_widget').removeClass('success enquiry-type-event-interest');
5335
5336                    $('#quick_contact_widget form #qcw_field_originating_page').val(window.location.pathname);
5337                    
5338                    if (clicked_element && typeof clicked_element != 'undefined') {
5339                        var additional_field_content = $(clicked_element).attr('data-contact-form-details');
5340                        var additional_field_image = $(clicked_element).attr('data-contact-form-image');
5341                        var additional_field_parent_id = $(clicked_element).attr('data-contact-form-parent-id');
5342                        
5343                        var item_table = $(clicked_element).attr('data-item-table') && typeof $(clicked_element).attr('data-item-table') != 'undefined' ? $(clicked_element).attr('data-item-table') : '';
5344                        var item_id = $(clicked_element).attr('data-item-id') && typeof $(clicked_element).attr('data-item-id') != 'undefined' ? $(clicked_element).attr('data-item-id') : '';
5345                        
5346                        var additional_field_artist_interest = $(clicked_element).attr('data-contact-form-artist-interest') && typeof $(clicked_element).attr('data-contact-form-artist-interest') != 'undefined' ? $(clicked_element).attr('data-contact-form-artist-interest') : '';
5347                        var additional_field_artwork_interest = $(clicked_element).attr('data-contact-form-artwork-interest') && typeof $(clicked_element).attr('data-contact-form-artwork-interest') != 'undefined' ? $(clicked_element).attr('data-contact-form-artwork-interest') : '';
5348                        var form_type = $(clicked_element).attr('data-type') && typeof $(clicked_element).attr('data-type') != 'undefined' ? $(clicked_element).attr('data-type') : form_type;
5349                        var form_subtype = $(clicked_element).attr('data-subtype') && typeof $(clicked_element).attr('data-subtype') != 'undefined' ? $(clicked_element).attr('data-subtype') : '';
5350                        
5351                        var email_address_to = $(clicked_element).attr('data-contact-form-to') && typeof $(clicked_element).attr('data-contact-form-to') != 'undefined' ? $(clicked_element).attr('data-contact-form-to') : '';
5352                        $('#quick_contact_widget form #qcw_field_email_to').val(email_address_to);
5353                        
5354                        var email_address_to_bcc = $(clicked_element).attr('data-contact-form-to-bcc') && typeof $(clicked_element).attr('data-contact-form-to-bcc') != 'undefined' ? $(clicked_element).attr('data-contact-form-to-bcc') : '';
5355                        $('#quick_contact_widget form #qcw_field_email_to_bcc').val(email_address_to_bcc);
5356                        
5357                        var heading_label = $(clicked_element).attr('data-contact-form-heading') && typeof $(clicked_element).attr('data-contact-form-heading') != 'undefined' ? $(clicked_element).attr('data-contact-form-heading') : '';
5358                        if (heading_label != '') {
5359                            $('#quick_contact_widget #qcw_main_header').text(heading_label);
5360                            $('#quick_contact_widget #qcw_main_subheader').hide();
5361                        }
5362                    }
5363
5364                    $('#qcw_field_contact_type').val(form_type);
5365                    $('#qcw_field_item_table').val(item_table);
5366                    $('#qcw_field_item_id').val(item_id);
5367
5368                    if (form_type == 'event-interest') {
5369                        $('#quick_contact_widget').addClass('enquiry-type-event-interest');
5370                    }
5371
5372                    if (additional_field_content || form_type == 'sales') {
5373
5374                        // Sales / artwork enquiry form type
5375                        if (additional_field_content) {
5376                            $('#quick_contact_widget form #qcw_field_artist_interest').val(additional_field_artist_interest);
5377                            $('#quick_contact_widget form #qcw_field_artwork_interest').val(additional_field_artwork_interest);
5378                            
5379                            if ($('#quick_contact_widget .notify_panel_items').length) {
5380                                $('#quick_contact_widget .notify_panel_items').html('<ul><li></li></ul>');
5381                                $('#quick_contact_widget .notify_panel_items li').html('<div class="content">' + decodeURIComponent(additional_field_content) + '</div>');
5382                                if (additional_field_image) {
5383                                    var website_domain = '';
5384                                    if (additional_field_image.substr(0,7) != 'http://' && additional_field_image.substr(0,8) != 'https://') {
5385                                        var website_domain = 'http://' + document.location.host;
5386                                    }
5387                                    $('#quick_contact_widget .notify_panel_items li').prepend('<div class="image"><div><img alt="" src="' + website_domain + additional_field_image + '"/></div></div>');
5388                                }
5389                                $('#quick_contact_widget form #qcw_field_item').val(encodeURIComponent($('#quick_contact_widget .notify_panel_items').html()));
5390                            }
5391                        }
5392                    }
5393                    
5394                    // focus trap the popup
5395                    h.accessibility.on_popup_opening('.enquire-overlay', '#qcw_field_name', '.enquire-overlay .enquire-close-button');
5396                },
5397
5398                clear_form: function() {
5399                    $('#qcw_field_item').val('');
5400                    $('#quick_contact_widget form #qcw_field_artist_interest').val('');
5401                    $('#quick_contact_widget form #qcw_field_artwork_interest').val('');
5402                    $('#qcw_field_message', '#quick_contact_widget').each(function() {
5403                        $(this).val($(this).attr('default-value')).removeClass('active');
5404                    });
5405                    $('#qcw_field_subject', '#quick_contact_widget').each(function() {
5406                        $(this).val('').removeClass('active');
5407                    });
5408                    $('#quick_contact_widget .notify_panel_items').html('');
5409                },
5410
5411                submit_form: function(instance) {
5412
5413                    if (instance) {
5414                        // Process captcha
5415                        if ($(instance).hasClass('contact_form_captcha_enabled')) {
5416                            if (!$('body').hasClass('contact_form_captcha_challenge_passed')) {
5417                                var captcha_error = '<h2>Sorry</h2>An error occurred, please refresh this page and try again. If you continue to have problems please contact us for support.';
5418                                if (typeof grecaptcha != 'undefined') {
5419                                    window.recaptcha_success_callback_instance = instance;
5420                                    window.recaptcha_success_callback = function (instance) {
5421                                        window.site.overlays.enquire.submit_form(instance);
5422                                    };
5423                                    try {
5424                                        grecaptcha.execute();
5425                                    } catch (error_message) {
5426                                        h.alert(captcha_error);
5427                                        $(instance).removeClass('submitting');
5428                                        $('.button', instance).removeClass('loading');
5429                                        $.ajax({
5430                                            url: "/api/process_js_error/",
5431                                            data: 'type=captcha&message=Captcha error on page ' + window.location.pathname + ' Error message: ' + error_message,
5432                                            cache: false
5433                                        });
5434                                    }
5435                                } else {
5436                                    h.alert(captcha_error);
5437                                    $(instance).removeClass('submitting');
5438                                    $('.button', instance).remove
5438Class('loading');
5439                                    var error_message = 'Unknown error - grecaptcha may be undefined'
5440                                    $.ajax({
5441                                        url: "/api/process_js_error/",
5442                                        data: 'type=captcha&message=Captcha error on page ' + window.location.pathname + ' Error message: ' + error_message,
5443                                        cache: false
5444                                    });
5445                                }
5446                                return;
5447                                
5448                            } else {
5449                                $('body').removeClass('contact_form_captcha_challenge_passed');
5450                            }
5451                        }
5452                        $('#quick_contact_widget .button').addClass('loading');
5453                        $('.error_row', instance).removeClass('active');
5454
5455                        data = 'submit=1&';
5456                        $('input, select, textarea', instance).each(function() {
5457                            var field_value = $(this).val();
5458                            if ($(this).attr('type') == 'radio') {
5459                            	if ($(this).is(':checked')) {
5460                                	data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
5461                            	}
5462                            } else {
5463                                if (field_value != $(this).attr('default-value')) {
5464                                    if ($(this).attr('type') == 'checkbox') {
5465                                        if ($(this).attr('name') == 'terms') {
5466                                            var field_value = $(this).is(':checked') ? '1' : '';
5467                                        } else {
5468                                            var field_value = $(this).is(':checked') ? 'Yes' : 'No';
5469                                        }
5470                                    }
5471    
5472                                    if ($(this).attr('name') == 'message') {
5473                                        data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />').replace('%', 'percent') + '&';
5474                                    } else {
5475                                        data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
5476                                    }
5477                                }
5478                            }
5479                        });
5480
5481                        data = data + 'originating_page=' + encodeURIComponent(window.location.pathname + window.location.search) + '&';
5482
5483                        $.ajax({
5484                            url: "/enquiry/",
5485                            data: data,
5486                            cache: false,
5487                            method: 'POST',
5488                            dataType: 'json',
5489                            success: function(data) {
5490                                setTimeout(function() {
5491                                    $('#quick_contact_widget .button').removeClass('loading');
5492                                }, 1600);
5493                                $('#quick_contact_widget')
5494                                    .delay(400)
5495                                    .queue(function() {
5496                                        if (data['success'] == 1) {
5497                                            
5498                                            window.archimedes.archimedes_core.analytics.track_campaigns.save_form_data($('#quick_contact_widget'));
5499
5500                                            $('#quick_contact_widget').addClass('success');
5501
5502                                            if ($('.contact_form_captcha_enabled').length > 0) {
5503                                                if (typeof grecaptcha != 'undefined') {
5504                                                    grecaptcha.reset();
5505                                                }
5506                                            }
5507
5508                                            if (window.ga) {
5509                                                // Track in Analytics
5510                                                analytics_params = {
5511                                                  'hitType': 'event',
5512                                                  'eventCategory': 'Enquiry form submit success',
5513                                                  'eventAction': window.location.pathname,
5514                                                  'eventLabel': $(document).attr('title')
5515                                                };
5516                                                ga('send', analytics_params);
5517                                                ga('tracker2.send', analytics_params);
5518                                            }
5519
5520                                            window.site.overlays.enquire.close();
5521
5522                                            $('#quick_contact_widget')
5523                                                .delay(200)
5524                                                .queue(function() {
5525                                                    h.alert('<h2>Thank you</h2><div>Your inquiry has been sent and we will be in contact shortly.</div>
5525', {buttons: false});
5526                                                    $(this).dequeue();
5527                                                })
5528                                            ;
5529
5530                                        } else {
5531                                            var error_message = '';
5532                                            if (data['error_message'] && typeof data['error_message'] != 'undefined') {
5533                                                var error_message = data['error_message'];
5534                                            }
5535                                            var field_errors = [];
5536                                            if (data['field_errors'] && typeof data['field_errors'] != 'undefined') {
5537                                                var field_errors = data['field_errors'];
5538                                            }
5539                                            $.each(field_errors, function(i, v) {
5540                                                $('#quick_contact_widget').find('[name="' + v + '"]').closest('.form_row').addClass('error');
5541                                            });
5542                                            if (error_message) {
5543                                                h.alert(error_message, {buttons: fal
5543se});
5544                                            }
5545
5546                                            if ($('.contact_form_captcha_enabled').length > 0) {
5547                                                if (typeof grecaptcha != 'undefined') {
5548                                                    grecaptcha.reset();
5549                                                }
5550                                            }
5551
5552                                            if (window.ga) {
5553                                                // Track in Analytics
5554                                                analytics_params = {
5555                                                  'hitType': 'event',
5556                                                  'eventCategory': 'Enquiry form submit error',
5557                                                  'eventAction': window.location.pathname,
5558                                                  'eventLabel': $(document).attr('title')
5559                                                };
5560                                                ga('send', analytics_params);
5561                                                ga('tracker2.send', analytics_params);
5562                                            }
5563
5564                                        }
5565                                        $(this).dequeue();
5566                                    })
5567                               ;
5568                            }
5569                        });
5570                    }
5571                },
5572
5573                after_submit: function() {
5574
5575                }
5576
5577            },
5578            
5579            gallery_contact: {
5580                
5581                init: function() {
5582                    window.site.overlays.gallery_contact.setup();
5583                    if ($('.contact_form_captcha_enabled').length > 0) {
5584                        if (typeof google_captcha_onload != 'undefined') {
5585                            google_captcha_onload();
5586                        }
5587                    }
5588                },
5589
5590                setup: function() {
5591                    
5592                    $('.gallery-contact-open-button, .gallery-contact-close-button').unbind().click(function() {
5593                        
5594                        var clicked_element = $(this);
5595                        $('body').addClass('active-init');
5596                        window.setTimeout(function() {
5597                            if ($('.gallery-contact-overlay').hasClass('active')) {
5598                                window.site.overlays.gallery_contact.close();
5599                            } else {
5600                                // For accessibility - tracks which element to refocus on
5601                                try {
5602                                    h.accessibility.global_variables.element_to_refocus_to = clicked_element;
5603                                } catch(error) {
5604                                    console.error(error);
5605                                }
5606                                window.site.overlays.gallery_contact.open(clicked_element, {}, clicked_element.attr('data-type'));
5607                            }
5608                        }, 50, clicked_element);
5609                        return false;
5610                    });
5611
5612                    $('input, textarea', '#gallery_contact_widget')
5613                        .each(function() {
5614                            if (!$(this).hasClass('gallery_contact_message')) {
5615                                $(this).attr('default-value', $(this).parent().find('> label').text());
5616                                $(this).attr('placeholder', $(this).parent().find('> label').text());
5617                            }
5618                            if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
5619                                $(this).addClass('active');
5620                            } else {
5621                                $(this).val($(this).attr('default-value'));
5622                            }
5623                        })
5624                        .change(function() {
5625                            $(this).closest('.form_row').removeClass('error');
5626                        })
5627                        .focus(function() {
5628                            $(this).closest('.form_row').removeClass('error');
5629                            if ($(this).val() == $(this).attr('default-value')) {
5630                                $(this).addClass('active');
5631                                $(this).val('');
5632                            }
5633                            var field_offset_top = $(this).offset().top - 200;
5634                            $('#gallery_contact_widget .notify_panel_content').animate({'scrollTop': field_offset_top}, 0);
5635                        })
5636                        .blur(function() {
5637                            if (!$(this).hasClass('gallery_contact_message')) {
5638                                $(this).attr('default-value', $(this).parent().find('label').text());
5639                            }
5640                            if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
5641                                $(this).val($(this).attr('default-value'));
5642                                $(this).removeClass('active');
5643                            }
5644                        })
5645                    ;
5646
5647                    $('select', '#gallery_contact_widget')
5648                        .each(function() {
5649                            $(this).attr('default-value', $(this).val());
5650                        })
5651                        .change(function() {
5652                            if ($(this).val() != '') {
5653                                $(this).addClass('active');
5654                            } else {
5655                                $(this).removeClass('active');
5656                            }
5657                        })
5658                    ;
5659
5660                    $('#gallery_contact_widget .notify_panel_close').unbind().click(function() {
5661                        window.site.gallery_contact.close();
5662                    });
5663
5664                    $('#gallery_contact_widget .button a, #gallery_contact_widget button').unbind().click(function() {
5665                        window.site.overlays.gallery_contact.submit_form($(this).closest('#gallery_contact_widget').find('form'));
5666                        return false;
5667                    });
5668
5669                    $('#gallery_contact_widget').each(function() {
5670                        if (!$(this).hasClass('initialized')) {
5671                            if (false) {
5672                                $.ajax({
5673                                    url: "/custom/get_user_data/",
5674                                    cache: false,
5675                                    method: 'POST',
5676                                    success: function(data) {
5677                                        if (data) {
5678                                            var parsed_data = JSON.parse(data);
5679                                            $.each(parsed_data, function(k, v) {
5680                                                if (v && v != '') {
5681                                                    $('#gallery_contact_widget').find('input[name="' + k + '"]').val(v).addClass('active');
5682                                                }
5683                                            });
5684                                        }
5685                                    }
5686                                });
5687                            }
5688                        }
5689                        $(this).addClass('initialized');
5690                    });
5691
5692                },
5693
5694                close: function() {
5695                    window.setTimeout(function() {
5696                        if (!$('.overlay.active').not('.gallery-contact-overlay').length) {
5697                            $('body').removeClass('active-init');
5698                        }
5699                    }, 600);
5700
5701                    if (!$('.overlay.active').not('.gallery-contact-overlay').length) {
5702                        $('body, html').removeClass('overlay-open');
5703                    }
5704
5705                    $('body').removeClass('quick_contact_widget_active');
5706                    $('.gallery-contact-overlay .overlay-bg').removeClass('open');
5707                    $('.gallery-contact-overlay').removeClass('active');
5708
5709                    $(".gallery-contact-input-wrapper.visible").removeClass('visible');
5710                    h.accessibility.on_popup_closing();
5711                },
5712
5713                open: function(clicked_element, data, form_type) {
5714                    $('#container_outer').removeClass('scrolling-down scrolling-up');
5715                    $('.gallery-contact-overlay .overlay-bg').addClass('open');
5716                    $('.gallery-contact-overlay').addClass('active');
5717                    $('body, html').addClass('overlay-open');
5718                    
5719                    $('#gcw_field_item').val('');
5720                    $('#gallery_contact_widget form #gcw_field_artist_interest').val('');
5721                    $('#gallery_contact_widget form #gcw_field_artwork_interest').val('');
5722                    $('#gallery_contact_widget form #gcw_field_email_to').val('');
5723                    
5724                    $('#gallery_contact_widget form #gcw_field_message').val($('#gallery_contact_widget form #gcw_field_message').attr('default-value'));
5725                    
5726                    if ($('#gallery_contact_widget #gcw_main_header[data-default-label]').length == 0) {
5727                        $('#gallery_contact_widget #gcw_main_header').attr('data-default-label', $('#gallery_contact_widget #gcw_main_header').text());
5728                    }
5729                    $('#gallery_contact_widget #gcw_main_header').text($('#gallery_contact_widget #gcw_main_header').attr('data-default-label'));
5730                    $('#gallery_contact_widget #gcw_main_subheader').show();
5731                    
5732                    $(".gallery-contact-input-wrapper:not(.visible)").each(function(i){
5733                        var $item = $(this);
5734                        setTimeout(function() {
5735                            $item.addClass('visible')
5736                        }, 500);
5737                    });
5738
5739                    if (window.ga) {
5740                        // Track the click in Analytics
5741                        analytics_params = {
5742                          'hitType': 'event',
5743                          'eventCategory': 'Gallery contact form opened',
5744                          'eventAction': window.location.pathname,
5745                          'eventLabel': $(document).attr('title')
5746                        };
5747                        ga('send', analytics_params);
5748                        ga('tracker2.send', analytics_params);
5749                    }
5750
5751                    var form_type = form_type && typeof form_type != 'undefined' ? form_type : 'standard';
5752                    var data = data && typeof data != 'undefined' ? data : {};
5753                    var item_table = '';
5754                    var item_id = '';
5755                    
5756
5757                    $('body').addClass('quick_contact_widget_active');
5758                    $('#gallery_contact_widget').addClass('active');
5759                    $('#gallery_contact_widget').clearQueue().delay(10).queue(function() {
5760                        $(this).addClass('animate').dequeue();
5761                    });
5762                    $('#gallery_contact_widget').removeClass('success enquiry-type-event-interest');
5763
5764                    $('#gallery_contact_widget form #gcw_field_originating_page').val(window.location.pathname);
5765                    
5766                    if (clicked_element && typeof clicked_element != 'undefined') {
5767                        var additional_field_content = $(clicked_element).attr('data-contact-form-details');
5768                        var additional_field_image = $(clicked_element).attr('data-contact-form-image');
5769                        var additional_field_parent_id = $(clicked_element).attr('data-contact-form-parent-id');
5770                        
5771                        var item_table = $(clicked_element).attr('data-item-table') && typeof $(clicked_element).attr('data-item-table') != 'undefined' ? $(clicked_element).attr('data-item-table') : '';
5772                        var item_id = $(clicked_element).attr('data-item-id') && typeof $(clicked_element).attr('data-item-id') != 'undefined' ? $(clicked_element).attr('data-item-id') : '';
5773                        
5774                        var additional_field_artist_interest = $(clicked_element).attr('data-contact-form-artist-interest') && typeof $(clicked_element).attr('data-contact-form-artist-interest') != 'undefined' ? $(clicked_element).attr('data-contact-form-artist-interest') : '';
5775                        var additional_field_artwork_interest = $(clicked_element).attr('data-contact-form-artwork-interest') && typeof $(clicked_element).attr('data-contact-form-artwork-interest') != 'undefined' ? $(clicked_element).attr('data-contact-form-artwork-interest') : '';
5776                        var form_type = $(clicked_element).attr('data-type') && typeof $(clicked_element).attr('data-type') != 'undefined' ? $(clicked_element).attr('data-type') : form_type;
5777                        var form_subtype = $(clicked_element).attr('data-subtype') && typeof $(clicked_element).attr('data-subtype') != 'undefined' ? $(clicked_element).attr('data-subtype') : '';
5778                        
5779                        var email_address_to = $(clicked_element).attr('data-contact-form-to') && typeof $(clicked_element).attr('data-contact-form-to') != 'undefined' ? $(clicked_element).attr('data-contact-form-to') : '';
5780                        $('#gallery_contact_widget form #gcw_field_email_to').val(email_address_to);
5781                        
5782                        var email_address_to_bcc = $(clicked_element).attr('data-contact-form-to-bcc') && typeof $(clicked_element).attr('data-contact-form-to-bcc') != 'undefined' ? $(clicked_element).attr('data-contact-form-to-bcc') : '';
5783                        $('#gallery_contact_widget form #gcw_field_email_to_bcc').val(email_address_to_bcc);
5784                        
5785                        var heading_label = $(clicked_element).attr('data-contact-form-heading') && typeof $(clicked_element).attr('data-contact-form-heading') != 'undefined' ? $(clicked_element).attr('data-contact-form-heading') : '';
5786                        if (heading_label != '') {
5787                            $('#gallery_contact_widget #gcw_main_header').text(heading_label);
5788                            $('#gallery_contact_widget #gcw_main_subheader').hide();
5789                        }
5790                    }
5791
5792                    $('#gcw_field_contact_type').val(form_type);
5793                    $('#gcw_field_item_table').val(item_table);
5794                    $('#gcw_field_item_id').val(item_id);
5795
5796                    if (form_type == 'event-interest') {
5797                        $('#gallery_contact_widget').addClass('enquiry-type-event-interest');
5798                    }
5799
5800                    if (additional_field_content || form_type == 'sales') {
5801
5802                        // Sales / artwork enquiry form type
5803                        if (additional_field_content) {
5804                            $('#gallery_contact_widget form #gcw_field_artist_interest').val(additional_field_artist_interest);
5805                            $('#gallery_contact_widget form #gcw_field_artwork_interest').val(additional_field_artwork_interest);
5806                            
5807                            if ($('#gallery_contact_widget .notify_panel_items').length) {
5808                                $('#gallery_contact_widget .notify_panel_items').html('<ul><li></li></ul>');
5809                                $('#gallery_contact_widget .notify_panel_items li').html('<div class="content">' + decodeURIComponent(additional_field_content) + '</div>');
5810                                if (additional_field_image) {
5811                                    var website_domain = '';
5812                                    if (additional_field_image.substr(0,7) != 'http://' && additional_field_image.substr(0,8) != 'https://') {
5813                                        var website_domain = 'http://' + document.location.host;
5814                                    }
5815                                    $('#gallery_contact_widget .notify_panel_items li').prepend('<div class="image"><div><img alt="" src="' + website_domain + additional_field_image + '"/></div></div>');
5816                                }
5817                                $('#gallery_contact_widget form #gcw_field_item').val(encodeURIComponent($('#gallery_contact_widget .notify_panel_items').html()));
5818                            }
5819                        }
5820                    }
5821                    
5822                    // focus trap the popup
5823                    h.accessibility.on_popup_opening('.gallery-contact-overlay', '#gcw_field_first_name', '.gallery-contact-overlay .enquire-close-button');
5824                },
5825
5826                clear_form: function() {
5827                    $('#gcw_field_item').val('');
5828                    $('#gallery_contact_widget form #gcw_field_artist_interest').val('');
5829                    $('#gallery_contact_widget form #gcw_field_artwork_interest').val('');
5830                    $('#gcw_field_message', '#gallery_contact_widget').each(function() {
5831                        $(this).val($(this).attr('default-value')).removeClass('active');
5832                    });
5833                    $('#gcw_field_subject', '#gallery_contact_widget').each(function() {
5834                        $(this).val('').removeClass('active');
5835                    });
5836                    $('#gallery_contact_widget .notify_panel_items').html('');
5837                },
5838
5839                submit_form: function(instance) {
5840
5841                    if (instance) {
5842                        if ($(instance).hasClass('contact_form_captcha_enabled')) {
5843                            if (!$('body').hasClass('contact_form_captcha_challenge_passed')) {
5844                                var captcha_error = '<h2>Sorry</h2>An error occurred, please refresh this page and try again. If you continue to have problems please contact us for support.';
5845                                if (typeof grecaptcha != 'undefined') {
5846                                    window.recaptcha_success_callback_instance = instance;
5847                                    window.recaptcha_success_callback = function (instance) {
5848                                        window.site.overlays.gallery_contact.submit_form(instance);
5849                                    };
5850                                    try {
5851                                        grecaptcha.execute();
5852                                    } catch (error_message) {
5853                                        h.alert(captcha_error);
5854                                        $(instance).removeClass('submitting');
5855                                        $('.button', instance).removeClass('loading');
5856                                        $.ajax({
5857                                            url: "/api/process_js_error/",
5858                                            data: 'type=captcha&message=Captcha error on page ' + window.location.pathname + ' Error message: ' + error_message,
5859                                            cache: false
5860                                        });
5861                                    }
5862                                } else {
5863                                    h.alert(captcha_error);
5864                                    $(instance).removeClass('submitting');
5865                                    $('.button', instance).removeClass('loading');
5866                                    var error_message = 'Unknown error - grecaptcha may be undefined'
5867                                    $.ajax({
5868                                        url: "/api/process_js_error/",
5869                                        data: 'type=captcha&message=Captcha error on page ' + window.location.pathname + ' Error message: ' + error_message,
5870                                        cache: false
5871                                    });
5872                                }
5873                                return;
5874                                
5875                            } else {
5876                                $('body').removeClass('contact_form_captcha_challenge_passed');
5877                            }
5878                        }
5879                        $('#gallery_contact_widget .button').addClass('loading');
5880                        $('.error_row', instance).removeClass('active');
5881
5882                        data = 'submit=1&';
5883                        $('input, select, textarea', instance).each(function() {
5884                            var field_value = $(this).val();
5885                            if ($(this).attr('type') == 'radio') {
5886                            	if ($(this).is(':checked')) {
5887                                	data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
5888                            	}
5889                            } else {
5890                                if (field_value != $(this).attr('default-value')) {
5891                                    if ($(this).attr('type') == 'checkbox') {
5892                                        if ($(this).attr('name') == 'terms') {
5893                                            var field_value = $(this).is(':checked') ? '1' : '';
5894                                        } else {
5895                                            var field_value = $(this).is(':checked') ? 'Yes' : 'No';
5896                                        }
5897                                    }
5898    
5899                                    if ($(this).attr('name') == 'message') {
5900                                        data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />').replace('%', 'percent') + '&';
5901                                    } else {
5902                                        data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
5903                                    }
5904                                }
5905                            }
5906                        });
5907
5908                        data = data + 'originating_page=' + encodeURIComponent(window.location.pathname + window.location.search) + '&';
5909
5910                        $.ajax({
5911                            url: "/enquiry/",
5912                            data: data,
5913                            cache: false,
5914                            method: 'POST',
5915                            dataType: 'json',
5916                            success: function(data) {
5917                                setTimeout(function() {
5918                    
5918                $('#gallery_contact_widget .button').removeClass('loading');
5919                                }, 1600);
5920                                $('#gallery_contact_widget')
5921                                    .delay(400)
5922                                    .queue(function() {
5923                                        if (data['success'] == 1) {
5924                                            
5925                                            window.archimedes.archimedes_core.analytics.track_campaigns.save_form_data($('#gallery_contact_widget'));
5926
5927                                            if ($('.contact_form_captcha_enabled').length > 0) {
5928                                                if (typeof grecaptcha != 'undefined') {
5929                                                    grecaptcha.reset();
5930                                                }
5931                                            }
5932
5933                                            $('#gallery_contact_widget').addClass('success');
5934                                            if (window.ga) {
5935                                                // Track in Analytics
5936                                                analytics_params = {
5937                                                  'hitType': 'event',
5938                                                  'eventCategory': 'Gallery contact form submit success',
5939                                                  'eventAction': window.location.pathname,
5940                                                  'eventLabel': $(document).attr('title')
5941                                                };
5942                                                ga('send', analytics_params);
5943                                                ga('tracker2.send', analytics_params);
5944                                            }
5945
5946                                            window.site.overlays.gallery_contact.close();
5947
5948                                            $('#gallery_contact_widget')
5949                                                .delay(200)
5950                                                .queue(function() {
5951                                                    h.alert('<h2>Thank you</h2><div>Your inquiry has been sent and we will be in contact shortly.</div>
5951', {buttons: false});
5952                                                    $(this).dequeue();
5953                                                })
5954                                            ;
5955
5956                                        } else {
5957                                            var error_message = '';
5958                                            if (data['error_message'] && typeof data['error_message'] != 'undefined') {
5959                                                var error_message = data['error_message'];
5960                                            }
5961                                            var field_errors = [];
5962                                            if (data['field_errors'] && typeof data['field_errors'] != 'undefined') {
5963                                                var field_errors = data['field_errors'];
5964                                            }
5965                                            $.each(field_errors, function(i, v) {
5966                                                $('#gallery_contact_widget').find('[name="' + v + '"]').closest('.form_row').addClass('error');
5967                                            });
5968                                            if (error_message) {
5969                                                h.alert(error_message, {buttons: fal
5969se});
5970                                            }
5971
5972                                            if ($('.contact_form_captcha_enabled').length > 0) {
5973                                                if (typeof grecaptcha != 'undefined') {
5974                                                    grecaptcha.reset();
5975                                                }
5976                                            }
5977
5978                                            if (window.ga) {
5979                                                // Track in Analytics
5980                                                analytics_params = {
5981                                                  'hitType': 'event',
5982                                                  'eventCategory': 'Gallery contact form submit error',
5983                                                  'eventAction': window.location.pathname,
5984                                                  'eventLabel': $(document).attr('title')
5985                                                };
5986                                                ga('send', analytics_params);
5987                                                ga('tracker2.send', analytics_params);
5988                                            }
5989
5990                                        }
5991                                        $(this).dequeue();
5992                                    })
5993                               ;
5994                            }
5995                        });
5996                    }
5997                },
5998
5999                after_submit: function() {
6000
6001                }
6002                
6003            },
6004
6005            content: {
6006
6007                init: function() {
6008                    window.site.overlays.content.setup();
6009                },
6010
6011                setup: function() {
6012
6013                    $('.content_overlay_link_example, .content-overlay .overlay-close-button').unbind().click(function() {
6014                        var clicked_element = $(this);
6015
6016                        if ($('.content-overlay').hasClass('active')) {
6017                            window.site.overlays.content.close();
6018                        } else {
6019                            window.site.overlays.content.open(clicked_element);
6020                        }
6021                        return false;
6022                    });
6023                },
6024
6025                close: function() {
6026                    window.setTimeout(function() {
6027                        $('body').removeClass('active-init');
6028                    }, 600);
6029                    $('.content-overlay .overlay-bg').removeClass('open');
6030                    $('.content-overlay').removeClass('active');
6031                    $('body, html').removeClass('overlay-open content-overlay-open');
6032                    $(".content-overlay-wrapper.visible").removeClass('visible');
6033
6034                    $('.content-overlay .overlay-container-inner').scrollTop(0);
6035
6036                    $('.list-preview-track-list .item').removeClass('active');
6037                    $('.list-preview-track-list').removeClass('item-preview-active');
6038                },
6039
6040                open: function(clicked_element, received_html) {
6041                    var received_html = (received_html && typeof received_html != 'undefined' ? received_html : '');
6042
6043                    $('#content-overlay-content').html(received_html);
6044                    $('body').addClass('active-init');
6045                    $(clicked_element).closest('.item').addClass('active');
6046                    $(clicked_element).closest('.list-preview-track-list').addClass('item-preview-active');
6047
6048                    setTimeout(function() {
6049                        $('#container_outer').removeClass('scrolling-down scrolling-up');
6050                        $('.content-overlay .overlay-bg').addClass('open');
6051                        $('.content-overlay').addClass('active');
6052                        $('body, html').addClass('overlay-open content-overlay-open');
6053                        
6054                        setTimeout(function() {
6055                            $('.content-overlay-wrapper:not(.visible)').each(function(i){
6056                                $(this).addClass('visible')
6057                            });
6058                        }, 700, clicked_element);
6059                    }, 50, clicked_element);
6060
6061                    if (window.ga) {
6062                        // Track the click in Analytics
6063                        analytics_params = {
6064                          'hitType': 'event',
6065                          'eventCategory': 'Whats on event preview opened',
6066                          'eventAction': window.location.pathname,
6067                          'eventLabel': $(document).attr('title')
6068                        };
6069                        ga('send', analytics_params);
6070                        ga('tracker2.send', analytics_params);
6071                    }
6072                }
6073            },
6074
6075            navigation: function() {
6076                $('#menu, .nav-close-button').unbind().click(function() {
6077                	$('#container_outer').removeClass('scrolling-down scrolling-up');
6078                    $('body').addClass('active-init');
6079                    setTimeout(function() {
6080                        if (typeof nav_close_timeout1 != 'undefined') {
6081                            clearTimeout(nav_close_timeout1);
6082                        }
6083                        if ($('.nav-overlay').hasClass('active')) {
6084                            nav_close_timeout1 = setTimeout(function() {
6085                                $('body').removeClass('active-init');
6086                                $('.dropdown-nav button').removeClass('dropdown_active').attr("aria-expanded", "false");
6087                                $('.nav-overlay .dropdown_navigation_container').slideUp();
6088                            }, 600);
6089                            $('.nav-overlay .overlay-bg').removeClass('open');
6090                            $('.nav-overlay').removeClass('active');
6091                            $('body, html').removeClass('overlay-open nav-overlay-open');
6092
6093                            $(".nav-contact-module.visible, .nav-wrapper li.visible, #translations_nav.visible").removeClass('visible');
6094                            h.accessibility.on_popup_closing('#menu');
6095                        } else {
6096                            $('.nav-overlay .overlay-bg').addClass('open');
6097                            $('.nav-overlay').addClass('active');
6098                            $('body, html').addClass('overlay-open nav-overlay-open');
6099
6100                            setTimeout(function() {
6101                                $(".nav-contact-module:not(.visible)").each(function(i){
6102                                    var $item = $(this);
6103                                    $item.addClass('visible')
6104                                });
6105                                $(".nav-wrapper > ul > li:not(.visible), #translations_nav:not(.visible)").each(function(i){
6106                                    var $item = $(this);
6107                                    $item.addClass('visible')
6108                                });
6109                            }, 400);
6110
6111                            h.accessibility.on_popup_opening('.nav-overlay', '.nav-wrapper a:first', '.nav-close-button');
6112                        }
6113                    }, 50);
6114
6115                });
6116                
6117                $('.fire-pageload').unbind().click(function() {
6118
6119                    var this_link = $(this).attr('data-link');
6120                    
6121                    $('.nav-overlay').addClass('animate-out').removeClass('active');
6122                    
6123                    $(".nav-contact-module.visible").each(function(i){
6124                        var $item = $(this);
6125                        setTimeout(function() {
6126                            $item.removeClass('visible');
6127                        }, 300*i);
6128                    });
6129                    $(".nav-wrapper li.visible").each(function(i){
6130                        var $item = $(this);
6131                        setTimeout(function() {
6132                            $item.removeClass('visible');
6133                        }, 100*i);
6134                    });
6135
6136                    window.setTimeout(function() {
6137                        window.location.href = this_link;
6138                    }, 1500, this_link);
6139                });
6140                
6141
6142            },
6143            
6144            artworks: function() {
6145                        //history.pushState({'ajaxPageLoad': true}, null, '/artworks/');
6146                        //$('body').addClass('page-popup-clicked-close');
6147                        //window.history.back();
6148                $('.artworks-overlay-button, .artworks-overlay-close-button').unbind('click.artworks-overlay-click').bind('click.artworks-overlay-click', function(e) {
6149                    var clicked_element = $(this);
6150                	$('#container_outer').removeClass('scrolling-down scrolling-up');
6151                    $('body').addClass('active-init');
6152                    window.setTimeout(function() {
6153                        if ($('.artworks-overlay').hasClass('active')) {
6154                            $('.artworks-overlay').removeClass('show-content');
6155
6156                            $(".nav-contact-module.visible, .nav-wrapper li.visible").removeClass('visible');
6157                            
6158
6159                            setTimeout(function() {
6160	                            $('.artworks-overlay .overlay-bg').removeClass('open');
6161	                            $('.artworks-overlay').removeClass('active');
6162                            	$('body, html').removeClass('overlay-open artworks-overlay-open');
6163
6164	                            setTimeout(function() {
6165	                                $('body').removeClass('active-init');
6166                                    $('.artwork-nav-top-level').removeClass('active not-active');
6167                                    $('.artworks-overlay-content').removeClass('second-level-active');
6168	                            }, 600);
6169                            }, 200);
6170                            
6171		                    $('.artwork-nav-top-level .artwork-nav-hero').each(function() {
6172		                    	$(this).find('.image').filter(':eq(0)').addClass('active');
6173		                    });
6174                        } else {
6175                            var relative_id = clicked_element.attr('data-relative-id') && typeof clicked_element.attr('data-relative-id') != 'undefined' ? clicked_element.attr('data-relative-id') : false;
6176                            window.site.lazy_load.fire($('.artworks-overlay .image_lazy_load'));
6177                            $('.artworks-overlay .overlay-bg').addClass('open');
6178                            $('.artworks-overlay').addClass('active');
6179                            $('body, html').addClass('overlay-open artworks-overlay-open');
6180
6181                            setTimeout(function() {
6182                                $('.artworks-overlay').addClass('show-content');
6183                            }, 400);
6184                        
6185                            setTimeout(function() {
6186	                        	if ($('body, html').hasClass('nav-overlay-open')) {
6187		                            $('.nav-overlay .overlay-bg').removeClass('open');
6188		                            $('.nav-overlay').removeClass('active');
6189		                            $('body, html').removeClass('nav-overlay-open');
6190		                            $('.nav-contact-module.visible, .nav-wrapper li.visible').removeClass('visible');
6191	                        	}
6192                            }, 800);
6193
6194                            if (relative_id) {
6195                                $('.artworks-overlay .artwork-nav-top-level[data-id="' + relative_id + '"]').trigger('click');
6196                            }
6197                        }
6198                    }, 50, clicked_element);
6199                    return false;
6200                });
6201
6202                $('.artwork-navigation a').unbind().click(function() {
6203                	var selected_element = $(this).closest('li');
6204                	var this_href = $(this).attr('href');
6205                	//$('.artworks-overlay-close-button').trigger('click');
6206                	$(this).closest('li').addClass('selected');
6207                	//$(this).closest('ul').find('li').not('.selected').each(function() {
6208                	//	$(this).slideUp(800);
6209                	//});
6210
6211                	$('.artwork-navigation').addClass('nav-selected');
6212                	//setTimeout(function() {
6213                	//	$(selected_element).addClass('selected2')
6214                	//}, 600, selected_element);
6215                	//setTimeout(function() {
6216                		$.pageload.load(this_href, true, false);
6217                	//}, 1200, this_href);
6218                	return false;
6219                });
6220
6221                $('.artworks-overlay-content').each(function() {
6222                	$('.artwork-nav-top-level').unbind().bind('click.artist-nav-click', function() {
6223                		var this_instance = $(this);
6224                		if (!this_instance.hasClass('active') && !$('.artworks-overlay-content').hasClass('nav-transitioning')) {
6225	                		$(this).closest('.artworks-overlay-content').find('.artwork-nav-top-level').not(this_instance).removeClass('active').addClass('not-active');
6226	                		$(this).addClass('active').removeClass('not-active');
6227	                		$(this).closest('.artworks-overlay-content').addClass('second-level-active');
6228
6229		                    $(this).closest('.artworks-overlay-content').find('.artwork-nav-top-level').not(this_instance).find('.artwork-nav-wrapper li.visible').each(function(i){
6230		                        var $item = $(this);
6231		                        setTimeout(function() {
6232		                            $item.removeClass('visible');
6233		                        }, 100*i);
6234		                    });
6235
6236		                    $(this).closest('.artwork-nav-top-level').find('.artwork-nav-wrapper li').each(function(i){
6237		                        var $item = $(this);
6238		                        setTimeout(function() {
6239		                            $item.addClass('visible');
6240		                        }, 100*i);
6241		                    });
6242
6243                            if (false) {
6244                    			$('.artworks-overlay-content').addClass('nav-transitioning');
6245    							$('.artworks-overlay-content').removeClass('nav-not-transitioning');
6246                    			setTimeout(function() {
6247    								$('.artworks-overlay-content').removeClass('nav-transitioning');
6248    								$('.artworks-overlay-content').addClass('nav-not-transitioning');
6249                    			}, 600);
6250                            }
6251
6252                            var this_top_level_category_offset_top = $(this).offset().top - $('.artwork-navigation').offset().top;
6253                            if (this_top_level_category_offset_top > 0) {
6254                                $('.overlay-container-inner').animate({'scrollTop': this_top_level_category_offset_top}, 600, 'easeInOutExpo');
6255                            }
6256                		}
6257                	});
6258                	$('.artwork-nav-top-level').hover(
6259                		function() {
6260                			$('.artworks-overlay-content').addClass('top-level-hover');
6261                			$(this).parent().find('.artwork-nav-top-level').not(this).removeClass('last-hover');
6262                			//$(this).addClass('last-hover');
6263                		},
6264                		function() {
6265                			$('.artworks-overlay-content').removeClass('top-level-hover');
6266                		}
6267            		);
6268
6269                    if (!window.site.device.handheld() && window.site.device.breakpoint() > 2) {
6270                    	$('.artwork-nav-top-level .artwork-nav-wrapper ul li').hover(
6271                    		function() {
6272                    			if (!$('.artwork-navigation').hasClass('nav-selected')) {
6273    	                			var hero_instance = $(this).closest('.artwork-nav-top-level').find('.artwork-nav-hero');
6274    	                			var this_index = $(this).index() + 1;
6275    	                			hero_instance.find('.artwork-image').removeClass('active');
6276    	                			hero_instance.find('.artwork-image').filter(':eq(' + this_index + ')').addClass('active');
6277    	                			$(this).closest('.artwork-nav-top-level').addClass('subnav-hover');
6278    	                		}
6279                    		},
6280                    		function() {
6281                    			if (!$('.artwork-navigation').hasClass('nav-selected')) {
6282    	                			var hero_instance = $(this).closest('.artwork-nav-top-level').find('.artwork-nav-hero');
6283    	                			hero_instance.find('.artwork-image').removeClass('active');
6284    	                			hero_instance.find('.artwork-image').filter(':eq(0)').addClass('active');
6285    	                			$(this).closest('.artwork-nav-top-level').removeClass('subnav-hover');
6286    	                		}
6287                    		}
6288                		);
6289                    }
6290
6291            		// Reset everything in case we have loaded from a previous page and some of the settings remain from before
6292                    $('.artwork-nav-top-level .artwork-nav-hero').each(function() {
6293                    	$(this).find('.artwork-image').filter(':eq(0)').addClass('active');
6294                    });
6295                    $('.artwork-navigation').removeClass('nav-selected');
6296                    $('.artwork-nav-wrapper ul li').removeClass('selected').attr('style', '');
6297                });
6298
6299                // Artwork menu permalink page
6300                if (window.location.pathname.indexOf('/artworks/section/') == 0) {
6301                    var relative_id = window.location.pathname.replace('/artworks/section/', '').replace('/', '');
6302                    if (relative_id) {
6303                        $('.artwork-nav-top-level[data-id="' + relative_id + '"]').trigger('click');
6304                    }
6305                }
6306                if (window.location.pathname == '/artworks/' || window.location.pathname.indexOf('/artworks/section/') == 0) {
6307                    window.site.lazy_load.fire($('.artwork-navigation .image_lazy_load'));
6308                }
6309
6310                ///////////////////////////////////////////
6311                ///////////////////////////////////////////
6312                // OPEN AUTOMATICALLY FOR DEVELOPMENT
6313                //$('.artworks-overlay-button').trigger('click');
6314                ///////////////////////////////////////////
6315                ///////////////////////////////////////////
6316                /*
6317                $('.fire-pageload').unbind().click(function() {
6318
6319                    var this_link = $(this).attr('data-link');
6320                    
6321                    $('.nav-overlay').addClass('animate-out').removeClass('active');
6322                    
6323                    $(".nav-contact-module.visible").each(function(i){
6324                        var $item = $(this);
6325                        setTimeout(function() {
6326                            $item.removeClass('visible');
6327                        }, 300*i);
6328                    });
6329                    $(".nav-wrapper li.visible").each(function(i){
6330                        var $item = $(this);
6331                        setTimeout(function() {
6332                            $item.removeClass('visible');
6333                        }, 100*i);
6334                    });
6335
6336                    window.setTimeout(function() {
6337                        window.location.href = this_link;
6338                    }, 1500, this_link);
6339                });
6340                */
6341            }
6342        },
6343
6344        artlogic_inview: {
6345
6346        	default_elements: '.inview_element, .hide-off-screen, .scroll_section_top, .faux_footer, .records_slider_panel, .list-ajax-load-more, .related_content_slideshow_panel',
6347
6348        	options: {
6349				rootMargin: '0px', //Viewport margins 10px 20px 30px 40px
6350				threshold: [0, 0.1, 0.3, 0.5, 0.7, 1]  //how much needs to be showing. Fires IN and Out by that amount
6351            },
6352
6353            init: function(context) {
6354                
6355                $('#container').removeClass('hero-section-visible');
6356                $('#container').addClass('hero-section-not-visible');
6357                $('#container_outer').removeClass('page-enquiry-visible');
6358                $('#container_outer').addClass('page-enquiry-not-visible');
6359
6360                if (window.site.device.handheld_not_ios()) {
6361                	// Compatability mode if intersection observer does not work
6362                	// $.browser.name == 'mozilla'
6363                	$(window.site.artlogic_inview.default_elements).each(function() {
6364	                    var $entry = $(this);
6365
6366                    	if ($entry.hasClass('inview_element')) {
6367	                    	$entry.addClass('visible');
6368                            var video_element = $entry.find('video');
6369                            var lazy_load_context = $('.image_lazy_load');
6370                            var lazy_load_element = $entry.find('.image_lazy_load').not('.loaded, .loading');
6371                            var position_of_lazy_load_element = lazy_load_context.index($entry.find('.image_lazy_load'));
6372
6373                            var lazy_load_element_to_fire = lazy_load_element;
6374                            if (position_of_lazy_load_element > 0) {
6375                            	var adjacent_lazy_load_elements = lazy_load_context.slice(position_of_lazy_load_element, position_of_lazy_load_element + 4);
6376                            	lazy_load_element_to_fire = adjacent_lazy_load_elements;
6377                            }
6378
6379                            if (lazy_load_element_to_fire.length) {
6380                            	window.site.lazy_load.fire(lazy_load_element_to_fire);
6381                            }
6382
6383                            if (video_element.length && window.site.device.video_inline()) {
6384                                video_element.get(0).play();
6385                            }
6386                        }
6387                	});
6388                    $(window).bind('scroll', window.site.throttle(50, function() {
6389                        $(window.site.artlogic_inview.default_elements).each(function() {
6390                            var $entry = $(this);
6391                            if ($entry.hasClass('faux_footer')) {
6392                                 if ($(window).scrollTop() + $(window).height() > $entry.offset().top) {
6393                                    $('#container').addClass('footer-visible');
6394                                 } else {
6395                                    $('#container').removeClass('footer-visible');
6396                                 }
6397                            }
6398                            if ($entry.hasClass('scroll_section_top') && $entry.hasClass('hide-off-screen')) {
6399                                if ($(window).scrollTop() > $(window).height()) {
6400                                    if (!$entry.hasClass('hidden-off-screen')) {
6401                                        $entry.addClass('hidden-off-screen')
6402                                    }
6403                                    if (!$('#container').hasClass('hero-section-not-visible')) {
6404                                        $('#container').addClass('hero-section-not-visible');
6405                                        $('#main_slideshow, .main_slideshow').cycle('pause');
6406                                        $('#container').removeClass('hero-section-visible');
6407                                    }
6408                                } else {
6409                                    if ($entry.hasClass('hidden-off-screen')) {
6410                                        $entry.removeClass('hidden-off-screen ')
6411                                    }
6412                                    if (!$('#container').hasClass('hero-section-visible')) {
6413                                        $('#container').removeClass('hero-section-not-visible');
6414                                        //if ($('#main_slideshow, .main_slideshow').hasClass('cycle-paused-forced')) {
6415                                        //    $('#main_slideshow, .main_slideshow').cycle('resume');
6416                                        //}
6417                                        $('#container').addClass('hero-section-visible');
6418                                    }
6419                                }
6420                            }
6421                        });
6422                    }));
6423                } else {
6424
6425	                var default_context = window.site.artlogic_inview.default_elements;
6426	                var context = (context && typeof context != 'undefined' ? context : default_context);
6427
6428	                // SETUP THE OBSERVER
6429	                artlogic_observer = new IntersectionObserver(window.site.artlogic_inview.callback, window.site.artlogic_inview.options);
6430
6431	                /// SET TARGETS
6432	                var targets = document.querySelectorAll(context);
6433	                // Watch the targets
6434	                for (var i = targets.length - 1; i >= 0; i--) {
6435	                	// UNBIND OBSERVERS IF THEY ARE ALREADY RUNNING
6436	                	artlogic_observer.unobserve(targets[i]);
6437	                }
6438	                for (var i = targets.length - 1; i >= 0; i--) {
6439	                	// OBSERVE ELEMENTS
6440	                    artlogic_observer.observe(targets[i]);
6441	                }
6442	                $('.inview_element').addClass('animate-from-bottom');
6443                }
6444            },
6445
6446            destroy: function() {
6447            	if (typeof artlogic_observer == 'undefined') {
6448            		artlogic_observer = false;
6449            	}
6450            	if (artlogic_observer && typeof artlogic_observer != 'undefined') {
6451	            	var elements = window.site.artlogic_inview.default_elements;
6452	                var targets = document.querySelectorAll(elements);
6453	                for (var i = targets.length - 1; i >= 0; i--) {
6454	                	artlogic_observer.unobserve(targets[i]);
6455	                }
6456            	}
6457            },
6458            
6459            callback: function(entries, observer) {
6460                
6461                entries.forEach(function(entry) {
6462                    
6463                    var $entry = $(entry.target);
6464                    var ratio_onscreen = entry.intersectionRatio;
6465                    
6466                    if (false && $('body').hasClass('section-exhibitions')) {
6467                        if ($entry.hasClass('list-ajax-load-more')) {
6468                            if (entry.isIntersecting && !$entry.hasClass('triggered')) {
6469                                $entry.addClass('triggered');
6470                                $entry.find('button').trigger('click');
6471                            }
6472                        }
6473                        if ($entry.hasClass('link_more')) {
6474                            if (entry.isIntersecting && !$entry.hasClass('triggered')) {
6475                                $entry.addClass('triggered');
6476                                $entry.find('button').trigger('click');
6477                            }
6478                        }
6479                    }
6480                    
6481                    /////GALLERY SECTIONS
6482                    if ($entry.hasClass('inview_element')) {
6483                        var video_element_embed = $entry.find('.video_embed_wrapper');
6484                        var video_element = $entry.find('video');
6485                        var intro_content = $entry.hasClass('inview_element_intro');
6486                        $entry.attr('data-ratio_onscreen', ratio_onscreen);
6487                        if (!entry.isIntersecting) {
6488                            // SETTING ABOVE AND BELOW CLASSES
6489                            if (entry.boundingClientRect.top >= 0){
6490                                //Scrolling down
6491                                $entry.addClass('animate-from-bottom').removeClass('animate-from-top');
6492                            } else {
6493                                //Scrolling up
6494                                $entry.addClass('animate-from-top').removeClass('animate-from-bottom');
6495                            }
6496                            if (!$entry.hasClass('inview_element inview_once')) {
6497                                $entry.removeClass('visible');
6498                            }
6499                            if (video_element.length) {
6500                                video_element.get(0).pause();
6501                            }
6502                            if (video_element_embed.length) {
6503                                if (video_element_embed.hasClass('video_playing')) {
6504                                    video_element_embed.removeClass('video_playing');
6505                                    video_element_embed.find('.video_embed_pause').trigger('click');
6506                                }
6507                            }
6508                            if (intro_content) {
6509                            	//$entry.removeClass('inview_element_intro_timeout');
6510                            }
6511                            if ($entry.hasClass('page_enquiry_widget')) {
6512                            	if (!entry.boundingClientRect.top >= 0){
6513	                            	$('#container_outer').removeClass('page-enquiry-visible');
6514                                    $('#container_outer').addClass('page-enquiry-not-visible');
6515	                            }
6516                            }
6517                        } else {
6518                            $entry.addClass('visible');
6519                            var lazy_load_context = $('.image_lazy_load');
6520                            var lazy_load_element = $entry.find('.image_lazy_load').not('.loaded, .loading');
6521                            var position_of_lazy_load_element = lazy_load_context.
6521index($entry.find('.image_lazy_load'));
6522
6523                            var lazy_load_element_to_fire = lazy_load_element;
6524                            if (position_of_lazy_load_element > 0) {
6525                            	var adjacent_lazy_load_elements = lazy_load_context.slice(position_of_lazy_load_element, position_of_lazy_load_element + 3);
6526                            	lazy_load_element_to_fire = adjacent_lazy_load_elements;
6527                            }
6528
6529                            if (lazy_load_element_to_fire.length) {
6530                            	window.site.lazy_load.fire(lazy_load_element_to_fire);
6531                            }
6532
6533                            if (video_element.length && window.site.device.video_inline()) {
6534                           	    video_element.get(0).play();
6535                            }
6536                            
6537                            if (video_element_embed.length) {
6538                                if (!video_element_embed.hasClass('video_playing')) {
6539                                    video_element_embed.addClass('video_playing');
6540                                    video_element_embed.find('.video_embed_play').trigger('click');
6541                                }
6542                            }
6543
6544                            if (intro_content) {
6545                            	window.setTimeout(function() {
6546                            		$entry.addClass('inview_element_intro_timeout');
6547                            	}, 2000, $entry);
6548                            }
6549                            if ($entry.hasClass('page_enquiry_widget')) {
6550                            	$('#container_outer').addClass('page-enquiry-visible');
6551                                $('#container_outer').removeClass('page-enquiry-not-visible');
6552                            }
6553                        }
6554                    }
6555
6556                    if ($entry.hasClass('related_content_slideshow_panel')) {
6557                        if (entry.isIntersecting) {
6558                        	$('body').addClass('related_content_slideshow_panel-visible');
6559                        	if ( ratio_onscreen >= 0.5) {
6560                        		$('body').addClass('related_content_slideshow_panel-visible2');
6561                        	} else if (ratio_onscreen < 0.5) {
6562                                $('body').removeClass('related_content_slideshow_panel-visible2');
6563                            }
6564                        	
6565                    	} else {
6566                        	$('body').removeClass('related_content_slideshow_panel-visible related_content_slideshow_panel-visible2 related_content_slideshow_panel-visible3');
6567                    	}
6568                    }
6569
6570                    ///// Footer
6571                    if ($entry.hasClass('faux_footer')) {
6572                        if (entry.isIntersecting) {
6573                        	$('#container').addClass('footer-visible');
6574                        	if ( ratio_onscreen > 0.5) {
6575                        		$('#container').addClass('footer-visible2');
6576                        	}
6577                        	if ( ratio_onscreen > 0.75) {
6578                        		$('#container').addClass('footer-visible3');
6579                        	}
6580                    	} else {
6581                        	$('#container').removeClass('footer-visible footer-visible2 footer-visible3');
6582                    	}
6583                    }
6584                    
6585                    ///// DEACTIVATE EXPENSIVE STUFF WHEN OUT OF SITE
6586                    if ($entry.hasClass('hide-off-screen')) {
6587                        if (entry.isIntersecting) {
6588                            $entry.removeClass('hidden-off-screen');
6589                        } else {
6590                            $entry.addClass('hidden-off-screen');
6591                        }
6592                    }
6593
6594                    if ($entry.hasClass('scroll_section_top')) {
6595                        // entry.isIntersecting would sometimes wrongly return false so we also check for page-top-proximity class
6596                        if (entry.isIntersecting || $('#container_outer').hasClass('page-top-proximity')) {
6597                            $('#container').removeClass('hero-section-not-visible');
6598                            $('#container').addClass('hero-section-visible');
6599                        } else {
6600                            $('#container').addClass('hero-section-not-visible');
6601                            $('#container').removeClass('hero-section-visible');
6602                        }
6603                    }
6604                });
6605            }
6606        },
6607
6608        lazy_load: {
6609
6610        	init: function() {
6611        		window.site.lazy_load.setup();
6612        		// Fire lazy load on the first few elements
6613        		window.site.lazy_load.fire($('.image_lazy_load:not(.deferred_image_lazy_load)').slice(0,3));
6614        	},
6615
6616        	setup: function() {
6617                $('.image_lazy_load:not(.deferred_image_lazy_load)').each(function() {
6618                    // Only process lazy load images if they do not already have a loading class
6619                    if ($(this).find('img').length && !$(this).hasClass('loading') && !$(this).hasClass('initialized')) {
6620                    	if (false) {
6621                    		// Development functionality to show an initial low resolution image before the high-res is lazy-loaded
6622	                    	var image_src_init = $(this).find('img').attr('data-src-init');
6623	                    	if (image_src_init && typeof image_src_init != 'undefined') {
6624	                    		$(this).append('<img class="init_img" src="' + image_src_init + '" />');
6625	                    	}
6626                    	} else {
6627                    		$(this).append('<span class="loader"><svg viewBox="25 25 50 50" focusable="false"><circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="3" stroke-miterlimit="10"/></svg></span>');
6628                    	}
6629                    }
6630                    $(this).addClass('initialized');
6631                });
6632        	},
6633
6634        	fire: function(element) {
6635        	    
6636                $(element).each(function() {
6637                    
6638                    
6639                    // console.log('fire each');
6640                    
6641                	if ((!$(this).hasClass('loaded') && !$(this).hasClass('loading')) && $(this).hasClass('initialized')) {
6642                        var physical_image_width = $(this).width();
6643
6644                        if (!this.offsetWidth) {
6645                            physical_image_width = screen.width / 2;
6646                        }
6647
6648	                	$(this).addClass('loading');
6649	                    $(this).find('img[data-src]').each(function() {
6650	                        
6651                            var $img = $(this);
6652                            
6653                            var responsive_sizes = $img.attr('data-responsive-src');
6654
6655                            if (responsive_sizes) {
6656                                
6657                                // Work out the target size
6658                                var scale = (typeof window.devicePixelRatio !== 'undefined') ? window.devicePixelRatio : 1;
6659                                
6660                                var load_image_width = physical_image_width * scale;
6661                                
6662                                // Work out the available image sizes
6663                                var responsive_map = responsive_sizes;
6664                                var responsive_map_clean = JSON.parse(responsive_map.replace(/'/g, '"'));
6665                                var responsive_size_array = Object.keys(responsive_map_clean);
6666                                var process_closest = responsive_size_array.filter(function(item) {
6667                                    return item > load_image_width;
6668                                });
6669                                
6670                                var closest = (typeof process_closest !== 'undefined' && process_closest.length) ? process_closest[0] : responsive_size_array[responsive_size_array.length - 1];
6671                                
6672                                // If responsive option, use it! Else fall back to the data-src
6673                                var responsive_img_url = responsive_map_clean[closest.toString()].length ? responsive_map_clean[closest.toString()] : $img.attr('data-src');
6674                                var image_src = responsive_img_url;
6675
6676                                if (!dev_site) {
6677                                    $img.removeAttr('data-responsive-src');
6678                                }
6679    
6680	                        } else {
6681	                           var image_src = $img.attr('data-src');
6682	                        }
6683	             
6684	                        $(this).attr('src', image_src)
6685	                            .load(function(e) {
6686	                                if (!$(this).hasClass('force-loaded')) {
6687    	                                var $image_wrapper = $(this).closest('.image_lazy_load');
6688    	                                $image_wrapper.trigger('change.lazyload');
6689    	                                $(this).trigger('change.lazyload');
6690    	                                if ($image_wrapper.hasClass('loading')) {
6691    	                                    $(this)
6692    	                                        .delay(100)
6693    	                                        .queue(function() {
6694    	                                            $image_wrapper.removeClass('loading').addClass('loaded');
6695    	                                            
6696                                                    // window.site.layout.align_captions($image_wrapper.parent());
6697                                                    
6698    	                                            if ($(this).closest('.artwork_detail').length) {
6699                                                        $(window).trigger('resize');
6700    	                                            }
6701    	                                            $(this).dequeue();
6702    	                                        })
6703    	                                        .delay(500)
6704    	                                        .queue(function() {
6705    	                                            $image_wrapper.removeClass('loading-init');
6706    	                                            $image_wrapper.find('.loader').remove();
6707    	                                            $image_wrapper.find('img').css('min-height', '');
6708                	                                            
6709                                                    // window.site.layout.align_captions($image_wrapper.parent());
6710                                                    
6711    	                                            $(this).dequeue();
6712    	                                        })
6713    	                                    ;
6714    	                                }
6715    	                                
6716    	                                if ($image_wrapper.hasClass('artist_image_preview_image')) {
6717    	                                    window.site.artists.list_hover_load_adjacent($image_wrapper);
6718    	                                }
6719    	                                
6720                                        if ($(this).attr('data-src').indexOf('youtube.com') > -1 && String($(this).get(0).naturalHeight) == '90') {
6721                                            $(this).attr('src', $(this).attr('data-src').replace('maxresdefault.jpg', '0.jpg')).addClass('force-loaded');
6722                                        }
6723	                                }
6724	                            })
6725	                            .on('error', function(e) {
6726                                })
6727	                        ;
6728	                    });
6729                	}
6730                });
6731        	}
6732        },
6733
6734        artworks: {
6735
6736        	init: function() {
6737        		window.site.artworks.setup();
6738        	},
6739
6740        	setup: function() {
6741
6742        		window.site.artworks.resize();
6743                $(window).resize(function() {
6744                    window.site.artworks.resize();
6745                });
6746
6747        		$('.artwork_detail').each(function() {
6748        			$(this).addClass('visible');
6749	        		window.site.lazy_load.fire($('.artwork_hero_image_container'));
6750	        		window.site.lazy_load.fire($('.artwork_detail .image_lazy_load'));
6751                    
6752                    if ($('.artwork_detail_add_to_cart_wrapper .fallback_cart_wrapper', this).length) {
6753                        $('.tools .enquire_link', this).parent().remove();
6754                    }
6755        		});
6756
6757                $('.artwork_detail .image_container, .artwork_detail .image_container .image .image_inner').each(function() {
6758                    if (!window.site.device.handheld()) {
6759                        // Disabled on handheld as this stops users from swiping through the works.
6760                        var zoom_image = $(this).attr('data-zoom-url');
6761                        var zoom_type = $('.artwork_detail_type_standard').length || window.site.device.handheld() ? 'click' : 'mouseover';
6762                        if (zoom_image && typeof zoom_image != 'undefined') {
6763                            $(this).zoom({
6764                                url: zoom_image,
6765                                duration: 400,
6766                                on: zoom_type,
6767                                onZoomIn: function(){
6768                                    $('body').addClass('zoom-active');
6769                                },
6770                                onZoomOut: function(){
6771                                    $('body').removeClass('zoom-active');
6772                                }}
6773                            );
6774                        }
6775                    }
6776                });
6777        		
6778        		
6779                if ($('.roomview-photo-image').length) {
6780                    $('.roomview-photo-image').roomViewPhoto({
6781                        zoom_enabled: true,
6782                        zoom_scrollwheel_enabled: false
6783                    });
6784                } 
6785
6786        		$('.roomview-button-custom').unbind().click(function(e) {
6787        		    
6788                    e.preventDefault();
6789                    $('#popup_content').scrollTop(0);
6790                    // For accessibility - tracks which element to refocus on
6791                    try {
6792                        h.accessibility.global_variables.element_to_refocus_to = $(this).children('a');
6793                    } catch(error) {
6794                        console.error(error);
6795                    }
6796                    
6797                    var roomview_id = $(this).attr('data-roomview-id');
6798                    
6799                    if (roomview_id && typeof roomview_id != 'undefined') {
6800                        
6801                        var random_class;
6802                        $('.roomview-object.furniture-type-photo_bg').removeClass('view1 view2 view3');
6803                        
6804                         $('.roomview-object.furniture-type-photo_bg').removeClass('view1 view2 view3');
6805                        var view_classes = ["view1", "view2", "view3"];
6806                        var random_class = view_classes[~~(Math.random()*view_classes.length)];
6807                        
6808                        $('.roomview-object.furniture-type-photo_bg').addClass(random_class);
6809        
6810                        
6811                        if ($('.artwork_detail_main .image_container').find('.image_gallery_multiple').length) {
6812                            var roomview_instance = $('.artwork_detail_main .image_container .image:not(.cycle-sentinel) .roomview-image[data-roomview-id="' + roomview_id + '"]');
6813                            
6814                        } else {
6815                            var roomview_instance = $('.artwork_detail_main .image_container .roomview-image[data-roomview-id="' + roomview_id + '"]');
6816                        }
6817                        
6818                        var roomview_theme = 'standard';
6819                        
6820                        if (roomview_instance.attr('data-roomview-theme') && typeof roomview_instance.attr('data-roomview-theme') != 'undefined') {
6821                            roomview_theme = roomview_instance.attr('data-roomview-theme');
6822                        }
6823                        
6824                        $('.roomview-object.furniture-type-photo_bg').addClass('theme-'+roomview_theme)
6824;
6825                        roomview_instance.addClass('theme-'+roomview_theme);
6826                        
6827                        if ($('.artwork_detail_main .image_container').find('.image_gallery_multiple').length && !$('.image_gallery_multiple .item:not(.cycle-sentinel) .roomview-image[data-roomview-id="' + roomview_id + '"]').closest('.item').hasClass('cycle-slide-active')) {
6828                            // Change slide before view in a room starts
6829                            var this_slide_index = roomview_instance.closest('.cycle-slide').index($('.artwork_detail_main .image_container .image_gallery_multiple .cycle-slide').not('.cycle-sentinel'));
6830                            var timeout_length = 600;
6831                            if (roomview_instance.closest('.cycle-slide').hasClass('cycle-slide-active')) {
6832                                var timeout_length = 0;
6833                            }
6834                            if (this_slide_index > -1) {
6835                                $('.image_gallery_multiple').cycle(this_slide_index);
6836                                setTimeout(function() {
6837                                    roomview_instance.roomView('open');
6838                                }, timeout_length, roomview_instance);
6839                            }
6840                        } else {
6841                            
6842                            roomview_instance.roomView('open');
6843                        }
6844                    }
6845                });
6846                
6847
6848                if (false && $('body').hasClass('site-version-development-mode')) {
6849            		$('.artwork_detail .image').unbind('click.zoom-activate').bind('click.zoom-activate', function() {
6850                        if (window.site.device.breakpoint() >= 3) {
6851                            if (!$('body').hasClass('user-distraction-free')) {
6852                                $('body').addClass('user-distraction-free');
6853                            } else if (!$('body').hasClass('zoom-active') && $(this).hasClass('super_zoom_enabled')) {
6854                                $(this).closest('.artwork_detail').addClass('zoom-active');
6855                                $('body').addClass('zoom-active');
6856                            } else {
6857                                $(this).closest('.artwork_detail').removeClass('zoom-active');
6858                                setTimeout(function() {
6859                                    $('body').removeClass('zoom-active user-distraction-free');
6860                                }, 400);
6861                            }
6862                        }
6863            		});
6864                }
6865
6866                $('.image_gallery_multiple')
6867                    .each(function() {
6868                        
6869                        $slideshow = $(this);
6870                        var $slideshow_pager = $slideshow.closest('.image_container').find('.slideshow_pager');
6871                        
6872                        var paused = true ? $(this).hasClass('image_gallery_multiple_paused') : false;
6873                        
6874                        $(this)
6875                            .cycle({
6876                                fx:       'fade',
6877                                speed:    600,
6878                                timeout:  3500,
6879                                paused:    paused,
6880                                slides: '>',
6881                                autoHeight: 'container',
6882                                swipe: true
6883                            })
6884                            .on('cycle-before', function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
6885                                var hero_slide = $(incomingSlideEl).hasClass('image_hero_placeholder');
6886                                if (hero_slide) {
6887                                    $('.artwork_hero_image_container').addClass('active');
6888                                } else {
6889                                    $('.artwork_hero_image_container').removeClass('active');
6890                                }
6891                                
6892                                // Update active state of pagination controls
6893                                var new_slide_index = $(incomingSlideEl).index()
6894                                $('.slideshow-pager-item', $slideshow_pager).removeClass('pager-item-active');
6895                                $('.slideshow-pager-item:eq(' + new_slide_index + ')', $slideshow_pager).addClass('pager-item-active');
6896                                
6897                                // update caption
6898                                $('.slideshow_caption.truncated-image-caption', $slideshow.closest('.image_container')).removeClass('max_height_read_more').css({'max-height': '', '-webkit-line-clamp': '', 'line-clamp': '' });
6899                                if (!$('.slideshow_caption.truncated-image-caption', $slideshow.closest('.image_container')).hasClass('max_height_read_more')) {
6900                                    $('.slideshow_caption.truncated-image-caption', $slideshow.closest('.image_container')).parent().find('.max_height_read_more_button').remove();
6901                                }
6902                                
6903                                var slide_caption = $(incomingSlideEl).attr('data-sli
6903de-caption')
6904                                if (slide_caption && typeof slide_caption != 'undefined') {
6905                                    $('.slideshow_caption', $slideshow.closest('.image_container')).html(slide_caption).removeClass('empty_caption');
6906                                    $('.slideshow_caption.truncated-image-caption').each(function() {
6907                                        window.site.layout.max_height_read_more(this, 2);
6908                                        $('.image-caption-read-more-label', $(this).parent()).click(function() {
6909                                            $slideshow.cycle('pause');
6910                                        });
6911                                    });
6912                                } else {
6913                                    $('.slideshow_caption', $slideshow.closest('.image_container')).html('').addClass('empty_caption');
6914                                }
6915                            })
6916                        ;
6917                        
6918                        $('.slideshow_caption.truncated-image-caption').each(function() {
6919                            window.site.layout.max_height_read_more(this, 2);
6920                            $('.image-caption-read-more-label', $(this).parent()).click(function() {
6921                                $slideshow.cycle('pause');
6922                            });
6923                        });
6924                        
6925                        $(this).parent().find('.pagination_controls_previous').unbind().bind('click', function() {
6926                            $(this).closest('.image_gallery_multiple_container').find('.image_gallery_multiple').cycle('pause').cycle('prev');
6927                            return false;
6928                        });
6929                        $(this).parent().find('.pagination_controls_next').unbind().bind('click', function() {
6930                            $(this).closest('.image_gallery_multiple_container').find('.image_gallery_multiple').cycle('pause').cycle('next');
6931                            return false;
6932                        });
6933                        
6934                        // New version for introduction slideshows and teh slideshow in art fair detail pages
6935                        $('.previous_slide_button', $slideshow.parent()).unbind().bind('click', function() {
6936                            $slideshow.cycle('pause').cycle('prev');
6937                            return false;
6938                        });
6939                        $('.next_slide_button', $slideshow.parent()).unbind().bind('click', function() {
6940                            $slideshow.cycle('pause').cycle('next');
6941                            return false;
6942                        });
6943                        
6944                        if ($('.slideshow-pager-item', $slideshow_pager).length ) {
6945                            $('.slideshow-pager-item', $slideshow_pager).unbind().click(function() {
6946                                $slideshow.cycle('pause');
6947                                $slideshow.cycle(parseInt($(this).attr('data-index')));
6948                                return false;
6949                            });
6950                        }
6951                    })
6952                ;
6953
6954                if (false) {
6955                	// Add shipping info next to add to cart buttons
6956	                $('.artwork_detail .store_item').each(function() {
6957	                    if (!$('.delivery_info', this).length && !$('.price.sold_out', this).length) {
6958	                        $(this).append('<div class="delivery_info">Free UK shipping</div>')
6959	                    }
6960	                });
6961                }
6962
6963                $('.artwork_detail').each(function() {
6964                    $('.artwork_detail_type_editions').append('<div class="footer">' + $('#footer').html() + '</div>');
6965                    window.site.mailing_list_form.init();
6966                });
6967
6968                $('.artwork_hero_image_container').on('change.lazyload', function() {
6969                    var hero_image_path = $(this).find('.image_hero_full_image_duplicate').attr('src');
6970                    $('.artwork_hero_image_container .image').css({'background-image': "url('" + hero_image_path + "')"});
6971                });
6972
6973                $('.image_gallery_multiple .image:eq(0)')
6974                    .each(function() {
6975                        var hero_slide = $(this).hasClass('image_hero_placeholder');
6976                        if (hero_slide) {
6977                            $('.artwork_hero_image_container').addClass('active');
6978                        }
6979                    })
6980                ;
6981                
6982                
6983                $('.image_gallery_multiple_thumbnails a')
6984                	.unbind()
6985                    .click(function() {
6986                    	$('.artwork_detail').removeClass('zoom-active');
6987                        if ($('body').hasClass('page-popup-active')) {
6988                            var container_scroll_top = $('#popup_content').scrollTop();
6989                            var scroll_context = $('#popup_content');
6990                        } else {
6991                            var container_scroll_top = $(window).scrollTop();
6992                            var scroll_context = $('html,body');
6993                        }
6994                        if (container_scroll_top > $('.image_gallery_multiple').offset().top - scroll_context.offset().top + 20) {
6995                            scroll_context.animate({'scrollTop': 0}, 600, 'easeInOutExpo');
6996                        }
6997                        $('.image_gallery_multiple').cycle('pause');
6998                        $('.image_gallery_multiple').cycle(parseInt($(this).attr('data-index')));
6999                        return false;
7000                    })
7001                ;
7002
7003                if (window.site.device.handheld()) {
7004                    prevous_drag_percentage = 0;
7005                    var x;
7006
7007                    var freezeVp = function(e) {
7008                        e.preventDefault();
7009                    };
7010                    function stopBodyScrolling (bool) {
7011                        if (bool === true) {
7012                            document.body.addEventListener("touchmove", function(e) {
7013                                e.preventDefault();
7014                            }, {passive: false});
7015                        } else {
7016                            document.body.removeEventListener("touchmove", function(e) {
7017                                e.preventDefault();
7018                            }, {passive: false});
7019                        }
7020                    }
7021
7022                    
7023                    if (false) {
7024                        
7025                        // Swipe artwork functionality - disabled
7026                        
7027                        $('.artwork_detail')
7028                            .on('touchstart', function(e) {
7029                                if (!$(e.target).parents('.image_gallery_multiple_thumbnails_container').length) {
7030    
7031                                    x = e.originalEvent.targetTouches[0].pageX // anchor point
7032                                }
7033                            })
7034                            .on('touchmove', function(e) {
7035                                if (!$(e.target).parents('.image_gallery_multiple_thumbnails_container').length) {
7036    
7037                                    $('.artwork_detail').addClass('dragging');
7038                                    var change = e.originalEvent.targetTouches[0].pageX - x;
7039                                    var percentage = 100 * change / window.innerWidth;
7040                                    var drag_element = $('.artwork_detail .draginner');
7041                                    if (change < -10 || change > 10) {
7042                                        var condition_context = $('.artwork_detail').closest('#popup_content').length ? '#popup_content' : '#container_outer';
7043                                        var condition = !$(condition_context).hasClass('scrolling');
7044                                        if (condition) {
7045                                            // not yet working ios: stopBodyScrolling(true);
7046                                            $('body').addClass('content-swipe');
7047                                            drag_element.css({'transform': 'translate3d(' + percentage + '%, 0, 0)'});
7048                                            $('.artwork_detail .draginner').attr('data-left', percentage);
7049                                            prevous_drag_percentage = percentage;
7050                                        } else {
7051        
7052                                        }
7053                                    }
7054                                }
7055                            })
7056                            .on('touchend', function(e) {
7057                                if (!$(e.target).parents('.image_gallery_multiple_thumbnails_container').length) {
7058    
7059                                    // not yet working ios: stopBodyScrolling(false);
7060                                    $('.artwork_detail').removeClass('dragging');
7061                                    var percentage = $('.artwork_detail .draginner').attr('data-left');
7062                                    var drag_element = $('.artwork_detail .draginner');
7063                                    $('.artwork_detail').removeClass('dragging');
7064                                    window.setTimeout(function() {
7065                                        $('body').removeClass('content-swipe');
7066                                    }, 200);
7067                                    if (percentage > 30) {
7068                                        // Previous
7069                                        if ($('body').hasClass('page-popup-active')) {
7070                                            var link = $('#popup_box > .inner > .pagination_controls .previous').not('.disabled');
7071                                        } else {
7072                                            var link = $('.artwork_detail .pagination_controls .previous a').not('.disabled');
7073                                        }
7074                                        if (link.length) {
7075                                            drag_element.css({'transform': 'translate3d(201%, 0, 0)'});
7076                                            link.trigger('click');
7077                                        } else {
7078                                            prevous_drag_percentage = 0;
7079                                            drag_element.css({'transform': 'translate3d(0, 0, 0)'});
7080                                            $('.artwork_detail .draginner').attr('data-left', '0');
7081                                        }
7082                                    } else if (percentage < -30) {
7083                                        // Next
7084                                        if ($('body').hasClass('page-popup-active')) {
7085                                            var link = $('#popup_box > .inner > .pagination_controls .next').not('.disabled');
7086                                        } else {
7087                                            var link = $('.artwork_detail .pagination_controls .next a').not('.disabled');
7088                                        }
7089                                        if (link.length) {
7090                                            drag_element.css({'transform': 'translate3d(-201%, 0, 0)'});
7091                                            link.trigger('click');
7092                                        } else {
7093                                            prevous_drag_percentage = 0;
7094                                            drag_element.css({'transform': 'translate3d(0, 0, 0)'});
7095                                            $('.artwork_detail .draginner').attr('data-left', '0');
7096                                        }
7097                                    } else {
7098                                        prevous_drag_percentage = 0;
7099                                        drag_element.css({'transform': 'translate3d(0, 0, 0)'});
7100                                        $('.artwork_detail .draginner').attr('data-left', '0');
7101                                    }
7102                                }
7103                            })
7104                        ;
7105                    }
7106                }
7107                //CAPTION
7108                if($('.news_detail_popup').length){
7109                    if ($('.artwork_detail_main_image', this).length) {
7110                        var $artwork_detail_main_image = $('.artwork_detail_main_image', this);
7111                        var item_height = $artwork_detail_main_image.height();
7112        				var image_width = $artwork_detail_main_image.attr('data-width');
7113        				var image_height = $artwork_detail_main_image.attr('data-height');
7114        				var image_width_proportional = 0;
7115        				var image_height_proportional = 0;
7116        				if (image_width && image_height) {
7117        					var image_height_proportional = item_height / image_height;
7118        					var image_width_proportional = image_width * image_height_proportional;
7119        					if (image_height_proportional) {
7120        					    $('.artwork_detail.record_detail_simple .caption').css('max-width', image_width_proportional);
7121        					}
7122        				}
7123                    }
7124                }
7125                
7126            },
7127
7128            resize: function() {
7129                
7130
7131                $('.content_image_1_wrapper').each(function(){
7132                    var item_width = $(this).width();
7133                    var image_width = $(this).attr('data-width');
7134    				var image_height = $(this).attr('data-height');
7135    				var image_width_proportional = 0;
7136    				var image_height_proportional = 0;
7137    				var unrestricted_height = $(this).attr('data-unrestricted-height') && typeof $(this).attr('data-unrestricted-height') != 'undefined' ? true: false;
7138    				if (image_width && image_height) {
7139    					var image_width_proportional = item_width / image_width;
7140    					var image_height_proportional = image_height * image_width_proportional;
7141    					$(this).find('.image').find('img').css('max-height', '');
7142    					if (image_height_proportional > item_width && !unrestricted_height) {
7143    						// Set a maximum height based on a square proportion
7144    						var image_height_proportional = item_width;
7145    						$(this).find('.image').css('max-height', image_height_proportional);
7146    						$(this).find('.image').find('img').css('max-height', image_height_proportional);
7147    					}
7148    					if (image_height_proportional) {
7149    						$(this).find('.image').css('min-height', image_height_proportional);
7150    					}
7151    				}
7152                    });
7153                    
7154                if ($('.johnen-galerie-intro-container .image').length) {
7155                    var $johnen_galerie_main_image = $('.johnen-galerie-intro-container .image');
7156                    var item_width = $johnen_galerie_main_image.width();
7157    				var image_width = $johnen_galerie_main_image.attr('data-width');
7158    				var image_height = $johnen_galerie_main_image.attr('data-height');
7159    				var image_width_proportional = 0;
7160    				var image_height_proportional = 0;
7161    				if (image_width && image_height) {
7162    					var image_width_proportional = item_width / image_width;
7163    					var image_height_proportional = image_height * image_width_proportional;
7164    					if (image_height_proportional) {
7165    						$johnen_galerie_main_image.css('height', image_height_proportional);
7166    					}
7167    				}
7168                }
7169                
7170                $('.artwork_detail .artwork_detail_main').each(function() {
7171                    var min_height = $(window).width() * 0.62;
7172                    if (min_height < 850) {
7173                        var min_height = 850;
7174                    }
7175                    if (min_height > $(window).height()) {
7176                        var min_height = $(window).height();
7177                    }
7178                    if (min_height < 500) {
7179                        var min_height = 500;
7180                    }
7181                    //$(this).css('min-height', min_height);
7182                    //$('.artwork_hero_image_container').css('height', min_height);
7183
7184                    //$(this).find('.image_container').css('min-height', min_height);
7185
7186                    var pagination_controls_height = $(this).height();
7187                    if (pagination_controls_height > $(window).height()) {
7188                        var pagination_controls_height = $(window).height();
7189                    } else if (pagination_controls_height < min_height) {
7190                        var pagination_controls_height = min_height;
7191                    }
7192                    $('#popup_box .pagination_controls > div, .artwork_detail .pagination_controls > div').css('height', pagination_controls_height - 170);
7193                    
7194                    if ($(window).width() <= 900) {
7195                        $(".image_gallery_multiple_thumbnails_container.mobile-only .image_gallery_multiple_thumbnails a").removeClass('focustrap-ignore');
7196                    } else {
7197                        $(".image_gallery_multiple_thumbnails_container.mobile-only .image_gallery_multiple_thumbnails a").addClass('focustrap-ignore');
7198                    }
7199                    
7200                    if ($('.artwork_detail_main_image', this).length) {
7201                        var $artwork_detail_main_image = $('.artwork_detail_main_image', this);
7202                        var item_width = $artwork_detail_main_image.width();
7203        				var image_width = $artwork_detail_main_image.attr('data-width');
7204        				var image_height = $artwork_detail_main_image.attr('data-height');
7205        				var image_width_proportional = 0;
7206        				var image_height_proportional = 0;
7207        				if (image_width && image_height) {
7208        					var image_width_proportional = item_width / image_width;
7209        					var image_height_proportional = image_height * image_width_proportional;
7210        					if (image_height_proportional) {
7211        						$artwork_detail_main_image.css('height', image_height_proportional);
7212        					}
7213        				}
7214                    }
7215                    
7216                    //CAPTION
7217                    if($('.news_detail_popup').length){
7218                        if ($('.artwork_detail_main_image', this).length) {
7219                            var $artwork_detail_main_image = $('.artwork_detail_main_image', this);
7220                            var item_height = $artwork_detail_main_image.height();
7221            				var image_width = $artwork_detail_main_image.attr('data-width');
7222            				var image_height = $artwork_detail_main_image.attr('data-height');
7223            				var image_width_proportional = 0;
7224            				var image_height_proportional = 0;
7225            				if (image_width && image_height) {
7226            					var image_height_proportional = item_height / image_height;
7227            					var image_width_proportional = image_width * image_height_proportional;
7228            					if (image_height_proportional) {
7229            					    $('.artwork_detail.record_detail_simple .caption').css('max-width', image_width_proportional);
7230            					}
7231            				}
7232                        }
7233                    }
7234                    
7235                });
7236            }
7237
7238        },
7239
7240        social_media: {
7241            
7242            init: function() {
7243
7244                $('.share_links').each(function() {
7245                    $('.link a', this)
7246                        .unbind()
7247                        .blur(function() {
7248                            if (false) {
7249                                var element_context = $(this).closest('.share_links');
7250                                if (element_context.hasClass('active')) {
7251                                    element_context.addClass('closing').removeClass('animate active');
7252                                    element_context.delay(400).queue(function() {
7253                                        $(this).removeClass('closing');
7254                                        $(this).dequeue();
7255                                    });
7256                                }
7257                            }
7258                        })
7259                        .click(function() {
7260                            var instance = $(this);
7261                            if ($(this).closest('.share_links').hasClass('active') || $(this).closest('.share_links').hasClass('closing')) {
7262                                $(this).closest('.share_links').removeClass('active animate');
7263                            } else {
7264                                $(this).closest('.share_links').addClass('active');
7265                                share_links_timeout = setTimeout(function() {
7266                                    $(instance).closest('.share_links').addClass('animate');
7267                                }, 20, instance);
7268                                $(this).focus();
7269                            }
7270                            return false;
7271                        })
7272                    ;
7273                    $('.social_links_item a', this).unbind().click(function() {
7274                        if ($(this).attr('href').indexOf('http') == 0) {
7275                            var new_window = window.open($(this).attr('href'), 'social_media_share', 'width=600,height=500');
7276                            return false;
7277                        }
7278                    });
7279                });
7280
7281            }
7282
7283        },
7284
7285        enquiry: {
7286
7287            init: function() {
7288                window.site.enquiry.setup();
7289            },
7290
7291            setup: function() {
7292
7293                $('.form_row_types', '#contact_enquiry_form').each(function() {
7294                    $(this).find('li').click(function() {
7295                        $('#qcw_field_contact_variant').val($(this).attr('data-type'));
7296                        $(this).parent().find('li').removeClass('active');
7297                        $(this).addClass('active');
7298                    });
7299                    $(this).find('li:eq(0)').addClass('active');
7300                });
7301
7302                $('input, textarea', '#contact_enquiry_form')
7303                    .each(function() {
7304                        $(this).attr('default-value', $(this).parent().find('> label').text());
7305                        $(this).attr('placeholder', $(this).parent().find('> label').text());
7306                        if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
7307                            $(this).addClass('active');
7308                        } else {
7309                            $(this).val($(this).attr('default-value'));
7310                        }
7311                    })
7312                    .change(function() {
7313                        $(this).closest('.form_row').removeClass('error');
7314                    })
7315                    .focus(function() {
7316                        $(this).closest('.form_row').removeClass('error');
7317                        if ($(this).val() == $(this).attr('default-value')) {
7318                            $(this).addClass('active');
7319                            $(this).val('');
7320                        }
7321                    })
7322                    .blur(function() {
7323                        $(this).attr('default-value', $(this).parent().find('label').text());
7324                        if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
7325                            $(this).val($(this).attr('default-value'));
7326                            $(this).removeClass('active');
7327                        }
7328                    })
7329                ;
7330
7331                $('select', '#contact_enquiry_form')
7332                    .each(function() {
7333                        $(this).attr('default-value', $(this).val());
7334                    })
7335                    .change(function() {
7336                        if ($(this).val() != '') {
7337                            $(this).addClass('active');
7338                        } else {
7339                            $(this).removeClass('active');
7340                        }
7341                    })
7342                ;
7343
7344                $('#contact_enquiry_form .button a, #contact_enquiry_form button').click(function() {
7345                    window.site.enquiry.submit_form($(this).closest('.enquiry_form').find('form'));
7346                    return false;
7347                });
7348                
7349                $('#contact_enquiry_form form').submit(function(e) {
7350                    e.preventDefault(); 
7351                });
7352
7353                $('#contact_enquiry_form').each(function() {
7354                    if (!$(this).hasClass('initialized')) {
7355                        
7356                    }
7357                    $(this).addClass('initialized');
7358                });
7359
7360            },
7361
7362            clear_form: function() {
7363                $('#ecw_field_item').val('');
7364                $('#ecw_field_message', '#contact_enquiry_form').each(function() {
7365                    $(this).val($(this).attr('default-value')).removeClass('active');
7366                });
7367                $('#ecw_field_subject', '#contact_enquiry_form').each(function() {
7368                    $(this).val('').removeClass('active');
7369                });
7370                $('#contact_enquiry_form .notify_panel_items').html('');
7371            },
7372
7373            submit_form: function(instance) {
7374
7375                if (instance) {
7376                    $('.button', instance).addClass('loading');
7377                    $('.error_row', instance).removeClass('active');
7378                    data = 'submit=1&';
7379                    $('input, select, textarea', instance).each(function() {
7380                        var field_value = $(this).val();
7381                        if ($(this).attr('type') == 'radio') {
7382                        	if ($(this).is(':checked')) {
7383                            	data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
7384                        	}
7385                        } else {
7386                            if ($(this).attr('type') == 'checkbox') {
7387                                if ($(this).attr('name') == 'terms') {
7388                                    var field_value = $(this).is(':checked') ? '1' : '';
7389                                } else {
7390                                    var field_value = $(this).is(':checked') ? 'Yes' : 'No';
7391                                }
7392                            }
7393                            if ($(this).attr('name') == 'message') {
7394                                data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />').replace('%', 'percent') + '&';
7395                            } else {
7396                                data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
7397                            }
7398                        }
7399                    });
7400
7401                    data = data + 'originating_page=' + encodeURIComponent(window.location.pathname + window.location.search) + '&';
7402
7403                    $.ajax({
7404                        url: "/enquiry/",
7405                        data: data,
7406                        cache: false,
7407                        method: 'POST',
7408                        dataType: 'json',
7409                        success: function(data) {
7410                            $('#contact_enquiry_form .button').removeClass('loading');
7411                            $('#contact_enquiry_form')
7412                                .delay(400)
7413                                .queue(function() {
7414                                    if (data['success'] == 1) {
7415                                        
7416                                        window.archimedes.archimedes_core.analytics.track_campaigns.save_form_data($('#contact_enquiry_form'));
7417
7418                                        $('#contact_enquiry_form').addClass('success');
7419                                        h.alert('<h2>Thank you</h2><div>Your inquiry has been sent and we will be in contact shortly.</div>
7419', {buttons: false});
7420                                        if (window.ga) {
7421                                            // Track in Analytics
7422                                            analytics_params = {
7423                                              'hitType': 'event',
7424                                              'eventCategory': 'Enquiry form submit success',
7425                                              'eventAction': window.location.pathname,
7426                                              'eventLabel': $(document).attr('title')
7427                                            };
7428                                            ga('send', analytics_params);
7429                                            ga('tracker2.send', analytics_params);
7430                                        }
7431
7432                                        $('#contact_enquiry_form')
7433                                            .delay(2000)
7434                                            .queue(function() {
7435                                                $(this).dequeue();
7436                                            })
7437                                        ;
7438
7439                                    } else {
7440                                        var error_message = '';
7441                                        if (data['error_message'] && typeof data['error_message'] != 'undefined') {
7442                                            var error_message = data['error_message'];
7443                                        }
7444                                        var field_errors = [];
7445                                        if (data['field_errors'] && typeof data['field_errors'] != 'undefined') {
7446                                            var field_errors = data['field_errors'];
7447                                        }
7448                                        $.each(field_errors, function(i, v) {
7449                                            $('#contact_enquiry_form').find('[name="' + v + '"]').closest('.form_row').addClass('error');
7450                                        });
7451                                        if (error_message) {
7452                                            h.alert(error_message, {buttons: fal
7452se});
7453                                        }
7454
7455                                        if (window.ga) {
7456                                            // Track in Analytics
7457                                            analytics_params = {
7458                                              'hitType': 'event',
7459                                              'eventCategory': 'Enquiry form submit error',
7460                                              'eventAction': window.location.pathname,
7461                                              'eventLabel': $(document).attr('title')
7462                                            };
7463                                            ga('send', analytics_params);
7464                                            ga('tracker2.send', analytics_params);
7465                                        }
7466
7467                                    }
7468                                    $(this).dequeue();
7469                                })
7470                           ;
7471                        }
7472                    });
7473                }
7474
7475            },
7476
7477            after_submit: function() {
7478
7479            }
7480
7481        },
7482
7483        tracking: {
7484
7485            init: function() {
7486
7487
7488            }
7489
7490        },
7491
7492        quick_enquiry: {
7493
7494            // Quick mailing list signup form
7495
7496            init: function() {
7497                window.site.quick_enquiry.setup();
7498            },
7499
7500            setup: function() {
7501
7502                $('input:not(.signup_interests_user_select_input), textarea', '.page_enquiry_widget')
7503                    .each(function() {
7504                        if (!$(this).is('[type="checkbox"]')) {
7505                            $(this).attr('default-value', $(this).parent().find('> label').text());
7506                            $(this).attr('placeholder', $(this).parent().find('> label').text());
7507                            if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
7508                                $(this).addClass('active');
7509                            } else {
7510                                $(this).val($(this).attr('default-value'));
7511                            }
7512                        }
7513                    })
7514                    .change(function() {
7515                        $(this).closest('.form_row').removeClass('error');
7516                    })
7517                    .focus(function() {
7518                        $(this).closest('.form_row').removeClass('error');
7519                        if ($(this).val() == $(this).attr('default-value')) {
7520                            $(this).addClass('active');
7521                            $(this).val('');
7522                        }
7523                    })
7524                    .blur(function() {
7525                        $(this).attr('default-value', $(this).parent().find('label').text());
7526                        if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
7527                            $(this).val($(this).attr('default-value'));
7528                            $(this).removeClass('active');
7529                        }
7530                    })
7531	                .keypress(function(event) {
7532	                    if (event.which == 13) {
7533	                        window.site.quick_enquiry.submit_form($(this).closest('.page_enquiry_widget').find('form'));
7534	                        return false;
7535	                    }
7536	                })
7537                ;
7538                
7539                interests_to_submit = new Array();
7540                
7541                $('input.signup_interests_user_select_input', '.page_enquiry_widget')
7542                    .each(function() {
7543                        var $user_checkbox = $(this);
7544                        var $interests_input =  $user_checkbox.closest('.page_enquiry_widget').find("input[name='interests']");
7545                        var $user_checkbox_val = $user_checkbox.val();
7546                        //console.log('each');
7547                        
7548                        if ($user_checkbox.prop('checked')) {
7549                            interests_to_submit.push($user_checkbox_val);
7550                        } else {
7551                            interests_to_submit.splice( $.inArray($user_checkbox_val,interests_to_submit), 1);
7552                     
7553                        }
7554                        $interests_input.val(interests_to_submit);
7555                        
7556                    })
7557                    .change(function() {
7558                        var $user_checkbox = $(this);
7559                        var $interests_input =  $user_checkbox.closest('.page_enquiry_widget').find("input[name='interests']");
7560                        var $user_checkbox_val = $user_checkbox.val();
7561                        //console.log('change');
7562                        
7563                        if ($user_checkbox.prop('checked')) {
7564                            interests_to_submit.push($user_checkbox_val);
7565                        } else {
7566                            interests_to_submit.splice( $.inArray($user_checkbox_val,interests_to_submit), 1);
7567                        }
7568                        $interests_input.val(interests_to_submit);
7569                    })
7570                ;
7571
7572                if ($('.contact_form_captcha_enabled').length > 0) {
7573                    if (typeof google_captcha_onload != 'undefined') {
7574                        google_captcha_onload();
7575                    }
7576                }
7577                
7578                $('.page_enquiry_widget .page_enquiry_widget_submit button').unbind().click(function() {
7579                    window.site.quick_enquiry.submit_form($(this).closest('.page_enquiry_widget').find('form'));
7580                    return false;
7581                });
7582                
7583                $('.page_enquiry_widget .form_row_submit button').unbind().click(function() {
7584                    window.site.quick_enquiry.submit_form($(this).closest('.page_enquiry_widget').find('form'));
7585                    return false;
7586                });
7587
7588                $('.page_enquiry_widget').each(function() {
7589                    if (!$(this).hasClass('initialized')) {
7590                        
7591                    }
7592                    $(this).addClass('initialized');
7593                });
7594
7595            },
7596
7597            clear_form: function() {
7598                $('#pew_field_item').val('');
7599                $('#pew_field_email', '.page_enquiry_widget').each(function() {
7600                    $(this).val($(this).attr('default-value')).removeClass('active');
7601                });
7602            },
7603
7604            email_is_valid: function(email) {
7605                flag = false;
7606                if (email.indexOf('@') > -1 && email.split('@')[1].indexOf('.') > -1 && email.indexOf(' ') == -1) {
7607                    flag = true;
7608                }
7609                if (!flag) {
7610                     return false
7611                }
7612                return flag;
7613            },
7614
7615            submit_form: function(instance) {
7616                
7617                if (instance) {
7618                    // Process captcha
7619                    if ($(instance).hasClass('contact_form_captcha_enabled')) {
7620                        if (!$('body').hasClass('contact_form_captcha_challenge_passed')) {
7621                            var captcha_error = '<h2>Sorry</h2>An error occurred, please refresh this page and try again. If you continue to have problems please contact us for support.';
7622                            if (typeof grecaptcha != 'undefined') {
7623                                window.recaptcha_success_callback_instance = instance;
7624                                window.recaptcha_success_callback = function (instance) {
7625                                    window.site.quick_enquiry.submit_form(instance);
7626                                };
7627                                try {
7628                                    grecaptcha.execute();
7629                                } catch (error_message) {
7630                                    h.alert(captcha_error);
7631                                    $(instance).removeClass('submitting');
7632                                    $('.button', instance).removeClass('loading');
7633                                    $.ajax({
7634                                        url: "/api/process_js_error/",
7635                                        data: 'type=captcha&message=Captcha error on page ' + window.location.pathname + ' Error message: ' + error_message,
7636                                        cache: false
7637                                    });
7638                                }
7639                            } else {
7640                                h.alert(captcha_error);
7641                                $(instance).removeClass('submitting');
7642                                $('.button', instance).removeClass('loading');
7643                                var error_message = 'Unknown error - grecaptcha may be undefined'
7644                                $.ajax({
7645                                    url: "/api/process_js_error/",
7646                                    data: 'type=captcha&message=Captcha error on page ' + window.location.pathname + ' Error message: ' + error_message,
7647                                    cache: false
7648                                });
7649                            }
7650                            return;
7651                            
7652                        } else {
7653                            $('body').removeClass('contact_form_captcha_challenge_passed');
7654                        }
7655                    }
7656
7657                    $('.page_enquiry_widget_submit', instance).addClass('loading');
7658                    $('.form_row_submit .button', instance).addClass('loading');
7659                    $('.error_row', instance).removeClass('active');
7660                    data = 'submit=1&';
7661                    email_string = instance.find('input[name="email"]').val();
7662                    verify_email = window.site.quick_enquiry.email_is_valid(email_string);
7663                    
7664                    if (!verify_email) {
7665                        $('.page_enquiry_widget .page_enquiry_widget_submit').removeClass('loading');
7666                        $('.form_row_submit .button').removeClass('loading');
7667                        h.alert('<h2>Sorry</h2>
7667Please enter a valid email address.', {buttons: false});
7668                        return false;
7669                    }
7670
7671                    $('input, select, textarea', instance).each(function() {
7672                        var field_value = $(this).val();
7673                        if (field_value != $(this).attr('default-value')) {
7674                            if ($(this).hasClass('multiple_checkboxes')) {
7675                                var field_value = $('[name="' + $(this).attr('name') + '"]:checked').map(function() { 
7676                                   return this.value; 
7677                                }).get().join('<br>');
7678                            } else if ($(this).attr('type') == 'checkbox') {
7679                                if ($(this).attr('name') == 'terms') {
7680                                    var field_value = $(this).is(':checked') ? '1' : '';
7681                                } else {
7682                                    var field_value = $(this).is(':checked') ? 'Yes' : 'No';
7683                                }
7684                            }
7685                            if ($(this).attr('name') == 'message') {
7686                                data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />').replace('%', 'percent') + '&';
7687                            } else {
7688                                data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
7689                            }
7690                        }
7691                    });
7692
7693                    data = data + 'type=send&originating_page=' + encodeURIComponent(window.location.pathname + window.location.search);
7694                    
7695                    var url_context = "/mailing-list/signup/";
7696                    var submit_type = 'standard';
7697                    if ($(instance).closest('.page_enquiry_widget').attr('id') == 'page_enquiry_secondary') {
7698                        url_context = "/enquiry/";
7699                        var submit_type = 'advanced';
7700                    }
7701                    $.ajax({
7702                        url: url_context,
7703                        data: data,
7704                        cache: false,
7705                        method: 'POST',
7706                        dataType: 'json',
7707                        success: function(data) {
7708                            $('.page_enquiry_widget')
7709                                .eq(0)
7710                                .delay(400)
7711                                .queue(function() {
7712                            		$('.page_enquiry_widget .page_enquiry_widget_submit').removeClass('loading');
7713                                    $('.form_row_submit .button').removeClass('loading');
7714                                    if (data['success']) {
7715                                        window.archimedes.archimedes_core.analytics.track_campaigns.save_form_data($(instance));
7716
7717                                        $('.page_enquiry_widget').addClass('success');
7718                                        h.alert('<h2>Thank you</h2><div>You have been added to our mailing list.</div>
7718', {buttons: false});
7719                                        if (window.ga) {
7720                                            // Track in Analytics
7721                                            analytics_params = {
7722                                              'hitType': 'event',
7723                                              'eventCategory': 'Enquiry form submit success',
7724                                              'eventAction': window.location.pathname,
7725                                              'eventLabel': $(document).attr('title')
7726                                            };
7727                                            ga('send', analytics_params);
7728                                            ga('tracker2.send', analytics_params);
7729                                        }
7730
7731                                    } else {
7732                                        var error_message = '<h2>Sorry</h2>There was a problem signing up to the mailing list. Please try again or contact us for assistance.';
7733                                        if (data['error_message'] && typeof data['error_message'] != 'undefined') {
7734                                            var error_message = data['error_message'];
7735                                        }
7736                                        var field_errors = [];
7737                                        if (data['field_errors'] && typeof data['field_errors'] != 'undefined') {
7738                                            var field_errors = data['field_errors'];
7739                                        }
7740                                        $.each(field_errors, function(i, v) {
7741                                            $('.page_enquiry_widget').find('[name="' + v + '"]').closest('.form_row').addClass('error');
7742                                        });
7743                                        // console.log('alert')
7744                                        if (error_message) {
7745                                            h.alert(error_message, {buttons: fal
7745se});
7746                                        }
7747
7748                                        if (window.ga) {
7749                                            // Track in Analytics
7750                                            analytics_params = {
7751                                              'hitType': 'event',
7752                                              'eventCategory': 'Enquiry form submit error',
7753                                              'eventAction': window.location.pathname,
7754                                              'eventLabel': $(document).attr('title')
7755                                            };
7756                                            ga('send', analytics_params);
7757                                            ga('tracker2.send', analytics_params);
7758                                        }
7759
7760                                    }
7761                                    $(this).dequeue();
7762                                })
7763                           ;
7764                        }
7765                    });
7766                }
7767
7768            },
7769
7770            after_submit: function() {
7771
7772            }
7773
7774        },
7775
7776        mailing_list_form: {
7777
7778            _send_url: '/mailing-list/signup/',
7779            _error_messages: '',
7780
7781            init: function() {
7782                var self = this;
7783                $('.mailing_list_form')
7784                    .unbind()
7785                    .each(function() {
7786                        $('.field', this)
7787                            .unbind()
7788                            .each(function() {
7789                                $(this).val($(this).attr('data-default-value'));
7790                            })
7791                            .focus(function() {
7792                                if ($(this).val() == $(this).attr('data-default-value')) {
7793                                    $(this).addClass('active').val('');
7794                                }
7795                            })
7796                            .blur(function() {
7797                                if ($(this).val() == '') {
7798                                    $(this).removeClass('active').val($(this).attr('data-default-value'));
7799                                }
7800                            })
7801                        ;
7802                        $('.submit_button', this).unbind().click(function() {
7803                            $(this).closest('form').submit();
7804                            return false;
7805                        });
7806                        $('input, textarea', this).keypress(function(event) {
7807                            if (event.which == 13) {
7808                                $(this).closest('form').submit();
7809                                return false;
7810                            }
7811                        });
7812                    })
7813                    .submit(function(e){
7814                        e.preventDefault();
7815                        self._send_form($(this).closest('form'));
7816                    });
7817
7818                    if ($('.contact_form_captcha_enabled').length > 0) {
7819                        
7820                        if (typeof google_captcha_onload != 'undefined') {
7821                            
7822                            google_captcha_onload();
7823                        }
7824                    }
7825            },
7826
7827            _form_data: function(instance) {
7828
7829                var data = {}
7830                $('input, textarea', instance).each(function() {
7831                    if ($(this).val() != $(this).attr('data-default-value')) {
7832                        data[$(this).attr('name')] = $(this).val();
7833                    } else {
7834                        data[$(this).attr('name')] = '';
7835                    }
7836                });
7837                return data;
7838            },
7839
7840            _clear_form_data: function(instance) {
7841                $('input, textarea', instance).each(function() {
7842                    $(this).val($(this).attr('data-default-value'));
7843                });
7844                $('.error', instance).text('').hide();
7845            },
7846
7847            _mandatory_fields: function() {
7848
7849            },
7850
7851            _email_is_valid: function(instance) {
7852                var self = this,
7853                    flag = false,
7854                    email = self._form_data(instance)['email'];
7855
7856                if (!self._form_data(instance)['email']) {
7857                    flag = false;
7858                } else if (email.indexOf('@') > -1 && email.split('@')[1].indexOf('.') > -1 && email.indexOf(' ') == -1) {
7859                    flag = true;
7860                }
7861
7862                /* Set error message */
7863                if (!flag) {
7864                     self._set_error('<h2>Sorry</h2>Please enter a valid email address.');
7865                     return false
7866                }
7867                return flag;
7868
7869
7870            },
7871
7872            _emails_match: function(instance) {
7873
7874                // We are NOT matching the emails on this form
7875                return true;
7876
7877                var self = window.site.mailing_list_form,
7878                    flag = false;
7879
7880                self._form_data(instance)['email2'] == self._form_data(instance)['email'] ? flag = true : flag = false;
7881
7882                /* Set error message */
7883                if (!flag) {
7884                    self._set_error('Your email addresses do not match.');
7885                }
7886                return flag;
7887            },
7888
7889            _email_not_exists: function(instance) {
7890
7891                return true;
7892                
7893            },
7894
7895            _set_error: function(error) {
7896                this._error_messages = error;
7897            },
7898
7899            _display_error: function(instance) {
7900                var self = this;
7901                error_messages_str = '' + self._error_messages + ''
7902                error_element = $('.error', instance);
7903                if (!error_element.length) {
7904                    // Fall back to error container outside the mailing list form
7905                    error_element = $('.error');
7906                }
7907                $(error_element).text(error_messages_str);
7908                $(error_element).fadeOut(1);
7909                $(error_element).fadeIn(200);
7910            },
7911
7912            _send_form: function(instance) {
7913
7914                var self = this;
7915                if ($(instance).hasClass('contact_form_captcha_enabled')) {
7916                    if (!$('body').hasClass('contact_form_captcha_challenge_passed')) {
7917                        var captcha_error = '<h2>Sorry</h2>An error occurred, please refresh this page and try again. If you continue to have problems please contact us for support.';
7918                        if (typeof grecaptcha != 'undefined') {
7919                            window.recaptcha_success_callback_instance = instance;
7920                            window.recaptcha_success_callback = function (instance) {
7921                                window.site.mailing_list_form._send_form(instance);
7922                            };
7923                            try {
7924                                grecaptcha.execute();
7925                            } catch (error_message) {
7926                                h.alert(captcha_error);
7927                                $(instance).removeClass('submitting');
7928                                $('.button', instance).removeClass('loading');
7929                                $.ajax({
7930                                    url: "/api/process_js_error/",
7931                                    data: 'type=captcha&message=Captcha error on page ' + window.location.pathname + ' Error message: ' + error_message,
7932                                    cache: false
7933                                });
7934                            }
7935                        } else {
7936                            h.alert(captcha_error);
7937                            $(instance).removeClass('submitting');
7938                            $('.button', instance).removeClass('loading');
7939                            var error_message = 'Unknown error - grecaptcha may be undefined'
7940                            $.ajax({
7941                                url: "/api/process_js_error/",
7942                                data: 'type=captcha&message=Captcha error on page ' + window.location.pathname + ' Error message: ' + error_message,
7943                                cache: false
7944                            });
7945                        }
7946                        return;
7947                        
7948                    } else {
7949                        $('body').removeClass('contact_form_captcha_challenge_passed');
7950                    }
7951                }
7952                if (self._email_is_valid(instance) && self._email_not_exists(instance) && self._emails_match(instance)) {
7953                    $.ajax({
7954                        url: self._send_url,
7955                        type: "POST",
7956                        dataType: 'json',
7957                        data: self._form_data(instance),
7958                        success: function(data) {
7959                            if (data.success) {
7960                                h.alert('<h2>Thank you</h2>
7960 You have been added to our mailing list.', {buttons: false});
7961                                self._clear_form_data(instance);
7962                                window.site.overlays.mailings.close();
7963                                if ($('.contact_form_captcha_enabled').length > 0) {
7964                                    if (typeof grecaptcha != 'undefined') {
7965                                        grecaptcha.reset();
7966                                    }
7967                                }
7968                            } else {
7969                                self._set_error('There was a problem adding you to the mailing list, please check the form and try again.');
7970                                self._display_error(instance);
7971                                if ($('.contact_form_captcha_enabled').length > 0) {
7972                                    if (typeof grecaptcha != 'undefined') {
7973                                        grecaptcha.reset();
7974                                    }
7975                                }
7976                            }
7977                            if ($('.contact_form_captcha_enabled').length > 0) {
7978                                if (typeof google_captcha_onload != 'undefined') {
7979                                    google_captcha_onload();
7980                                }
7981                            }
7982                        }
7983                    });
7984                } else {
7985                    self._display_error(instance);
7986                }
7987            }
7988        },
7989
7990        artists: {
7991        	
7992        	init: function() {
7993        	    
7994        	    $('#artist_list_grid_selector li').click(function() {
7995                    var this_type = $(this).attr('data-type');
7996                    $('.scroll_section_artist_list_grid').removeClass('image-active');
7997                    $('.scroll_section_artist_list_grid_image_background').css('background-image', '');
7998                    $('#artist_list_grid_selector li').removeClass('active');
7999                    $('#artist_list_grid_selector li button').removeAttr('aria-label');
8000                    $(this).addClass('active');
8001                    var button_label = $(this).find('button').text();
8002                    $(this).find('button').attr('aria-label', (button_label + ' (selected)'));
8003                    
8004                    $('#artist_list_grid_container .artist_list_section').removeClass('active animate').addClass('disabled');
8005                    $('#artist_list_grid_container .artist_list_section[data-type="' + this_type + '"]').addClass('active').removeClass('disabled');
8006                    setTimeout(function() {
8007                        $('#artist_list_grid_container .artist_list_section[data-type="' + this_type + '"]').addClass('animate');
8008                    }, 10, this_type);
8009                    
8010                    if (typeof $('#artist_list_grid_container .artist_list_section[data-type="' + this_type + '"]').attr('data-image') != 'undefined') {
8011                        $('.scroll_section_artist_list_grid').addClass('image-active');
8012                        $('.scroll_section_artist_list_grid_image_background').css('background-image', 'url(' + $('#artist_list_grid_container .artist_list_section[data-type="' + this_type + '"]').attr('data-image') + ')');
8013                    }
8014                    
8015                });
8016                
8017                // if (window.site.device.breakpoint() <= 2) {
8018                //     $('#artist_list_grid_selector li[data-type="list"]').trigger('click');
8019                // } else {
8020                //     $('#artist_list_grid_selector li[data-type="grid"]').trigger('click');
8021                // }
8022        	    
8023        	    window.site.artists.artist_list_columns();
8024        	    
8025        	    $('.artist_list_panel').each(function() {
8026        	        $(this).attr('data-artist-list-index', $(this).index('.artist_list_panel'));
8027                    $('.artist_names_list li a', this).hover(function() {
8028                        $(this).closest('.artist_names_list').find('li a').removeClass('active');
8029                        $(this).addClass('active');
8030                        var this_index = $(this).attr('data-index');
8031                        if (!$('.artist_image_preview li[data-index="' + this_index + '"]', $(this).closest('.artist_list_panel')).hasClass('active')) {
8032                            window.site.artists.list_hover(this_index, false, $(this).closest('.artist_list_panel'));
8033                        }
8034                    }, function() {
8035                	    if (typeof artist_name_hover_timeout != 'undefined') {
8036                            clearTimeout(artist_name_hover_timeout);
8037                        }
8038                    });
8039                    
8040                    var random = Math.floor(Math.random()* $('.artist_names_list li a', this).length);
8041                    $('.artist_names_list li a', this).eq(random).each(function() {
8042                        var this_index = $(this).attr('data-index');
8043                        $(this).addClass('active');
8044                        window.site.artists.list_hover(this_index, true, $(this).closest('.artist_list_panel'));
8045                    });
8046                    
8047                    $('.artist_names_list li a[href="#"]', this).click(function() {
8048                        return false;
8049                    });
8050        	    });
8051                
8052        	},
8053        	
8054        	artist_list_preview: function() {
8055        	    
8056        	    if ($('.artist_image_preview').length) {
8057        	        
8058                    var selector = $(".artist_image_preview > .item").not('.cycle-sentinel');
8059                    
8060                    var random_slide_index = parseInt($('.artist_image_preview').attr('data-first-slide')) - 1;
8061                    // var random_slide_index = Math.floor(Math.random() * selector.length);
8062                    // console.log(random_slide_index);
8063
8064                    var params = {
8065                        fx:     'fade',
8066                        speed:    800,
8067                        timeout:  4500,
8068                        paused: true,
8069                        before: function(cSlide, nSlide, options) {
8070                            
8071                        },
8072                        after: function(cSlide, nSlide, options) {
8073
8074                        },
8075                        slides: '>',
8076                        startingSlide: parseInt(random_slide_index),
8077                        autoHeight: false
8078                    };
8079                
8080                
8081                    $('.artist_image_preview').cycle(params);
8082
8083                    // $( '.artist_image_preview' ).on( 'cycle-before', function( event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag ) {
8084                    //     // event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag
8085                    //     // argument opts is the slideshow's option hash
8086                        
8087                    // });
8088                    $( '.artist_image_preview' ).on( 'cycle-after', function( event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag ) {
8089                        // event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag
8090                        // argument opts is the slideshow's option hash
8091                        $(outgoingSlideEl).removeClass('zoom-animation');
8092                        $(incomingSlideEl).addClass('zoom-animation');
8093                    });
8094
8095                    // Add hover styling and change to correct slideshow slide
8096                    function onHover(hoverElement) {
8097                        $('.artist_names_list li').removeClass('last_hovered');
8098                        hoverElement.closest('li').addClass('last_hovered');
8099                        
8100                        $('.artist_list_section_list').addClass( "list-hover-active" );
8101                        hoverElement.addClass('hovering');
8102                        
8103                        if ($('.artist_image_preview').is(':visible')) {
8104                            $('.artist_image_preview').cycle('pause');
8105                            $('.artist_image_preview').cycle(parseInt(hoverElement.attr('data-index')) - 1);
8106                            return false;
8107                        }
8108                    }
8109                    // Remove hover styling
8110                    function afterHover(hoverElement) {
8111                        $('.artist_list_section_list').removeClass( "list-hover-active" );
8112                        hoverElement.removeClass('hovering hovered-on-touch');
8113                    }
8114                    
8115                    // Add hover effect for mobile
8116                    $('.artist_names_list li a').on('touchstart', function(e) {
8117                        if (!$(this).hasClass('hovered-on-touch')) {
8118                            e.preventDefault();
8119                            $('.artist_list_section_list').removeClass( "list-hover-active" );
8120                            $('.artist_names_list li a').removeClass('hovering hovered-on-touch');
8121                            $(this).addClass('hovered-on-touch');
8122                            onHover($(this));
8123                        } else {
8124                            afterHover($(this));
8125                        }
8126                    });
8127                    
8128                    
8129                    // Add hover effect for desktop
8130                    $( ".artist_names_list li a" ).hover(function() {
8131                        onHover($(this));
8132                    }, function() {
8133                        afterHover($(this));
8134                    });
8135                    
8136                    // If scrolled a certain distance - remove any hover styles (mainly needed for mobile)
8137                    var initial_scroll_top_distance = $(document).scrollTop();
8138                    $(document).scroll(function() {
8139                        var current_scroll_top_distance = $(document).scrollTop();
8140                        var difference_in_scroll_position = current_scroll_top_distance - initial_scroll_top_distance;
8141                        if (difference_in_scroll_position >= 40 || difference_in_scroll_position <= -40) {
8142                            $('.artist_list_section_list').removeClass('list-hover-active');
8143                            $(".artist_names_list li a").removeClass('hovering hovered-on-touch');
8144                            initial_scroll_top_distance = current_scroll_top_distance;
8145                        }
8146                    })
8147                    
8148                    // Remove hover effects on mobile if anywhere other than an artist link is touched
8149                    $(document).on('touchend', function(e) {
8150                        if (!$(e.target).closest(".artist-name-link").length) {
8151                            $('.artist_list_section_list').removeClass('list-hover-active');
8152                            $(".artist_names_list li a").removeClass('hovering hovered-on-touch');
8153                        }
8154                    });
8155                }
8156        	},
8157        	
8158        	
8159        	list_hover_load_adjacent: function(image) {
8160        	    
8161        	   // console.log(image.closest('.item').prev().find('img').attr('data-src'));
8162        	    
8163        	   // console.log(image.closest('.item').index());
8164        	    
8165        	    //console.log($('li.last_hovered').index());
8166        	    var items_to_load = [];
8167        	    
8168        	    var hovered_index = $('.last_hovered').index();
8169        	    
8170        	    var above_item = $('.last_hovered').prev();
8171                items_to_load.push(above_item);
8172        	    
8173        	    var below_item = $('.last_hovered').next();
8174        	    items_to_load.push(below_item);
8175        	    
8176        	    var left_item = $('.last_hovered').closest('ul').prev('ul').find('li').eq(hovered_index);
8177        	    items_to_load.push(left_item);
8178        	    var left_item_above = left_item.prev();
8179        	    items_to_load.push(left_item_above);
8180        	    var left_item_below = left_item.next();
8181        	    items_to_load.push(left_item_below);
8182        	    
8183        	    
8184        	    var right_item = $('.last_hovered').closest('ul').next('ul').find('li').eq(hovered_index);
8185        	    items_to_load.push(left_item);
8186      	        var right_item_above = right_item.prev();
8187        	    items_to_load.push(right_item_above);
8188        	    var right_item_below = right_item.next();
8189        	    items_to_load.push(right_item_below);
8190        	    
8191        	    $.each( items_to_load, function( index, value ){
8192                    var url = this.attr('data-preload-url');
8193                    var this_item = this;
8194                    
8195                    if (this_item && typeof this_item != 'undefined') {
8196                        var slide_index = this_item.find('a').attr('data-index');
8197                        var slide_image = $('.artist_image_preview .item[data-index="'+slide_index+'"]').find('.image');
8198                        window.site.lazy_load.fire(slide_image);
8199                    }
8200                    
8201                });
8202        	    
8203        	},
8204        	
8205        	preload_image: function(url) {
8206        	    
8207        	},
8208        	
8209        	list_hover: function(this_index, auto, context) {
8210        	    
8211        	    var context_index = $(context).attr('data-artist-list-index');
8212        	    
8213        	    var auto = auto && typeof auto != 'undefined' ? true : false;
8214        	    
8215        	    var artist_name_hover_timeout = [];
8216        	    var artist_name_hover_timeout2 = [];
8217        	    var artist_name_hover_timeout3 = [];
8218        	    
8219        	    if (this_index && typeof this_index != 'undefined') {
8220            	    if (typeof artist_name_hover_timeout[context_index] != 'undefined') {
8221                        clearTimeout(artist_name_hover_timeout[context_index]);
8222                    }
8223                    if (typeof artist_name_hover_timeout2[context_index] != 'undefined') {
8224                        clearTimeout(artist_name_hover_timeout2[context_index]);
8225                    }
8226                    if (typeof artist_name_hover_timeout3[context_index] != 'undefined') {
8227                        clearTimeout(artist_name_hover_timeout3[context_index]);
8228                    }
8229                    artist_name_hover_timeout[context_index] = setTimeout(function() {
8230                        if (!auto) {
8231                            $('.artist_names_list', context).addClass('item-hovering');
8232                        }
8233                        $('.artist_image_preview li', context).removeClass('animate');
8234                        artist_name_hover_timeout2[context_index] = setTimeout(function() {
8235                            $('.artist_image_preview li', context).removeClass('active');
8236                            $('.artist_image_preview li[data-index="' + this_index + '"]', context).addClass('active');
8237                            artist_name_hover_timeout3[context_index] = setTimeout(function() {
8238                                $('.artist_image_preview li[data-index="' + this_index + '"]', context).addClass('animate');
8239                            }, 20, context);
8240                            
8241                        }, 100, context);
8242                    }, 350, auto, context);
8243        	    }
8244        	},
8245        	
8246        	artist_list_columns: function() {
8247                    
8248                if ($('.artists_list_dynamic_columns').length) {
8249                    
8250                    // window.galleries.artist_list_preview.vertically_centre_artist_list.init();
8251                    
8252                    $('.artists_list_dynamic_columns .artist_list_positioning_wrapper').each(function(i) {
8253                        
8254                        var $this = $(this);
8255                        var instance_number = (i + 1).toString();
8256                        var list_original_id = '#artists_list_original_wrapper_' + instance_number;
8257                        var list_formatted_id = '#artists_list_formatted_wrapper_' + instance_number;
8258                        
8259                        /*
8260                            1.  Format the column widths correctly. It takes the desktop column width as an 'ideal' size, and tries to maintain that as the
8261                                browser scales down. As each column becomes too small, the number of columns reduces.
8262                            
8263                            2.  Distributes the items into each column correctly. The items flow downwards then are broken into the next column. E.g 15 items / 5 column grid:
8264                                A   D   G   J   M
8265                                B   E   H   K   N
8266                                C   F   I   L   O
8267                                
8268                                --------------------------------------------------------
8269                            
8270                                E.g. 17 items / 5 column grid
8271                                
8272                                DISTRIBUTION METHOD A:
8273                                The script works out how to fill the columns as evenly as possible, then works out which columns should have more items.
8274                                Visually appears a bit like inline-block flowing (horizontal), although the items still actually flow vertically:
8275                                
8276                                A   D   G   J   M
8277                                B   E   H   K   N
8278                                C   F   I   L   O
8279                                P   Q
8280                                
8281                                
8282                                DISTRIBUTION METHOD B:
8283                                
8284                                A   E   I   M   Q
8285                                B   F   J   N
8286                                C   G   K   O
8287                                D   H   L   P
8288                        */
8289
8290                        //Take the lists and break them into a hidden original list and container for our reformatted version.
8291                        $this.append('<div id="'+list_original_id.substring(1)+'" class="artists-list-original-wrapper">' + $this.html() + '</div>');
8292                        $this.children('ul').remove();
8293                        $this.append('<div id="'+list_formatted_id.substring(1)+'" class="artists-list-formatted-wrapper clearwithin"></div>');
8294                        var original_window_width = $(window).width();
8295                        var initial_run = false;
8296                        $(window).resize(function() {
8297                            
8298                            // Check that width actually changes due to iphones triggering resize events on scroll
8299                            if (!initial_run || ($(window).width() > original_window_width || $(window).width() < original_window_width)) {
8300                                
8301                                initial_run = true
8302                            
8303                                $(list_original_id).show();
8304                                $(list_formatted_id).html('');
8305                                
8306                                var columns;
8307                                var column_fill_method = 'a'; //OPTIONS A or B... EXPLAINED ABOVE
8308                                var container_width = parseInt($this.width());
8309                                
8310                                //How many desired columns fit within the container (at desktop size).
8311                                var initially_set_columns = Math.floor(container_width + 20) / $(list_original_id+' > ul').outerWidth();
8312                                
8313                                var screen_width = $(window).width();
8314                                original_window_width = screen_width;
8315                                if (screen_width > 1023) {
8316                                    columns = 4;
8317                                } else if (screen_width > 767) {
8318                                    columns = 3;
8319                                } else {
8320                                    columns = 1;
8321                                }
8322                                
8323                                // NEW CODE 2018
8324                                // THERE SHOULD ALWAYS BE AT LEAST 1 COLUMN
8325                                // THIS ATTEMPTS TO FIX A BUG WHERE WHEN THE SCREEN SIZE WAS < 387px THE LIST WOULD NOT RENDER. REMOVE THE FOLLOWING TO TEST.
8326                                if(columns < 1){
8327                                    columns = 1;
8328                                }
8329                                // END OF NEW CODE
8330                                
8331                                var column_width = 1 / columns * 100;
8332                                var total_items = $(list_original_id).find('li').length;
8333                                
8334                                
8335                                if (column_fill_method == 'a') {
8336                                    /*
8337                                        DISTRIBUTION METHOD A:
8338                                        
8339                                        A   D   G   J   M
8340                                        B   E   H   K   N
8341                                        C   F   I   L   O
8342                                        P   Q
8343                                        
8344                                    */
8345                                    //Work out how many items would 'evenly' fill up the columns
8346                                    var evenly_filled_items_number = Math.floor(total_items / columns);
8347    
8348                                    // How many extra items are we left with? These to be evenly distributed across columns.
8349                                    remainder = total_items % columns;
8350    
8351                                } else {
8352                                    
8353                                    /*
8354                                        DISTRIBUTION METHOD B:
8355                                        
8356                                        A   E   I   M   Q
8357                                        B   F   J   N
8358                                        C   G   K   O
8359                                        D   H   L   P
8360                                        
8361                                    */
8362                                    var evenly_filled_items_number = Math.ceil(total_items / columns);
8363                                    remainder = 0;
8364                                }
8365    
8366                                
8367                                var current_item_index = 0;
8368    
8369                                for (var i = 0; i < columns; i++) {
8370                                    var extra_items_in_col = 0;
8371                                    if (remainder > 0) {
8372                                        var extra_items_in_col = 1;
8373                                        remainder = remainder - 1;
8374                                    }
8375                                    // Create columns with correct distribution.
8376                                    $(list_formatted_id).append('<ul class="dynamic-column ani-in"></ul>');
8377                                    $(list_original_id).find('li').slice(current_item_index, current_item_index + evenly_filled_items_number + extra_items_in_col).each(function() {
8378                                        var this_li_html = $(this).clone().wrap('<div>').parent().html();
8379                                        $(list_formatted_id+' ul:last-child').append(this_li_html);
8380                                    });
8381                                    var current_item_index = current_item_index + evenly_filled_items_number + extra_items_in_col;
8382                                }
8383                                $(list_formatted_id+' ul').css('width',column_width + '%');
8384                                $(list_original_id).hide();
8385                                
8386                                window.site.artists.artist_list_preview();
8387                                window.site.layout.grids.init();
8388                                
8389                                // if (window.site.device.handheld()) {
8390                                //     var onLoadHeight = $(window).height() - 93;
8391                                //     $('.artist_list_section_list .artist_image_preview').css({ height: onLoadHeight });
8392                                // }
8393                                
8394                                if ($.pageload && typeof $.pageload != 'undefined') {
8395                                    if($.pageload.fn && $.pageload.fn != 'undefined'){
8396                                       $.pageload.fn.pages.add_click_events(); 
8397                                    }
8398                                }
8399                            }
8400                            
8401                        }).trigger('resize');
8402                    });
8403                    
8404                }
8405            }
8406            
8407        },
8408
8409        exhibitions: {
8410
8411        },
8412
8413        countdown_clock: {
8414
8415            init: function() {
8416
8417
8418                $('.countdown_clock').each(function() {
8419                    
8420                    var $this = $(this);
8421                    
8422                    
8423                    // Set the date we're counting down to
8424                    var start_date = $(this).attr('data-target-time');
8425                    var countDownDate = new Date(start_date.replace(/-/g,"/")).getTime();
8426                    
8427                    // Clock is active
8428                    if (!$this.closest('.countdown_clock').hasClass('active')) {
8429                        $this.closest('.countdown_clock').addClass('active');
8430                    }
8431                    
8432                    // Set clock on first load
8433                    $this.html(window.site.countdown_clock.update_clock_html(countDownDate));
8434                    
8435                    // Update the countdown every 1 second
8436                    setInterval(function() {
8437                        $this.html(window.site.countdown_clock.update_clock_html(countDownDate));
8438                    }, 1000);
8439                
8440                });    
8441
8442            },
8443            
8444           update_clock_html: function(countDownDate) {
8445                  var clock_format = 'full';
8446                  // Get today's date and time
8447                  var now = new Date().getTime();
8448                  // Find the distance between now and the count down date
8449                  var distance = countDownDate - now;
8450                  var _html_ = '';
8451                    if (distance <= 0) {
8452                        _html_ = ''
8453                        $('.countdown_text').each(function() {
8454                            $(this).text('');
8455                            $(this).closest($('.countdown_container')).css('border', 'none');
8456                        });
8457                    } else {
8458                        if (clock_format == 'days') {
8459                              // Time calculations for days, hours, minutes and seconds
8460                              var days = Math.ceil(distance / (1000 * 60 * 60 * 24));
8461                              _html_ += (days != 0 ? '<span class="numeral">'+ days+ '</span>' : '');
8462                              _html_ += (days != 0 ? ' <span class="countdown_text">'+ (days > 1 ? 'days' : 'day') + '</span>' : '');
8463                        } else if (clock_format == 'full') {
8464                              // Time calculations for days, hours, minutes and seconds
8465                              var days = Math.floor(distance / (1000 * 60 * 60 * 24));
8466                              var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
8467                              var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
8468                              var seconds = Math.floor((distance % (1000 * 60)) / 1000);
8469                              _html_ += ('<span class="segment"><span class="numeral">'+ days+ '</span><span class="period">Days</span></span><span class="segment-divide">:</span>' || '');
8470                              _html_ += ('<span class="segment"><span class="numeral">'+ hours+ '</span><span class="period">Hours</span></span><span class="segment-divide">:</span>' || '');
8471                              _html_ += ('<span class="segment"><span class="numeral">'+ minutes+ '</span><span class="period">Mins</span></span><span class="segment-divide">:</span>' || '');
8472                              _html_ += '<span class="segment"><span class="numeral">'+ seconds+ '</span><span class="period">Secs</span></span>';
8473                        }
8474                    }
8475                  return _html_;
8476            }
8477        },
8478
8479
8480        store: {
8481
8482            init: function() {
8483                
8484                if ($('#wishlist_enquiry_submitted_confirmation').length) {
8485                    h.alert($('#wishlist_enquiry_submitted_confirmation').html(), {buttons: fal
8485se});
8486                }
8487                
8488                $('#wishlist_enquiry_form_submit_button').addClass('alt');
8489
8490                $('#shipping_container_loader').addClass('loader');
8491                $('#stripe_loader').addClass('loader');
8492                
8493                if (false) {
8494                    $('input, textarea', '#sc_additional_fields, #wishlistEnquiryForm')
8495                        .each(function() {
8496                            $(this).attr('default-value', $(this).parent().find('> label').text());
8497                            $(this).attr('placeholder', $(this).parent().find('> label').text());
8498                            if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
8499                                $(this).addClass('active');
8500                            } else {
8501                                $(this).val($(this).attr('default-value'));
8502                            }
8503                        })
8504                        .focus(function() {
8505                            if ($(this).val() == $(this).attr('default-value')) {
8506                                $(this).addClass('active');
8507                                $(this).val('');
8508                            }
8509                        })
8510                        .blur(function() {
8511                            $(this).attr('default-value', $(this).parent().find('label').text());
8512                            if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
8513                                $(this).val($(this).attr('default-value'));
8514                                $(this).removeClass('active');
8515                            }
8516                        })
8517                    ;   
8518                }
8519            }
8520
8521        },
8522        
8523        commands: {
8524            
8525            scrollto: function(offset, callback) {
8526                if ((offset && typeof offset != 'undefined') || offset == 0) {
8527                    $(window).bind('mousewheel.scrollcancel', function() {
8528                        $('html,body').stop().clearQueue();
8529                    })
8530                    $('html,body').animate(
8531                        {scrollTop: offset},
8532                        800,
8533                        'easeInOutExpo',
8534                        function() {
8535                            $(window).unbind('mousewheel.scrollcancel');
8536                            $(window).trigger('scroll');
8537                            if (callback && typeof callback != 'undefined') {
8538                                callback();
8539                            }
8540                        }
8541                    );
8542                }
8543            }
8544              
8545        },
8546
8547        misc: {
8548
8549        	init: function(call_type) {
8550        	    
8551        	    
8552        	    // We need to move the location of the basket widget for smaller screen sizes so its within the header.
8553        	    function positionBasketUI() {
8554        	        if ($(window).width() <= 1023 && $('.header_translations_nav_inner #basket').length) {
8555            	        $('#header_items_inner').prepend($('.header_translations_nav_inner #basket'));
8556            	        $('#basket').addClass('basket-mobile-layout');
8557            	    } else if ($(window).width() > 1023 && $('#header_items_inner #basket').length) {
8558            	        $('.header_translations_nav_inner').append($('#header_items_inner #basket'));
8559            	        $('#basket').removeClass('basket-mobile-layout');
8560            	    }
8561        	    }
8562        	    
8563        	    $(window).on('resize', function() {
8564        	        positionBasketUI()
8565        	    });
8566        	    
8567        	    $('.list_caption_wrapper .store_item_group .data_div, .records_list_slider .store_item_group .data_div').each(function() {
8568        	        if (!$(this).find('.store_item').hasClass('store_item_sold_out') && $(this).closest('.store_item_group').find('.single-item-show').length == 0) {
8569        	            $(this).addClass('single-item-show');
8570        	        }
8571        	        if ($(this).closest('.item').find('a').length) {
8572        	            $(this).find('.store_item').css('pointer-events', 'n
8572one');
8573        	            $(this).css('cursor', 'pointer').unbind().click(function() {
8574                	        $(this).closest('.item').find('a').trigger('click');
8575                	        return false;
8576                	    });
8577        	        }
8578        	    });
8579        	    
8580        	    $('[data-content-record-id]').each(function() {
8581        	        $('body').addClass('content-record-id-' + $(this).attr('data-content-record-id'));
8582        	    });
8583        	    
8584        	    $('#content[data-auto-redirect]').each(function() {
8585        	        window.location.href = $('#content[data-auto-redirect]').attr('data-auto-redirect');
8586        	    });
8587                
8588                $('a[href^="#panel_record_id_"]').click(function() {
8589                    if ($($(this).attr('href')).length > 0) {
8590                        window.site.commands.scrollto($($(this).attr('href')).offset().top);
8591                        return false;
8592                    }
8593                });
8594                
8595                setTimeout(function() {
8596                    if (window.location.hash && window.location.hash != '' && !$('body').hasClass('exhibition-list-scroll-to-initiated')) {
8597                        $('body').addClass('exhibition-list-scroll-to-initiated');
8598                        var page_header_height = $('#page_header').outerHeight();
8599                        if (window.location.hash.indexOf('#panel_record_id_') == 0) {
8600                            if ($(window.location.hash).length > 0) {
8601                                window.site.commands.scrollto($(window.location.hash).offset().top);
8602                            }
8603                        } else if ($('body').hasClass('section-exhibitions') && window.location.hash.indexOf('#current') == 0) {
8604                            window.site.commands.scrollto($('section[data-label="Current"]').offset().top - (page_header_height - 3));
8605                        } else if ($('body').hasClass('section-exhibitions') && window.location.hash.indexOf('#upcoming') == 0) {
8606                            window.site.commands.scrollto($('section[data-label="Upcoming"]').offset().top - (page_header_height - 3));
8607                        } else if ($('body').hasClass('section-exhibitions') && window.location.hash.indexOf('#past') == 0) {
8608                            window.site.commands.scrollto($('section[data-label="Past"]').offset().top - (page_header_height - 3));
8609                        }
8610                    }
8611                }, 150);
8612                
8613                $('img[src*="youtube.com"], img[data-src*="youtube.com"]').addClass('image-source-youtube');
8614                
8615                $('a.scrollto').click(function() {
8616                    if ($($(this).attr('href')).length > 0) {
8617                        window.site.commands.scrollto($($(this).attr('href')).offset().top - 50);
8618                        return false;
8619                    }
8620                });
8621                
8622                if (window.location.hash && typeof window.location.hash != 'undefined') {
8623                    if (window.location.hash.indexOf('#scrollto-') == 0) {
8624                        setTimeout(function() {
8625                            if ($('[data-scrollto-section="' + window.location.hash.replace('#', '') + '"]').length) {
8626                                window.site.commands.scrollto($('[data-scrollto-section="' + window.location.hash.replace('#', '') + '"]').offset().top - 50);
8627                                return false;
8628                            }
8629                        }, 1000);
8630                    }
8631                }
8632        	    
8633                function string_ends_with(str, target) {
8634                   return str.substring(str.length-target.length) == target;
8635                }
8636
8637                $('.video_wrapper').not('.initialised').each(function() {
8638                    if ($('.video_placeholder', this).length > 0) {
8639                        $(this).addClass('initialised').find('.fluid-width-video-wrapper').each(function() {
8640                            if ($(this).find('iframe').length) {
8641                                var iframe_src = $(this).find('iframe').attr('src').replace('autoplay=1', '').replace('autoplay=0', '').replace('autoplay=1&', '').replace('autoplay=0&', '');
8642                                if (string_ends_with(iframe_src, '?')) {
8643                                    var iframe_src = iframe_src.replace('?', '');
8644                                }
8645                                if (iframe_src.indexOf('?') > -1) {
8646                                    var iframe_src = iframe_src + '&autoplay_placeholder=1';
8647                                } else {
8648                                    var iframe_src = iframe_src + '?autoplay_placeholder=1';
8649                                }
8650                                $(this).find('iframe').attr('data-src', iframe_src).attr('src', '');
8651                            }
8652                        });
8653                    }
8654                });
8655                $('.video_wrapper .video_placeholder').click(function() {
8656                    if (!$('body').hasClass('slider-drag')) {
8657                        $(this).closest('.video_wrapper').addClass('show_video');
8658                        // $(this).closest('.item').addClass('hide_caption');
8659                        $(this).closest('.video_wrapper').find('.fluid-width-video-wrapper').each(function() {
8660                            if ($(this).find('iframe').length) {
8661                                var iframe_src = $(this).find('iframe').attr('data-src').replace('autoplay_placeholder=1', 'autoplay=1');
8662                                $(this).find('iframe').attr('src', iframe_src);
8663                                var iframe_html = $(this).find('iframe').html();
8664                            } 
8665                        });
8666                    }
8667                });
8668                
8669                $('#logo').hover(function() {
8670                    if (typeof logo_hover_timeout != 'undefined') {
8671                        clearTimeout(logo_hover_timeout);
8672                    }
8673                    $('#logo').addClass('hover');
8674                    logo_hover_timeout = setTimeout(function () {
8675                        $('#logo').removeClass('hover');
8676                    }, 400);
8677                }, function() {
8678
8679                });
8680
8681                var call_type = (call_type && typeof call_type != 'undefined' ? call_type : 'standard');
8682                
8683                $('.store_item_add_to_cart').each(function() {
8684                    if (!$('.loader', this).length) {
8685                        $(this).append('<div class="loader"></div>');
8686                    } 
8687                });
8688                
8689                $('.button').each(function() {
8690                    if (!$(this).find('.loader').length) {
8691                        $(this).append('<span class="loader"></span>');
8692                    }
8693                });
8694                
8695                $('.loader, .loader_simple').each(function() {
8696                    if (!$(this).find('svg').length) {
8697                        $(this).append('<svg viewBox="25 25 50 50" focusable="false"><circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="4" stroke-miterlimit="10"/></svg>');
8698                    }
8699                });
8700
8701        		$('a').each(function() {
8702                    var el = $(this);
8703                    var href = el.attr('href');
8704                    if (href && href.indexOf('http') == 0 && !el.hasClass('noPopup')
8705                        && !el.hasClass('nopopup')
8706                        && !$('body').hasClass('no_pop_ups')
8707                        && !$('body').hasClass('nopopups')
8708                        && href.indexOf(window.location.hostname) == -1) {
8709                            el.attr('target', '_blank').addClass('external').append("<span class='visually-hidden'>. (This link opens in a new tab).</span>");
8710                    }
8711                });
8712
8713                if (call_type != 'popup') {
8714                    //$('body').removeClass('content-type-reversed');
8715                    //if ($('#container .content-reversed').length) {
8716                    //    $('body').addClass('content-type-reversed');
8717                    //}
8718                }
8719                
8720                //CLICK FOR MOBILE ONLY
8721                $('body.device-handheld button.store_item_multiple_button').unbind().click(filter_handler);
8722                
8723                //KEYDOWN FOR accessibility
8724                $('button.store_item_multiple_button').unbind().keydown(filter_handler);
8725                
8726                
8727                function filter_handler(e){
8728                    
8729                    if(e.type == "keydown"){
8730                        
8731                        var keyCode = e.which;
8732                        if ($("this:focus") && (keyCode == 13 || keyCode == 32)) {
8733                            if ($(this).parent().hasClass('active')) {
8734                                $(this).attr("aria-expanded", "false");
8735                                $(this).parent().removeClass('active');
8736                            } else {
8737                                $(this).attr("aria-expanded", "true");
8738                                $(this).parent().addClass("active");
8739                            }
8740                        } else if ($("this:focus") && (keyCode == 9 && e.shiftKey) && $(this).parent().hasClass('active')) {
8741                            $(this).attr("aria-expanded", "false");
8742                            $(this).parent().removeClass('active');
8743                        }
8744                        
8745                    } else if (e.type == "click") {
8746                        if ($(this).parent().hasClass('active')) {
8747                            $(this).attr("aria-expanded", "false");
8748                            $(this).parent().removeClass('active');
8749                        } else {
8750                            $(this).attr("aria-expanded", "true");
8751                            $(this).parent().addClass("active");
8752                        }
8753                    }
8754                }
8755                
8756                // Close dropdown menu if tab focus goes off dropdown menu
8757                $('.store_item_group_options .store_item_add_to_cart').on('keydown', function (e) {
8758                    var keyCode = e.which;
8759                    if ($(this).closest('.data_div').hasClass('first_item') && $("this:focus") && (keyCode == 9 && e.shiftKey)) {
8760                        $(this).closest('.store_item_group').removeClass("active");
8761                        $(this).closest('.store_item_group').attr("aria-expanded", "false");
8762                    } else if ($(this).closest('.data_div').hasClass('last_item') && $("this:focus") && (keyCode == 9 && !e.shiftKey)) {
8763                        $(this).closest('.store_item_group').removeClass("active");
8764                        $(this).closest('.store_item_group').attr("aria-expanded", "false");
8765                    } else if ($("this:focus") && (keyCode == 27)) {
8766                        $(this).closest('.store_item_group').removeClass("active");
8767                        $(this).closest('.store_item_group').find('.store_item_multiple_button').attr("aria-expanded", "false");
8768                        $(this).closest('.store_item_group').find('.store_item_multiple_button').focus();
8769                    }
8770                });
8771                
8772                $('.store_item_group_options .store_item_add_to_cart').each(function() {
8773                    var aria_label = $(this).closest('.data_div').attr('data-aria');
8774                    $(this).attr("aria-label", aria_label);
8775                });
8776                
8777                // Header drop downs click events
8778                $('#main_nav button').off('click.custom_dropdown_button').on('click.custom_dropdown_button', function(){
8779                    $button = $(this);
8780                    if ($(this).hasClass('dropdown-active')) {
8781                        window.site.misc.hideDropdown();
8782                    } else {
8783                        window.site.misc.showDropdown($button);
8784                    }
8785                });
8786
8787                /* Trigger dropdown on touch devices, otherwise you gotta doable tap */ 
8788                $('body.device-handheld #main_nav ul li button').on('click', function () {
8789                    window.site.misc.showDropdown($(this));
8790                });
8791                
8792                $('#main_nav .dropdown_navigation_container a').off('click.custom_dropdown_link').on('click.custom_dropdown_link', function(){
8793                    $('.dropdown-nav button').removeClass('active');
8794                    $(this).closest('li.dropdown-nav').find('button').addClass('active');
8795                });
8796                
8797                $('#main_nav > ul > li > a').off('click.custom_nav_link').on('click.custom_nav_link', function(){
8798                    $('.dropdown-nav button').removeClass('active');
8799                });
8800                
8801                // Header drop downs hover events
8802                $('#main_nav .dropdown-nav').off('mouseenter.dropdown_mouseenter').on('mouseenter.dropdown_mouseenter', function(){
8803                    $button = $('button', this);
8804                    window.site.misc.showDropdown($button);
8805				})
8806				.off('mouseleave.dropdown_mouseleave').on('mouseleave.dropdown_mouseleave', function(){
8807				    window.site.misc.hideDropdown();
8808				})
8809				
8810				// Mobile nav drop down click events
8811				$('.nav-wrapper .dropdown-nav button').off('click.custom_mobile_dropdown_link').on('click.custom_mobile_dropdown_link', function(){
8812				    
8813				    var dropdown_currently_active = false;
8814				    if ($(this).hasClass('dropdown_active')) {
8815				        dropdown_currently_active = true;
8816				    }
8817				    
8818                    $('.dropdown-nav button').removeClass('dropdown_active').attr("aria-expanded", "false");
8819                    
8820                    if (!dropdown_currently_active) {
8821                        $(this).addClass('dropdown_active').attr("aria-expanded", "true");
8822                        $('.nav-overlay li.dropdown-nav').find('button:not(.dropdown_active) + .dropdown_navigation_container').slideUp();
8823                        $(this).closest('li.dropdown-nav').find('.dropdown_navigation_container').slideDown();
8824                    } else {
8825                        $(this).closest('li.dropdown-nav').find('.dropdown_navigation_container').slideUp();
8826                    }
8827                    
8828                });
8829                
8830                // Mobile nav link click events
8831                $('.nav-wrapper a').off('click.custom_mobile_nav_link').on('click.custom_mobile_nav_link', function() {
8832				    
8833				    $('.nav-wrapper a').removeClass('active').removeAttr('aria-label');
8834				    $('.nav-wrapper button').removeClass('active').removeAttr('aria-label');
8835				    
8836				    if ($(this).hasClass('dropdown_navigation_link')) {
8837				        $(this).closest('.dropdown-nav').find('button').addClass('active');
8838				    } else {
8839				        $(this).addClass('active');
8840				    }
8841				    
8842                });
8843				
8844            	window.site.misc.map();
8845        	},
8846        	
8847        	showDropdown: function($button_elem) {
8848        	    var dropdown_height = $button_elem.next().height();
8849                $('#header .header-dropdown-mask').css({"max-height": dropdown_height});
8850                $('body').addClass('header-dropdown-active');
8851                $button_elem.addClass('dropdown-active').attr("aria-expanded", "true");
8852        	},
8853        	
8854        	hideDropdown: function() {
8855        	    $('#header .header-dropdown-mask').css({"max-height": "0"});
8856                $('body').removeClass('header-dropdown-active');
8857                $('#main_nav ul li button').removeClass('dropdown-active').attr("aria-expanded", "false");
8858        	},
8859
8860        	map: function() {
8861        		if ($('.map_area').length){
8862        		    $('.map_area').each(function() {
8863                        var latlng = $(this).attr('data-latlng').split(',');
8864                        if (latlng.length == 2) {
8865                            
8866                            var $thismap = $(this);
8867                            // console.log($(this).attr('data-latlng'));
8868                            var lat = $thismap.attr('data-latlng').split(',')[0];
8869                            var lng = $thismap.attr('data-latlng').split(',')[1];
8870                            var centerlat = $thismap.attr('data-centerlatlng').split(',')[0];
8871                            var centerlng = $thismap.attr('data-centerlatlng').split(',')[1];
8872                            var map_title = $thismap.attr('data-title');
8873                            var map_link = $thismap.attr('data-url');
8874                            var new_styles = [{"featureType":"all","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"landscape","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#fbfbfb"}]},{"featureType":"landscape.man_made","elementType":"geometry.fill","stylers":[{"visibility":"off"}]},{"featureType":"poi.park","elementType":"all","stylers":[{"visibility":"on"},{"saturation":"-58"},{"lightness":"61"}]},{"featureType":"poi.park","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#bfd6bf"}]},{"featureType":"poi.park","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#1c1b1b"},{"weight":"0.81"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"color":"#080808"},{"visibility":"on"}]},{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#fbfbfb"},{"weight":"8.79"}]},{"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"color":"#1c1b1b"},{"weight":"1.77"}]},{"featureType":"road.highway","elementType":"geometry.stroke","stylers":[{"visibility":"off"}]},{"featureType":"road.arterial","elementType":"geometry.fill","stylers":[{"weight":"2.49"}]},{"featureType":"road.arterial","elementType":"labels.text","stylers":[{"weight":"2.46"},{"visibility":"simplified"}]},{"featureType":"road.arterial","elementType":"labels.text.fill","stylers":[{"visibility":"on"},{"color":"#1c1b1b"}]},{"featureType":"road.arterial","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"gamma":"0.00"},{"weight":"9.60"},{"color":"#fbfbfb"}]},{"featureType":"road.local","elementType":"geometry.fill","stylers":[{"color":"#c1c0c0"}]},{"featureType":"road.local","elementType":"labels.text.fill","stylers":[{"visibility":"on"},{"color":"#171717"},{"weight":"5.73"}]},{"featureType":"road.local","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"weight":"4.40"},{"color":"#fbfbfb"}]},{"featureType":"transit.station.rail","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"transit.station.rail","elementType":"labels.text.fill","stylers":[{"color":"#000000"}]},{"featureType":"transit.station.rail","elementType":"labels.icon","stylers":[{"gamma":"0.00"}]}];
8875                            
8876                            var position = new google.maps.LatLng(lat, lng);
8877                            // if (window.site.device.breakpoint() <= 2) {
8878                            //     var center = new google.maps.LatLng(lat, lng);
8879                            //     var zoomLevel = 15;
8880                            // } else {
8881                            //     var center = new google.maps.LatLng(centerlat, centerlng);
8882                            //     var zoomLevel = 17;
8883                            // }
8884                            
8885                            var center = new google.maps.LatLng(centerlat, centerlng);
8886                            var zoomLevel = 16;
8887                            if ($thismap.attr('data-zoomLevel') && typeof $thismap.attr('data-zoomLevel') != 'undefined') {
8888                                 zoomLevel = parseInt($thismap.attr('data-zoomLevel'));
8889                            }
8890                            
8891                            var dark_map = false;
8892                            var markerImage = {
8893                                url: '/images/mapmarker-icon.svg',
8894                                size: new google.maps.Size(29, 45),
8895                                scaledSize: new google.maps.Size(29, 45),
8896                                origin: new google.maps.Point(0, 0),
8897                                anchor: new google.maps.Point(15, 45)
8898                            };
8899                            var myOptions = {
8900                              zoom: zoomLevel,
8901                              center: center,
8902                              mapTypeId: google.maps.MapTypeId.ROADMAP,
8903                              panControl: false,
8904                              //panControl: true,
8905                              //panControlOptions: {
8906                              //    position: google.maps.ControlPosition.TOP_RIGHT
8907                              //},
8908                              zoomControl: false,
8909                              zoomControlOptions: {
8910                                style: google.maps.ZoomControlStyle.SMALL,
8911                                position: google.maps.ControlPosition.LEFT_TOP
8912                              },
8913                              scaleControl: false,
8914                              streetViewControl: false,
8915                              overviewMapControl: false,
8916                              scrollwheel: false,
8917                              draggable: true,
8918                              styles: new_styles,
8919                              mapTypeControl: false,
8920                              fullscreenControl: false,
8921        				// 	  backgroundColor: $(this).closest('.footer').length > 0 ? '#a4afae' : '#f7f4f2'
8922                            }
8923    
8924                            //insert the map into the id on page using map options etc
8925                            var map = new google.maps.Map($(this)[0], myOptions);
8926    
8927                            //each marker config
8928                            var marker = new google.maps.Marker({
8929                                position: position,
8930                                map: map,
8931                                url: map_link,
8932                                title: map_title,
8933                                icon: markerImage
8934                            });
8935    
8936                            if (map_link != '') {
8937                                google.maps.event.addListener(marker, 'click', function() {
8938                                    window.open(
8939                                      marker.url,
8940                                      '_blank'
8941                                    );
8942                                });
8943                            }
8944                            google.maps.event.trigger(map, 'resize');
8945                        }
8946        		    });
8947
8948
8949
8950
8951                    $( window ).load(function() {
8952                        setTimeout(function() {
8953                            $("img[src$='google_white2.png']").css({ opacity: 0.4 });
8954                            $(".gm-style-cc").css({ opacity: 0.4 });
8955                            $(".gm-style-cc div, .gm-style-cc a").css({background: 'none', color: '#333'});
8956                            $('.gmnoprint, .gm-style-cc').remove();
8957                        }, 300);
8958                        setTimeout(function() {
8959                            $("img[src$='google_white2.png']").css({ opacity: 0.4 });
8960                            $(".gm-style-cc").css({ opacity: 0.4 });
8961                            $(".gm-style-cc div, .gm-style-cc a").css({background: 'none', color: '#333'});
8962                            $('.gmnoprint, .gm-style-cc').remove();
8963                        }, 400);
8964                    });
8965                }
8966        	},
8967        	mulitple_maps: function() {
8968     
8969        		if ($('#map_area').length){
8970        		    
8971                    var bounds  = new google.maps.LatLngBounds();
8972                    //var new_styles = [{"featureType":"all","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"all","elementType":"geometry","stylers":[{"visibility":"off"},{"weight":"1.34"}]},{"featureType":"all","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"all","elementType":"labels.text.fill","stylers":[{"saturation":36},{"color":"#ffffff"},{"lightness":40}]},{"featureType":"all","elementType":"labels.text.stroke","stylers":[{"visibility":"off"},{"color":"#000000"},{"lightness":16}]},{"featureType":"all","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"geometry.fill","stylers":[{"color":"#ffffff"},{"lightness":20}]},{"featureType":"administrative","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":17},{"weight":1.2}]},{"featureType":"landscape","elementType":"all","stylers":[{"visibility":"off"},{"color":"#34302d"}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#fbf8f9"},{"lightness":"0"},{"visibility":"simplified"},{"gamma":"1"}]},{"featureType":"landscape.man_made","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"landscape.man_made","elementType":"geometry","stylers":[{"visibility":"off"}]},{"featureType":"landscape.man_made","elementType":"geometry.fill","stylers":[{"visibility":"off"},{"saturation":"-100"},{"lightness":"-100"},{"gamma":"0.00"},{"weight":"2.20"}]},{"featureType":"landscape.man_made","elementType":"geometry.stroke","stylers":[{"visibility":"off"}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":21}]},{"featureType":"poi.attraction","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"all","stylers":[{"visibility":"simplified"},{"weight":"1.00"},{"color":"#ffffff"}]},{"featureType":"road","elementType":"geometry","stylers":[{"visibility":"simplified"},{"color":"#757575"}]},{"featureType":"road","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"visibility":"on"},{"color":"#111111"}]},{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#fbf8f9"},{"weight":"7.99"}]},{"featureType":"road.highway","elementType":"labels","stylers":[{"visibility":"simplified"}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":19}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#525358"},{"lightness":"0"},{"visibility":"on"}]}];
8973                    var new_styles = [{"featureType":"all","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"landscape","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#000099"}]},{"featureType":"landscape.man_made","elementType":"geometry.fill","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#363636"},{"weight":"0.81"}]},{"featureType":"road.arterial","elementType":"geometry.fill","stylers":[{"weight":"2.49"},{"visibility":"on"},{"color":"#ffffff"}]},{"featureType":"road.arterial","elementType":"labels.text","stylers":[{"weight":"2.46"}]},{"featureType":"road.arterial","elementType":"labels.text.fill","stylers":[{"visibility":"on"},{"color":"#ffffff"}]},{"featureType":"road.arterial","elementType":"labels.text.stroke","stylers":[{"gamma":"0.00"},{"color":"#00009c"},{"weight":"9.60"},{"visibility":"on"}]},{"featureType":"road.local","elementType":"geometry.fill","stylers":[{"color":"#6e6e9d"}]},{"featureType":"road.local","elementType":"labels.text.fill","stylers":[{"visibility":"on"},{"color":"#ffffff"},{"weight":"5.73"}]},{"featureType":"road.local","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#000099"},{"weight":"4.40"}]}];
8974                    var map = new google.maps.Map(document.getElementById("map_area"), {
8975                        zoom: 18,
8976                        styles: new_styles,
8977                        center: new google.maps.LatLng(40.750681,-74.002781),
8978                        mapTypeId: google.maps.MapTypeId.ROADMAP,
8979                        disableDefaultUI: true,
8980                        backgroundColor: '#f8f8f8',
8981                        panControl: false,
8982                          //panControl: true,
8983                          //panControlOptions: {
8984                          //    position: google.maps.ControlPosition.TOP_RIGHT
8985                          //},
8986                        zoomControl: false,
8987                        zoomControlOptions: {
8988                        style: google.maps.ZoomControlStyle.SMALL,
8989                        position: google.maps.ControlPosition.LEFT_TOP
8990                        },
8991                        scaleControl: false,
8992                        streetViewControl: false,
8993                        overviewMapControl: false,
8994                        scrollwheel: false,
8995                        draggable: true,
8996                        mapTypeControl: false,
8997                        fullscreenControl: false
8998                    });
8999                    /* Disabled this block - enable for info bubbles
9000                        var infoBubble = new InfoBubble({
9001                            map: map,
9002                            ShadowStyle: 0,
9003                            padding: 20, //padding in css
9004                            backgroundColor: '#fff',
9005                            borderRadius: 0,
9006                            arrowSize: 10,
9007                            borderWidth: 0,
9008                            arrowPosition: 50,
9009                            borderColor: 'transparent',
9010                            disableAutoPan: true,
9011                            disableAnimation: false,
9012                            hideCloseButton: true,
9013                            backgroundClassName: 'map-popup clearwithin',
9014                            //closeSrc: '/images/map-box-close.png'
9015                        });
9016                    */
9017                    
9018                    if ($(window).width() < 640){
9019                       var icon_inactive = {
9020                            url: '/images/ropac_map.svg',
9021                            size: new google.maps.Size(40, 40),
9022                            scaledSize: new google.maps.Size(40, 40),
9023                            origin: new google.maps.Point(0, 0),
9024                            anchor: new google.maps.Point(20, 20)
9025                        };   
9026                    } else {
9027                        var icon_inactive = {
9028                            url: '/images/ropac_map.svg',
9029                            size: new google.maps.Size(62, 62),
9030                            scaledSize: new google.maps.Size(62, 62),
9031                            origin: new google.maps.Point(0, 0),
9032                            anchor: new google.maps.Point(31, 31)
9033                        };
9034                    }
9035
9036                    var icon_landmark = {
9037                        url: '/images/landmark.svg',
9038                        size: new google.maps.Size(24, 60),
9039                        scaledSize: new google.maps.Size(12, 60),
9040                        origin: new google.maps.Point(-6, 22),
9041                        anchor: new google.maps.Point(12, 12)
9042                    };    
9043                    
9044                    function placeMarker(icon,lat,long,html,label) {
9045
9046                        var latLng = new google.maps.LatLng(lat, long);
9047
9048                        var icon_active = icon_active;
9049                        var arrow_options = {
9050                            position: latLng,
9051                            icon: icon,
9052                            map:map,
9053                            label: label
9054                            //title: 'I am a Draggable-Rotatable Marker!' 
9055                        };
9056                        
9057                        var marker = new google.maps.Marker(arrow_options);
9058
9059                        /* Disabled this block - enable for info bubbles
9060                            google.maps.event.addListener(marker, 'click', function() {
9061                                infoBubble.close();
9062                                infoBubble.setContent(html);
9063                                infoBubble.open(map, this);
9064                                currentMark = this;
9065                                //////// this.setIcon(icon_active);  
9066                            });
9067                        */
9068                        
9069                        //////// google.maps.event.addListener(infoBubble,'closeclick',function(){
9070                        ////////   currentMark.setIcon(icon);  
9071                        //////// });
9072
9073                        // Increase the bounds to this marker
9074                        var bounds_loc = new google.maps.LatLng(marker.position.lat(), marker.position.lng());
9075                        bounds.extend(bounds_loc);
9076                    }
9077                    
9078                    
9079                    $('.map-marker').each(function() {
9080                        var lat = $(this).attr('data-lat');
9081                        var long = $(this).attr('data-long');
9082                        var html = $(this).find('.infowindow').html();
9083                        var text_label = $(this).attr('data-label');
9084                        
9085                        var label_obj = '';
9086                        if ($(this).hasClass('map-marker-landmark')) {
9087                            
9088                            var icon = icon_landmark;
9089                            
9090                            ///Only show labels on landmarks
9091                            var label_obj = {
9092                                text: text_label,
9093                                color: "white",
9094                                fontWeight: "bold",
9095                                fontSize: "14px"
9096                            }
9097                            
9098                        } else {
9099                            
9100                            var icon = icon_inactive;
9101
9102                        }
9103                        
9104                        placeMarker(icon, lat,long,html,label_obj);
9105                    });
9106                
9107                    //Set mimimum zoom as the bounds function tends to zoom in as tightly as possible - zooms too much
9108                    google.maps.event.addListenerOnce(map, 'bounds_changed', function(event) {
9109                        this.setZoom(map.getZoom()-1);
9110                        if (this.getZoom() > 18) {
9111                            this.setZoom(18);
9112                        }
9113                    });
9114                    map.fitBounds(bounds);
9115                    map.panToBounds(bounds); 
9116                    
9117                    
9118                }
9119        	},
9120        	extended_click_area: function() {
9121        	    
9122        	    $(".extended_click_area:not(.click_event_added)").addClass('click_event_added').click(function(){
9123        	        
9124                    var link_element = $(this).closest('.item, .slide, .sc_cell_item').find('a');
9125                    if (link_element.length) {
9126                        link_element[0].click();
9127                    } else {
9128                        $(this).removeClass('extended_click_area');
9129                    }
9130                });
9131        	},
9132        	fancybox_image_popup: function() {
9133        	    
9134        	    
9135        	    
9136        	    if ($(".flow_list_formatted a.fancybox_group_image").length || $("a.fancybox_group_image.main_artwork_image_link").length || $("a.fancybox_group_image.slider_image_popup").length) {
9137        	    
9138        	        
9139        	        
9140            	    var fancybox_options = {
9141                        overlayShow: true,
9142                        imageScale: 'true',
9143                        zoomOpacity: 'true',
9144                        prevEffect: 'fade',
9145                        nextEffect: 'fade',
9146                        closeEffect: 'fade',
9147                        openEffect: 'fade',
9148                        padding: 0,
9149                        margin: 0,
9150                        nextEasing: 'easeInOutQuad',
9151                        prevEasing: 'easeInOutQuad',
9152                        nextEffect: 'none',
9153                        afterLoad : function() {
9154                            
9155                            
9156                            if (!$('.fancybox-overlay .fancybox-caption-area-custom').length) {
9157                                
9158                                
9159                                $('.fancybox-overlay').append('<div class="fancybox-caption-area-custom"><div class="fancybox-caption-custom-wrapper col-2"><div class="fancybox-caption-custom image_caption"></div></div></div>')
9160                            } else {
9161                            
9162                                // Add pager stats and update them on each slide change
9163                                var fancybox_page_stats = (this.index + 1) + '/' + this.group.length + (this.title ? ' - ' + this.title : '');
9164                                var percentage_progress = (((this.index + 1) / this.group.length) * 100) + '%'
9165                                if (!$('.fancybox-overlay .fancybox-page-stats').length) {
9166                                    $('.fancybox-overlay').append('<div class="fancybox-page-stats"><div class="progress-bar"><div class="progress-bar-line" style="width:' + percentage_progress + ';"></div></div><div class="progress-bar-text">' + fancybox_page_stats +  '</div></div>');
9167                                } else if ($('.fancybox-overlay .fancybox-page-stats').length) {
9168                                    $('.fancybox-overlay .fancybox-page-stats .progress-bar-line').width(percentage_progress);
9169                                    $('.fancybox-overlay .fancybox-page-stats .progress-bar-text').text(fancybox_page_stats);
9170                                }
9171                            }
9172                 
9173                        },
9174                        beforeShow : function() {
9175                            // Fade in the image once it is loaded
9176                            var elem = $('.fancybox-tmp img');
9177                            elem.css('opacity', '0');
9178                            if (!elem.prop('complete')) {
9179                                // Not loaded yet loaded
9180                                elem.on('load', function() {
9181                                    elem.css('opacity', '1');
9182                                });
9183                            } else {
9184                                // Already loaded
9185                                elem.css('opacity', '1');
9186                            }
9187                            
9188                            
9189                            // console.log($(this.element).attr('data-sli
9189de-fancybox-caption'));
9190                            
9191                            if ($(this.element).attr('data-slide-fancybox-caption') && typeof $(this.element).attr('data-slide-fancybox-caption') != 'undefined') {
9192                                $('.fancybox-page-stats').hide();
9193                                $(".fancybox-caption-area-custom").css('opacity', '1');
9194                                
9195                                var cap = $(this.element).attr('data-slide-fancybox-caption');
9196                                
9197                                
9198
9199                                $(".fancybox-caption-custom").html(cap); 
9200                                 window.site.layout.max_height_read_more('.fancybox-caption-custom', 3, 'Full caption');
9201                            } else {
9202                                $(".fancybox-caption-area-custom").css('opacity', '0');
9203                            }
9204                            
9205                            
9206                            
9207                            // add image alt tag
9208                            var imgAlt = $(this.element).parent().find("img").attr("alt");
9209                            if (imgAlt && typeof imgAlt != 'undefined') {
9210                                $(".fancybox-image").attr("alt", imgAlt);
9211                            }
9212                            
9213                            
9214                        },
9215                        afterShow : function() {
9216                            // Add class to show and hide the fancybox progress bar when you hover on the next and previous buttons (desktop only)
9217                            $('.device-desktop .fancybox-overlay .fancybox-nav').off("mouseover.fancyboxPagination").on("mouseover.fancyboxPagination", function() {
9218                                $(".fancybox-overlay").addClass('fancybox-nav-hovered');
9219                            });
9220                            $('.device-desktop .fancybox-overlay .fancybox-nav').off("mouseout.fancyboxPagination").on("mouseout.fancyboxPagination", function() {
9221                                $(".fancybox-overlay").removeClass('fancybox-nav-hovered');
9222                            });
9223                        }
9224                    }
9225                    
9226                	// Ensure the rel attribute is added to group the images as it can be removed by the external link code
9227                	$(".flow_list_formatted a.fancybox_group_image, a.fancybox_group_image.main_artwork_image_link, a.fancybox_group_image.slider_image_popup").attr('rel', 'fancybox_group');
9228                	// Initialise fancybox
9229                	$(".flow_list_formatted a.fancybox_group_image, a.fancybox_group_image.main_artwork_image_link, a.fancybox_group_image.slider_image_popup").fancybox(fancybox_options);
9230                	
9231                	// Add click event to trigger click on hidden link for main artwork image.
9232                	// Had to be hidden like this so it didn't break view on a wall
9233                	$(".artwork_detail_main .main_artwork_image").unbind('click.main_artwork_image_click').bind('click.main_artwork_image_click', function() {
9234                	    $(".main_artwork_image_link").click();
9235                	});
9236        	    }
9237        	}
9238
9239        },
9240        
9241        filters: {
9242            
9243            init: function() {
9244                
9245                window.site.filters.clear_filters();
9246                
9247                $('.filters_button .filters_reveal_button button, .filter-close-button').unbind().click(function() {
9248                    var filter_options_element = $(this).closest('.filters_button').attr('data-filter-options');
9249                	$('#container_outer').removeClass('scrolling-down scrolling-up');
9250                    $('body').addClass('active-init');
9251                    window.setTimeout(function() {
9252                        if (typeof nav_close_timeout1 != 'undefined') {
9253                            clearTimeout(nav_close_timeout1);
9254                        }
9255                        if ($('.filter-overlay').hasClass('active')) {
9256                            
9257                            nav_close_timeout1 = setTimeout(function() {
9258                                $('body').removeClass('active-init');
9259                            }, 600);
9260                            $('.filter-overlay .overlay-bg').removeClass('open');
9261                            $('.filter-overlay').removeClass('active');
9262                            $('body, html').removeClass('overlay-open filter-overlay-open');
9263
9264                            $(".filter-wrapper.visible").removeClass('visible');
9265                            
9266                            if (filter_opener_element_id != '') {
9267                                var filter_opener = $('[data-filter-options="' + filter_opener_element_id + '"]');
9268                                if (filter_opener.length) {
9269                                    var element_id = filter_opener.attr('id');
9270                                    h.accessibility.on_popup_closing('#' + element_id + ' button');
9271                                }
9272                            }
9273                        } else {
9274                            
9275                            var filters_html = '';
9276                            filter_opener_element_id = '';
9277                            if (typeof filter_options_element != 'undefined') {
9278                                if ($('#' + filter_options_element).length) {
9279                                    filters_html = $('#' + filter_options_element).html();
9280                                    filter_opener_element_id = filter_options_element;
9281                                }
9282                            }
9283                            
9284                            if (filters_html) {
9285                                if (!$('.filter-wrapper').hasClass('initialised')) {
9286                                    $('.filter-wrapper').addClass('initialised').html(filters_html);
9287                                    $('.filter-wrapper [id^="placeholder_"]').each(function() {
9288                                        $(this).attr('id', $(this).attr('id').replace('placeholder_', ''));
9289                                    }).promise().done(function() {
9290                                        window.site.filters.setup();
9291                                    });
9292                                }
9293                                
9294                                $('.filter-overlay .overlay-bg').addClass('open');
9295                                $('.filter-overlay').addClass('active');
9296                                $('body, html').addClass('overlay-open filter-overlay-open');
9297    
9298                                setTimeout(function() {
9299                                    $(".filter-wrapper").addClass('visible');
9300                                    $("#filterpanel_form_wrapper .inview_element").addClass('visible');
9301                                }, 400);
9302    
9303                                h.accessibility.on_popup_opening('.filter-overlay', '.filter-close-button', '.filter-close-button');
9304                            
9305                            }
9306                        }
9307                    }, 50, filter_options_element);
9308
9309                });
9310                
9311            },
9312            
9313            setup: function() {
9314                
9315                window.site.filters.checked_items();
9316                window.site.filters.clear_filters();
9317                window.site.filters.responsive_filter_btn();
9318                // Responsive show/hide filter menu handler
9319                $('.artwork-filter-responsive-btn').on('click', function(e){
9320                    $('#artwork-filter-panel').toggleClass('show')
9321                });
9322                
9323                // Stop enter key from submitting the form and make it trigger checkbox change instead
9324                $('#filterpanel_form input').off().on('keydown', function (e) {
9325                    var keyCode = e.which;
9326                    if ($("this:focus") && (keyCode == 13)) {
9327                        e.preventDefault();
9328                        if ($(this).attr('checked')) {
9329                            $(this).attr('checked', false);
9330                            $(this).trigger("change");
9331                        } else {
9332                            $(this).attr('checked', true);
9333                            $(this).trigger("change");
9334                        }
9335                        return false;
9336                    }
9337                });
9338                
9339                $('#filterpanel_form .fp-checkbox-item a').on('keydown', function (e) {
9340                    if ((e.type == "keydown" && e.which == 13)){
9341                        $(this).closest('.fp-module').removeClass('open').find('.fp-module-button').attr("aria-expanded", "false");e.preventDefault();
9342                        
9343                        var checkbox = $(this).find('input[type="checkbox"]');
9344                        
9345                        if (checkbox.is(':checked')) {
9346                            checkbox.attr('checked', false);
9347                            checkbox.trigger("change");
9348                        } else {
9349                            checkbox.attr('checked', true);
9350                            checkbox.trigger("change");
9351                        }
9352                        return false;
9353                    }
9354                });
9355                
9356                // Submit button
9357                $('#filterpanel_form .fp-module-button-submit').off().on('click', function (e) {
9358                    window.site.filters.checked_items();
9359                    window.site.filters.processUniqueOptionCheckbox($(this));
9360                    window.site.filters.load_works();
9361                    $('.filter-close-button').trigger('click');
9362                });
9363              
9364                // Individual filter item click handler
9365                if ($('#filterpanel_form').hasClass('auto-submit')) {
9366                    $('#filterpanel_form input[type="checkbox"]').on('change', function(e){
9367                        window.site.filters.checked_items();
9368                        window.site.filters.processUniqueOptionCheckbox($(this));
9369                        window.site.filters.load_works();
9370                    });
9371                }
9372                
9373                $('#filterpanel_form label').on('click', function(e) {
9374                    // Prevents a bug where the checkbox click event was triggered twice.
9375                    e.stopPropagation();
9376                });
9377                
9378                $('#filterpanel_form .fp-module.fp-module--keyword input[type="text"]')
9379                    .keydown(function(e) {
9380                        if(e.type == "keydown"){
9381                            if ($("this:focus") && (e.which == 13)) {
9382                                window.site.filters.checked_items();
9383                                window.site.filters.processUniqueOptionCheckbox($(this));
9384                                window.site.filters.load_works();
9385                                $('.filter-close-button').trigger('click');
9386                            }
9387                        }
9388                    })
9389                    .each(function() {
9390                        if ($(this).val() != $(this).attr('data-default-value')) {
9391                            $(this).addClass('active');
9392                            $(this).closest('.fp-module').addClass('active');
9393                        }
9394                    })
9395                    .focus(function() {
9396                        if ($(this).val() == $(this).attr('data-default-value')) {
9397                            $(this).addClass('active').val('');
9398                            $(this).closest('.fp-module').addClass('active');
9399                        }
9400                    })
9401                    .blur(function() {
9402                        if ($(this).val() == '') {
9403                            $(this).removeClass('active').val($(this).attr('data-default-value'));
9404                            $(this).closest('.fp-module').removeClass('active');
9405                        }
9406                    })
9407                ;
9408                
9409                // Accessibility functions -------------------------- //
9410                
9411                $('.fp-module button').keydown(filter_handler);
9412                $('.fp-module button').click(filter_handler);
9413                
9414                function filter_handler(e){
9415                    var dropdown_type = '.fp-module--' + $(this).attr("data-dropdown");
9416                    if(e.type == "keydown"){
9417                    
9418                        var keyCode = e.which;
9419                        if ($("this:focus") && (keyCode == 13 || keyCode == 32)) {
9420                            $('.fp-module').not(dropdown_type).removeClass('open');
9421                            if ($(dropdown_type).hasClass('open')) {
9422                                $(this).attr("aria-expanded", "false");
9423                                $(dropdown_type).removeClass('open');
9424                            } else {
9425                                $(this).attr("aria-expanded", "true");
9426                                $(dropdown_type).addClass("open");
9427                            }
9428                        } else if ($("this:focus") && (keyCode == 9 && e.shiftKey) && $(dropdown_type).hasClass('open')) {
9429                            $(this).attr("aria-expanded", "false");
9430                            $(dropdown_type).removeClass('open');
9431                        }
9432                        
9433                    } else if(e.type == "click") {
9434                        var $fpmodule = $(this).closest('.fp-module');
9435                        $('.fp-module').not(dropdown_type).removeClass('open');
9436                        if ($('.fp-module').hasClass('open')) {
9437                            $(this).attr("aria-expanded", "false");
9438                            $('.fp-module').removeClass('open');
9439                        } else {
9440                            if (e.type != "blur") {
9441                                $('.fp-module').removeClass('open');
9442                                $(this).attr("aria-expanded", "true");
9443                                $fpmodule.addClass("open");
9444                            }
9445                        }
9446                    }
9447                }
9448                
9449                function closeFilterDropdown(dropdown_name) {
9450                    $('.fp-module--' + dropdown_name).removeClass("open");
9451                    $('.fp-module--' + dropdown_name + ' button').attr("aria-expanded", "false");
9452                }
9453                
9454                // Close dropdown menu if tab focus goes off dropdown menu
9455                $('.filters_panel .fp-module-content a').on('keydown', function (e) {
9456                    var keyCode = e.which;
9457                    if ($(this).closest('li').is(':first-child') && (keyCode == 9 && e.shiftKey)) {
9458                        closeFilterDropdown($(this).closest('.fp-module').find('.fp-module-button').attr("data-dropdown"));
9459                    } else if ($(this).closest('li').is(':last-child') && (keyCode == 9 && !e.shiftKey)) {
9460                        closeFilterDropdown($(this).closest('.fp-module').find('.fp-module-button').attr("data-dropdown"));
9461                    } else if ($("this:focus") && (keyCode == 27)) {
9462                        closeFilterDropdown( $(this).closest('.fp-module').find('.fp-module-button').attr("data-dropdown"));
9463                        $(this).closest('.fp-module').find('.fp-module-button').focus();
9464                    }
9465                });
9466                
9467                // Close keyword dropdown menu if tab focus goes off input
9468                $('.filters_panel .fp-module--keyword input').on('keydown', function (e) {
9469                    var keyCode = e.which;
9470                    if ($("this:focus") && (keyCode == 9)) {
9471                        var dropdown_name = $(this).attr("data-dropdown")
9472                        $('.fp-module--keyword').removeClass("open");
9473                        $('.fp-module--keyword button').attr("aria-expanded", "false");
9474                    }
9475                });
9476            },
9477            
9478            checked_items: function(){
9479                
9480                $('#filterpanel_form .fp-module').each(function(){
9481                    var checked_count = $(this).find('input:checked').length;
9482                    if(checked_count > 0) {
9483                        $(this).find('.group-count').html('('+ String(checked_count) + ')');
9484                    } else {
9485                        $(this).find('.group-count').html('');
9486                    }
9487                });
9488                
9489            },
9490            
9491            processUniqueOptionCheckbox: function(instance) {
9492                if (instance && instance.length) {
9493                    if (instance.closest('.unique-option-parent').length) {
9494                        instance.closest('.unique-option-parent').find('input').not(instance).prop('checked', false);
9495                    }
9496                }
9497            },
9498            
9499            processRangeCheckbox: function(){
9500                /**
9501                 * This function requires: data-min and data-max to be set on the checkbox input and 2 hidden inputs, .range_min and .range_max to be added as children of .range_parent. The hidden inputs need to be disabled by default.
9502                 * For all the selected checkboxes find the data-min and data-max values(which should be set on the input element). 
9503                 * Assign the min/max values to relevant array selectedMins/selectedMaxs and then use the ARRAY.sort() func to order them in ascending order.
9504                 * Set the min value as the FIRST item in the sorted selectedMins array. Set the max value as the LAST item in the selectedMaxs array.
9505                 * Assign these to the hidden inputs so they are passed when the form is serialized/submitted.
9506                 */
9507                $('.range-parent').each(function(){
9508                    var selectedRanges = $(this).find('input:checked');
9509                    
9510                    if(!selectedRanges.length){ 
9511                        $(this).find('.range_min, .range_max').attr('disabled', true); // Disable the min and max fields so the empty values aren't sent when the form is submitted.
9512                        return; // Don't bother to process if there aren't any checked checkboxes
9513                    } 
9514                    
9515                    // Remove the disabled attribute for the min and max inputs as a checkbox is selected
9516                    $(this).find('.range_min, .range_max').removeAttr('disabled');
9517                    
9518                    var parent = $(this).closest('.range-parent');
9519                    var selectedMins = [];
9520                    var selectedMaxs = [];
9521                    for (var i = 0; i < selectedRanges.length; i++) {
9522                        selectedMins.push(parseInt( ($(selectedRanges[i]).data('min') || 0) ));
9523                        selectedMaxs.push(parseInt( ($(selectedRanges[i]).data('max') || 100000000) ));
9524                    }
9525                    // Order the min and max arrays in ascending order
9526                    var selectedMinsSorted = selectedMins.sort(function(a,b){return a-b}); // By default the sort is alphabetical, the weird callback function forces it to sort numerically.
9527                    var selectedMaxsSorted = selectedMaxs.sort(function(a,b){return a-b}); // By default the sort is alphabetical, the weird callback function forces it to sort numerically.
9528                    
9529                    var minValue = selectedMinsSorted[0];
9530                    var maxValue = selectedMaxsSorted[selectedMaxsSorted.length - 1]; // the last item
9531                    
9532                    // Update the hidden inputs with the corresponding values
9533                    $(this).find('.range_min').val(minValue);
9534                    $(this).find('.range_max').val(maxValue);
9535                });  
9536            },
9537            
9538            load_works: function($filterPanelForm) {
9539                /**
9540                 * Serializes and submits the form.
9541                 * The result will be loaded into the inner_content_selector element.
9542                 */
9543                 
9544                if(typeof $filterPanelForm == 'undefined') {
9545                    if ($('#filterpanel_form').length) {
9546                        $filterPanelForm = $('#filterpanel_form');
9547                    } else {
9548                        $filterPanelForm = $('#placeholder_filterpanel_form');
9549                    }
9550                }
9551                
9552                $filterPanelForm.addClass('filter-results-loaded');
9553                $('.filters_button').addClass('filter-results-loaded');
9554                
9555                var pathToSubmitForm = $filterPanelForm.attr('action');
9556                if (pathToSubmitForm){
9557                    window.site.filters.processRangeCheckbox();
9558                    window.site.filters.processUniqueOptionCheckbox();
9559                    
9560                    if ($filterPanelForm.find('#filter_keyword').val() == $filterPanelForm.find('#filter_keyword').attr('data-default-value')) {
9561                        $filterPanelForm.find('#filter_keyword').attr('disabled', 'disabled');
9562                    }
9563                    
9564                    var serializedForm = $filterPanelForm.serialize();
9565                    
9566                    if(serializedForm.length){
9567                        var updated_url = pathToSubmitForm + '?filter=1&' + serializedForm;
9568                    } else {
9569                        var updated_url = pathToSubmitForm
9570                    }
9571                    
9572                    $filterPanelForm.find('#filter_keyword').removeAttr('disabled');
9573
9574                }   
9575                
9576                var incoming_content_type = 'inner';
9577                
9578                $.pageload.load(updated_url, false, function(new_page_inner_content, element_href, new_page_main_content) {
9579                    if (new_page_inner_content) {
9580                        $('.filter_results')
9581                            .addClass('filter_transition')
9582                            .delay(400)
9583                            .queue(function() {
9584                                
9585                                var filters_active = (updated_url.indexOf('filter=') > -1);
9586    
9587                                history.replaceState({'ajaxPageLoad': true}, null, updated_url);
9588                                
9589                                if ($('.filter_results').closest('.panel_filter_results_pending').length) {
9590                                    if (filters_active) {
9591                                        $('.filter_results').closest('.panel_filter_results_pending').closest('.scroll_section_panels').addClass('panel_filters_active');
9592                                        $('.filter_results').closest('.panel_filter_results_pending').addClass('panel_filter_results_active');
9593                                    } else {
9594                                        $('.filter_results').closest('.panel_filter_results_pending').closest('.scroll_section_panels').removeClass('panel_filters_active');
9595                                        $('.filter_results').closest('.panel_filter_results_pending').removeClass('panel_filter_results_active');
9596                                    }
9597                                } else {
9598                                    $('.section-store .filter_results').closest('section').find('.panel_heading_inner h2').text('Results');
9599                                    $('.filter_results').closest('.scroll_section_panels').addClass('panel_filters_active');
9600                                }
9601                                
9602                                if (!filters_active && $('body').hasClass('section-store')) {
9603                                    $('.section-store .filter_results').closest('section').find('.panel_heading_inner h2').text('All categories');
9604                                }
9605                                
9606                                var new_scroll_position = $('.filter_results').offset().top - 240;
9607                                $('html,body').animate(
9608                                    {scrollTop: new_scroll_position},
9609                                    1200,
9610                                    'easeInOutExpo'
9611                                );
9612                                
9613                                var full_html = $(new_page_main_content);
9614                                var results_html = full_html.find('.filter_results').html();
9615                                var footer_html = full_html.find('.panel_footer').length ? '<div class="panel_footer inview_element animate-from-bottom">' + full_html.find('.panel_footer').html() + '</div>' : '';
9616                                var pagestats_id = full_html.find('.filter_results').attr('data-pagestats-id');
9617                                
9618                                $('.filter_results').html(results_html).attr('data-pagestats-id', pagestats_id);
9619                                $('.filter_results').removeClass('filter_transition');
9620                                
9621                                $('.filter_results').parent().find('.panel_footer').remove();
9622                                $('.filter_results').parent().append(footer_html);
9623                                window.site.pageload.load_more_pagination.setup();
9624                                
9625                                window.cart.init();
9626                                window.site.misc.init();
9627                                window.site.enquiry.init();
9628                                window.site.overlays.enquire.init(
9628);
9629                                window.site.layout.grids.init();
9630                                window.site.lazy_load.setup();
9631                                window.site.artlogic_inview.init();
9632                                window.site.misc.extended_click_area();
9633                                
9634                                $(window).trigger('resize');
9635                                $.pageload.refresh();
9636                                
9637                                
9638                                $(this).dequeue();
9639                            })
9640                        ;
9641                    }
9642                }, null, null, null, incoming_content_type);
9643 
9644            },
9645            
9646            clear_filters: function(){
9647                
9648                $('.clear_filters').unbind().on('click', function(e){
9649                    e.preventDefault();
9650                    if ($('#filterpanel_form').length) {
9651                        $('#filterpanel_form input').prop('checked', false);
9652                        $('#filterpanel_form input[type="text"]').val('').trigger('blur');
9653                        $('#filterpanel_form').find('.group-count').html('');
9654                        window.site.filters.load_works();
9655                        if ($('.filter-overlay').hasClass('active')) {
9656                            $('.filter-close-button').trigger('click');
9657                        }
9658                    } else {
9659                        $('#placeholder_filterpanel_form input').prop('checked', false);
9660                        $('#placeholder_filterpanel_form input[type="text"]').val('');
9661                        $('#placeholder_filterpanel_form').find('.group-count').html('');
9662                        window.site.filters.load_works();
9663                    }
9664                    $('#filterpanel_form, .filters_button').removeClass('filter-results-loaded');
9665                });
9666                
9667            },
9668            
9669            responsive_filter_btn: function() {
9670                
9671                $('.artwork-filter-open-btn').on('click', function() {
9672                    // console.log('open responsive');
9673                    if($('#filterpanel_form').hasClass('open')){
9674                        $('#filterpanel_form').removeClass('open');
9675                        $('#filterpanel_form').attr('style','')
9676                    } else {
9677                        $('#filterpanel_form').addClass('open');
9678                        window.site.helpers.animate_height($('#filterpanel_form'));
9679                    }
9680                });
9681                
9682            }
9683            
9684        },
9685
9686
9687        device: {
9688
9689            init: function() {
9690
9691                // Find out the current browser
9692                if ($.browser.name) {
9693                    var browserVersion = parseInt($.browser.version);
9694                    var browserName = $.browser.name;
9695                    if (browserVersion) {
9696                        $('body').addClass('browser-' + browserName);
9697                        $('body').addClass('browser-' + browserName + '-' + browserVersion);
9698                    }
9699                    if ($.browser.platform) {
9700                        $('body').addClass('platform-' + $.browser.platform);
9701                    }
9702                }
9703
9704                // Find out if this is the Android default browser and add a class to the body
9705                // This is NOT a very good way of testing for this browser, but there does not seem to be a conclusive way to do it
9706                var nua = navigator.userAgent;
9707                var is_android_default_browser = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
9708                if (is_android_default_browser) {
9709                    $('body').addClass('browser-android-internet');
9710                }
9711
9712                // Find outo if this is a high res device and add a class to the body
9713                // This allows us to change graphics to high-res versions on compatible devices
9714                if (window.devicePixelRatio > 1) {
9715                    $('body').addClass('device-highres');
9716                }
9717
9718                if (window.site.device.handheld()) {
9719                    $('body').addClass('device-handheld');
9720                } else {
9721                    $('body').addClass('device-desktop');
9722                }
9723
9724                if (window.site.device.handheld_ios()) {
9725                    $('body').addClass('device-handheld-ios');
9726                }
9727
9728            },
9729
9730            breakpoint: function() {
9731                if ($(window).width() <= 459) {
9732                    return 1;
9733                } else if ($(window).width() <= 767) {
9734                    return 2;
9735                } else if ($(window).width() <= 900) {
9736                    return 2.5;
9737                } else if ($(window).width() <= 1023) {
9738                    return 3;
9739                } else {
9740                    return 4;
9741                }
9742            },
9743
9744            canvas_enabled: function() {
9745                // Check if canvas should be enabled
9746                if (window.location.search.indexOf("canvasdisabled=1") != -1 || !window.site.home.canvas_effect_enabled) {
9747                    return false;
9748                }
9749                return window.site.device.video_mode() && window.site.device.video_inline() && window.site.device.breakpoint() > 2;
9750            },
9751
9752            video_fallback: function() {
9753                // Does this device run in video fallback mode, e.g. usually non desktop devices
9754                return window.site.device.handheld() || !window.site.device.video_inline();
9755            },
9756
9757            video_mode: function() {
9758                // Do we want to show video on this device
9759                return window.site.device.video_inline();
9760            },
9761
9762            video_inline: function() {
9763                // Check if video content can be displayed inline (e.g. as a background physically on the page)
9764                if (window.location.search.indexOf("disablevideoinline=1") != -1) {
9765                	return false;
9766                }
9767                return navigator.userAgent.match(/(iPhone|iPod)/g) ? ('playsInline' in document.createElement('video')) : true;
9768            },
9769
9770            handheld: function() {
9771
9772                /* Detect mobile device */
9773                return (
9774                    //Uncomment to force for testing
9775                    //true ||
9776
9777                    //Dev mode
9778                    (window.location.search.indexOf("handheld=1") != -1) ||
9779                    //Detect iPhone
9780                    (navigator.platform.indexOf("iPhone") != -1) ||
9781                    //Detect iPod
9782                    (navigator.platform.indexOf("iPod") != -1) ||
9783                    //Detect iPad
9784                    (navigator.platform.indexOf("iPad") != -1) ||
9785                    //Detect iPad ios 13+
9786                    (navigator.platform.indexOf("MacIntel") != -1 && navigator.maxTouchPoints > 1) ||
9787                    //Detect Android
9788                    (navigator.userAgent.toLowerCase().indexOf("android") != -1) ||
9789                    //Detect Surface (ARM chip version e.g. low powered tablets) will also detect other windows tablets with the same chip
9790                    (navigator.userAgent.toLowerCase().indexOf("arm;") != -1 && navigator.userAgent.toLowerCase().indexOf("windows nt") != -1) ||
9791                    //Detect Opera Mini
9792                    (navigator.userAgent.toLowerCase().indexOf("opera mini") != -1) ||
9793                    //Detect Blackberry
9794                    (navigator.userAgent.toLowerCase().indexOf("blackberry") != -1) ||
9795                    //Detect webos
9796                    (navigator.userAgent.toLowerCase().indexOf("webos") != -1) ||
9797                    //Detect iemobile (old version of windows phone)
9798                    (navigator.userAgent.toLowerCase().indexOf("iemobile") != -1)
9799                );
9800
9801            },
9802
9803            handheld_not_ios: function() {
9804
9805                /* Detect mobile device */
9806                ios_devices = (
9807                    (navigator.platform.indexOf("iPhone") != -1) ||
9808                    //Detect iPod
9809                    (navigator.platform.indexOf("iPod") != -1) ||
9810                    //Detect iPad
9811                    (navigator.platform.indexOf("iPad") != -1) ||
9812                    //Detect iPad ios 13+
9813                    (navigator.platform.indexOf("MacIntel") != -1 && navigator.maxTouchPoints > 1)
9814                );
9815
9816                if (window.site.device.handheld() && !ios_devices) {
9817                	return true;
9818                } else {
9819                	return false;
9820                }
9821
9822            },
9823            
9824            handheld_ios: function() {
9825
9826                /* Detect mobile device */
9827                ios_devices = (
9828                    (window.location.search.indexOf("handheldios=1") != -1) ||
9829                    
9830                    (navigator.platform.indexOf("iPhone") != -1) ||
9831                    //Detect iPod
9832                    (navigator.platform.indexOf("iPod") != -1) ||
9833                    //Detect iPad
9834                    (navigator.platform.indexOf("iPad") != -1) ||
9835                    //Detect iPad ios 13+
9836                    (navigator.platform.indexOf("MacIntel") != -1 && navigator.maxTouchPoints > 1)
9837                );
9838
9839                if (window.site.device.handheld() && ios_devices) {
9840                	return true;
9841                } else {
9842                	return false;
9843                }
9844
9845            }
9846        },
9847
9848        throttle: function(delay, callback) {
9849            var previousCall = new Date().getTime();
9850            return function() {
9851                var time = new Date().getTime();
9852                if ((time - previousCall) >= delay) {
9853                    previousCall = time;
9854                    callback.apply(null, arguments);
9855                }
9856            };
9857        },
9858
9859        debounce: function(wait, func, immediate) {
9860            var timeout;
9861            return function() {
9862                var context = this, args = arguments;
9863                var later = function() {
9864                    timeout = null;
9865                    if (!immediate) func.apply(context, args);
9866                };
9867                var callNow = immediate && !timeout;
9868                clearTimeout(timeout);
9869                timeout = setTimeout(later, wait);
9870                if (callNow) func.apply(context, args);
9871            };
9872        },
9873        
9874        objectfit_polyfill: {
9875            /*
9876                Simple polyfill for image grids that use object-fit css for 'soft' cropping.
9877                Mostly required for all versions of Internet Explorer and older versions of Edge.
9878            */
9879            init: function() {
9880                
9881                var polyfill_images = '#hero .media_wrapper .image_media img, .splash-container #splash_images img, .hero_inner .media_wrapper .image img, .artwork-nav-hero img';
9882                
9883                if ($(polyfill_images).length){
9884                    
9885                    var supportsObjectfit;
9886                    
9887                    // Detect whether '@supports' CSS is supported, preventing errors in IE
9888                    var supports_supportsCSS = !!((window.CSS && window.CSS.supports) || window.supportsCSS || false);
9889
9890                    if (supports_supportsCSS){
9891                        // Older Edge supports '@supports' but not object-fit
9892                        supportsObjectfit = CSS.supports('object-fit','cover');
9893                    } else {
9894                        //IE doesn't support '@supports' or 'object-fit', so we can consider them the same
9895                        supportsObjectfit = false;
9896                    }
9897
9898                    if (!supportsObjectfit || typeof supportsObjectfit == 'undefined') {
9899    
9900                        $(polyfill_images).each(function() {
9901                            var $img = $(this);
9902                            var imageURL = false;
9903                            if ($img.attr('src') && typeof $img.attr('src') != 'undefined') {
9904                                var imageURL = $img.attr('src');
9905                            } else if ($img.attr('data-src') && typeof $img.attr('data-src') != 'undefined') {
9906                                var imageURL = $img.attr('data-src');
9907                            }
9908                            if (imageURL) {
9909                                var bg_positioning = '50% 50%';
9910                                if ($img.css('object-position')) {
9911                                    var positioning = $img.css('object-position');
9912                                }
9913                                $img.parent().addClass('objectfit-fallback-bg').css({'background-image':'url('+imageURL+')','background-position':bg_positioning});
9914                                $img.css('visibility','hidden');
9915                                
9916                                if (!$('body').hasClass('objectfit-polyfill-active')){
9917                                    $('body').addClass('objectfit-polyfill-active')
9918                                }
9919                            }
9920                        });
9921                    }
9922                }
9923            },
9924        },
9925        
9926        interactive_scroller: {
9927            
9928            init: function() {
9929            
9930                var device_supported = (
9931                    (
9932                        ($.browser.chrome && $.browser.versionNumber >= 75) 
9933                        ||
9934                        ($.browser.safari && $.browser.versionNumber >= 10)
9935                        ||
9936                        ($.browser.mozilla && $.browser.versionNumber >= 75)
9937                    ) 
9938                    && 
9939                    (
9940                        !window.site.device.handheld()
9941                        ||
9942                        $.browser.safari && $.browser.versionNumber >= 10
9943                    )
9944                );
9945                
9946                if (device_supported) {
9947                        
9948                    html = document.documentElement;
9949                	loopcount = 0;
9950                	
9951                	video_settings = {
9952                		'instances': {}
9953                	};
9954                	
9955                	function currentFrame(index) {
9956        			  return "scroll-images/".concat(index.toString().padStart(4, '0'), ".jpg");
9957        			};
9958        
9959        			function updateImage(index) {
9960        				context.drawImage(images[index], 0, 0);
9961        			};
9962        			
9963        			setTimeout(function() {
9964        				$('.video-wrapper').each(function() {
9965        				    $(this).addClass('loading');
9966
9967        					loopcount = loopcount + 1;
9968        					var element_id = 'scrollplay-' + loopcount;
9969        					$(this).attr('id', element_id);
9970        				
9971        					canvas = $(this).find('canvas')[0];
9972        					canvas.width=1920;
9973        					canvas.height=1080;
9974        				
9975        					context = canvas.getContext("2d");
9976        					frames = [];
9977        					frames_list = $(this).find('.video-frames').length ? $(this).find('.video-frames').text() : false;
9978        					frames_folder = $(this).attr('data-frames-folder') && typeof $(this).attr('data-frames-folder') != 'undefined' ? $(this).attr('data-frames-folder') : false;
9979        				
9980        					if (frames_list) {
9981        						frames = JSON.parse(frames_list);
9982        						frame_count = frames.length;
9983        					} else if (frames_folder) {
9984        						frame_count = $(this).attr('data-frame-count') && typeof $(this).attr('data-frame-count') != 'undefined' ? parseInt($(this).attr('data-frame-count')) : false;
9985        						if (frame_count) {
9986        							for (var i = 1; i < frame_count+1; i++) {
9987        								var frame_path = frames_folder.concat(i.toString().padStart(4, '0'), ".jpg");
9988        								frames.push(frame_path);
9989        							};
9990        						}
9991        					}
9992        			
9993        					video_settings['instances'][element_id] = {
9994        						'canvas': canvas,
9995        						'context': context,
9996        						'frame_count': parseInt(frame_count),
9997        						'frames_loaded': 0
9998        					};
9999        				
10000        					if (frames.length) {
10001        					
10002        						// Preload and setup all the images
10003        						images = [];
10004        						for (var i = 0; i < frame_count; i++) {
10005        								(function(images, frames, element_id){
10006        									images[i] = new Image();
10007        									images[i].src = frames[i];
10008        									images[i].onload=function(){
10009        									  video_settings.instances[element_id]['frames_loaded'] = video_settings.instances[element_id]['frames_loaded'] + 1;
10010        									  if (video_settings.instances[element_id]['frames_loaded'] == video_settings.instances[element_id]['frame_count']) {
10011        										$('#' + element_id).addClass('loaded').removeClass('loading');
10012        									  }
10013        									}
10014        								})(images, frames, element_id);
10015        						};
10016        					
10017        						// Load the first image
10018        						(function(context){
10019        							img = new Image()
10020        							img.src = frames[1];
10021        							img.onload=function(){
10022        							  context.drawImage(this, 0, 0);
10023        							}
10024        						})(context);
10025        				
10026        						video_settings['instances'][element_id]['images'] = images;
10027        					
10028        					}
10029        				});
10030        			    
10031        				$(window).on('resize scroll', function(e) {
10032        					$('.video-wrapper').each(function(){
10033        						var element_id = $(this).attr('id');
10034        						var $vid = $(this).find('canvas');
10035        						var $vidwrapper = $(this);
10036        						if ($vidwrapper.hasClass('interaction-active') || e.type == 'resize') {
10037        						
10038            						if ($vidwrapper.hasClass('loaded')) {
10039            							context = video_settings.instances[element_id].context;
10040            							images = video_settings.instances[element_id].images;
10041            							frame_count = video_settings.instances[element_id].frame_count;
10042            					
10043            							var element_offset = $vidwrapper.offset().top;
10044            							var scrollTop = $(window).scrollTop();
10045            							var scroll_amount_relative_to_item = scrollTop - element_offset;
10046            							var pixels_per_frame = 15;
10047            
10048            							calculated_frame = Math.floor(scroll_amount_relative_to_item / pixels_per_frame);
10049            							if (calculated_frame < 1) {
10050            								calculated_frame = 1;
10051            							} else if (calculated_frame >= frame_count) {
10052            								calculated_frame = frame_count - 1;
10053            							}
10054            
10055            							var container_height = (pixels_per_frame * frame_count) + window.innerHeight;
10056            							$vidwrapper.height(container_height);
10057        
10058            							requestAnimationFrame(function() {
10059            								context.drawImage(images[calculated_frame], 0, 0);
10060            							});
10061            						}
10062        						}
10063        				  });
10064        				}).trigger('resize');
10065        			}, 2200);
10066        			
10067        			
10068                    $(window).on('resize scroll', function() {
10069                    
10070                        $('.video').each(function(){
10071                            var $vid = $(this);
10072                            var $vidwrapper = $vid.closest('.video-wrapper');
10073                            if ($vidwrapper.isInViewport().dist_from_top < 1 && $(window).scrollTop() < $vidwrapper.height() + $vidwrapper.offset().top){
10074                                $vidwrapper.addClass('interaction-active');
10075                                $vid.addClass('visible');
10076                            } else {
10077                                $vidwrapper.removeClass('interaction-active');
10078                                $vid.removeClass('visible');
10079                            }
10080                            
10081        			  });
10082        			});
10083                    $('.interactive-scroller').removeClass('fallback-mode');
10084                } else {
10085                    // Device not supported    
10086                    $('.interactive-scroller').addClass('fallback-mode');
10087                }
10088                
10089            }
10090            
10091        },
10092
10093        cookie_notification: {
10094
10095            init: function () {
10096                // console.log('cookie_notification init');
10097                var cookie_settings = {
10098                    time_to_wait: 2000
10099                };
10100                var custom_cookie_settings = $('#cookie_notification').data('cookie-notification-settings') || {};
10101                $.extend(cookie_settings, custom_cookie_settings);
10102
10103                $('#cookie_notification').each(function () {
10104                    mode = 'notify';
10105                    if ($(this).attr('data-mode')){
10106                        mode = $(this).attr('data-mode');
10107                    }
10108                    // console.log('mode', mode);
10109                    if(mode == 'consent'){
10110                        var has_preferences = window.site.cookie_notification.get_cookie_preferences();
10111                        if(!has_preferences){
10112                            // Display the cookie notification after a set amount of time
10113                            setTimeout(function () {
10114                                $('#cookie_notification').addClass('active')
10115                            }, cookie_settings.time_to_wait)
10116
10117                            // Accept btn event listener
10118                            $('#cookie_notification_accept').click(
10119                                window.site.cookie_notification.cookie_consent_accept_btn_callback
10120                            );
10121
10122                            window.site.cookie_notification.manage_cookies_popup.init();
10123                        }
10124                        else {
10125                            $(this).hide();
10126                        }
10127                        
10128                    } else {
10129                        var notification_cookie = h.getCookie('cookie_notification_dismissed');
10130                        if (!notification_cookie) {
10131                            // Display the cookie notification after a set amount of time
10132                            setTimeout(function () {
10133                                $('#cookie_notification').addClass('active')
10134                            }, cookie_settings.time_to_wait)
10135
10136                            // Accept btn event listener
10137                            $('#cookie_notification_accept').click(
10138                                window.site.cookie_notification.cookie_notification_accept_btn_callback
10139                            );
10140
10141                        }
10142                        else {
10143                            $(this).hide();
10144                        }
10145                    }
10146                    
10147                });
10148
10149                
10150            },
10151
10152            cookie_notification_accept_btn_callback: function (e) {
10153                h.setCookie('cookie_notification_dismissed', '1', 365);
10154                /* Display:none the banner once it's transformed off the screen 
10155                    - do this instead of $.hide because it's janky */
10156                $('#cookie_notification').on('transitionend', function (te) {
10157                    if (te.originalEvent.propertyName == 'transform') {
10158                        $('#cookie_notification').hide();
10159                    }
10160                });
10161                $('#cookie_notification').removeClass('active');
10162                e.preventDefault();
10163            },
10164
10165            cookie_consent_accept_btn_callback: function (e) {
10166                
10167                // Set all cookie consent options to true as they have accepted all
10168                var cookie_consent = {
10169                    'essential': true,
10170                    'functionality': true,
10171                    'statistics': true,
10172                    'marketing': true
10173                }
10174                
10175                // h.setCookie('cookie_consent', JSON.stringify(cookie_consent), 365);
10176                window.site.cookie_notification.set_cookie_preferences(
10177                  cookie_consent
10178                );
10179                window.site.cookie_notification.hide_cookie_notification_banner();
10180                e.preventDefault();
10181            },
10182            
10183            hide_cookie_notification_banner: function (e) {
10184                
10185                /* Display:none the banner once it's transformed off the screen 
10186                    - do this instead of $.hide because it's janky */
10187                $('#cookie_notification').on('transitionend', function (te) {
10188                    if (te.originalEvent.propertyName == 'transform') {
10189                        $('#cookie_notification').hide();
10190                    }
10191                });
10192                $('#cookie_notification').removeClass('active');
10193                
10194            },
10195
10196            set_cookie_preferences: function (cookie_preferences) {
10197
10198                if (g.has_local_storage()) {
10199                    today = new Date();
10200                    today = today.toISOString().substr(0, 10);
10201                    cookie_preferences['date'] = today;
10202                    localStorage.setItem(
10203                        "cookie_preferences",
10204                        JSON.stringify(cookie_preferences)
10205                    );
10206                    window.google_analytics_init(location.pathname);
10207                    window.archimedes.archimedes_core.analytics.track_campaigns.init();
10208                }
10209
10210            },
10211
10212            get_cookie_preferences: function(){
10213                result = false;
10214                if(g.has_local_storage()){
10215                    var cookie_preferences = localStorage.getItem('cookie_preferences') || "";
10216                    if (cookie_preferences) {
10217                        cookie_preferences = JSON.parse(cookie_preferences);
10218                        if (cookie_preferences.date) {
10219                            var expires_on = new Date(cookie_preferences.date);
10220                            expires_on.setDate(expires_on.getDate() + 365);
10221                            // console.log('cookie preferences expire on', expires_on.toISOString());
10222                            var valid = expires_on > new Date();
10223                            if (valid){
10224                                result = cookie_preferences;
10225                            }
10226                        }
10227                    }
10228                }
10229                // console.log('cookie preferences', result);
10230                return result;
10231            },
10232
10233            get_cookie_preference: function (category) {
10234                result = false;
10235                try {
10236                    var cookie_preferences = localStorage.getItem('cookie_preferences') || "";
10237                    if (cookie_preferences) {
10238                        cookie_preferences = JSON.parse(cookie_preferences);
10239                        if (cookie_preferences.date) {
10240                            var expires_on = new Date(cookie_preferences.date);
10241                            expires_on.setDate(expires_on.getDate() + 365);
10242                            // console.log('cookie preferences expire on', expires_on.toISOString());
10243                            var valid = expires_on > new Date();
10244                            if (valid && cookie_preferences.hasOwnProperty(category) && cookie_preferences[category]) {
10245                                result = true;
10246                            }
10247                        }
10248                    }
10249                }
10250                catch(e) {
10251                    console.warn('get_cookie_preference() failed');
10252                    return result;
10253                }
10254                // console.log('cookie preference', category, result);
10255                return result;
10256            },
10257
10258            manage_cookies_popup: {
10259
10260                init: function(){
10261
10262                    $('#cookie_notification_preferences').unbind()
10263                        .click(function () {
10264                            window.site.cookie_notification.manage_cookies_popup.open();
10265                        });
10266
10267                    $('#manage_cookie_preferences_close_popup_link a, #manage_cookie_preferences_popup_overlay')
10268                        .unbind()
10269                        .click(function () {
10270                            window.site.cookie_notification.manage_cookies_popup.close(true);
10271                            return false;
10272                        })
10273                        ;
10274
10275
10276                    $('#cookie_preferences_form').submit(function(e){
10277                        e.preventDefault();
10278                        var cookie_consent = {};
10279                        $('input', this).not(':input[type=button], :input[type=submit], :input[type=reset]').each(function(){
10280                            cookie_consent[$(this).attr('name')] = $(this).prop('checked') ? true : false;
10281                        });
10282                        window.site.cookie_notification.set_cookie_preferences(cookie_consent);
10283                        window.site.cookie_notification.manage_cookies_popup.close(false);
10284                    }); 
10285
10286                },
10287
10288                open: function(){
10289                    $('body').addClass('manage_cookie_preferences_popup_active');
10290                    $('#cookie_notification').removeClass('active');
10291                    setTimeout(function () {
10292                        $('body').addClass('manage_cookie_preferences_popup_visible');
10293                        h.accessibility.on_popup_opening($('#manage_cookie_preferences_popup_box'), false, '#manage_cookie_preferences_close_popup_link a');
10294                        window.site.cookie_notification.manage_cookies_popup.after_popup();
10295                    }, 50);
10296                },
10297
10298                close: function(reopen_notification){
10299                    $('body').removeClass('manage_cookie_preferences_popup_visible');
10300                    setTimeout(function () {
10301                        $('body').removeClass('manage_cookie_preferences_popup_active');
10302                        if(reopen_notification){
10303                            $('#cookie_notification').addClass('active');
10304                        }
10305                        else {
10306                            window.site.cookie_notification.hide_cookie_notification_banner();
10307                        }
10308                    }, 400);
10309
10310                    h.accessibility.on_popup_closing();
10311                },
10312
10313                after_popup: function(){
10314
10315                }
10316
10317            }
10318            
10319        },
10320
10321        art_fairs_non_popup: {
10322            init: () => {
10323                if ($('.record_detail_simple:not(.artwork_detail_variant_store_detail) .additional_information').length) {
10324                    window.site.layout.max_height_read_more('.record_detail_simple .additional_information', 9, '+');
10325                }
10326            }
10327        }
10328
10329    };
10330
10331    $(document).ready(function() {
10332
10333        window.site.init();
10334
10335    });
10336
10337
10338})(jQuery);
10339
10340
10341
10342
10343$.fn.isInViewport = function() {
10344    //quick inview plugin
10345    var elementTop = $(this).offset().top;
10346    var elementBottom = elementTop + $(this).outerHeight();
10347    var viewportTop = $(window).scrollTop();
10348    var viewportBottom = viewportTop + $(window).height();
10349    var is_in_viewport = elementBottom > viewportTop && elementTop < viewportBottom;
10350
10351    return {'inview':is_in_viewport, 'dist_from_top': Math.floor(1 - (viewportTop - elementTop)),  'dist_from_bottom': Math.floor(viewportBottom - elementTop)  }
10352};
10353
10354
10355(function( $ ){
10356
10357  'use strict';
10358
10359  $.fn.fitVids = function( options ) {
10360    var settings = {
10361      customSelector: null,
10362      ignore: null
10363    };
10364
10365    if(!document.getElementById('fit-vids-style')) {
10366      // appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js
10367      var head = document.head || document.getElementsByTagName('head')[0];
10368      var css = '.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}';
10369      var div = document.createElement("div");
10370      div.innerHTML = '<p>x</p><style id="fit-vids-style">' + css + '</style>';
10371      head.appendChild(div.childNodes[1]);
10372    }
10373
10374    if ( options ) {
10375      $.extend( settings, options );
10376    }
10377
10378    return this.each(function(){
10379      var selectors = [
10380        'iframe[src*="player.vimeo.com"]',
10381        'iframe[src*="player.vimeo.com"]',
10382        'iframe[src*="youtube.com"]',
10383        'iframe[src*="youtube-nocookie.com"]',
10384        'iframe[src*="yumpu.com"]',
10385        'iframe[src*="www.yumpu.com"]',
10386        'iframe[src*="kickstarter.com"][src*="video.html"]',
10387        'iframe[src*="player.youku.com"]',
10388        'iframe[src*="mpembed.com"]',
10389        
10390        'object',
10391        'embed'
10392      ];
10393
10394      if (settings.customSelector) {
10395        selectors.push(settings.customSelector);
10396      }
10397
10398      var ignoreList = '.fitvidsignore';
10399
10400      if(settings.ignore) {
10401        ignoreList = ignoreList + ', ' + settings.ignore;
10402      }
10403
10404      var $allVideos = $(this).find(selectors.join(','));
10405      $allVideos = $allVideos.not('object object'); // SwfObj conflict patch
10406      $allVideos = $allVideos.not(ignoreList); // Disable FitVids on this video.
10407
10408      $allVideos.each(function(){
10409        var $this = $(this);
10410        if($this.parents(ignoreList).length > 0) {
10411          return; // Disable FitVids on this video.
10412        }
10413        if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; }
10414        if ((!$this.css('height') && !$this.css('width')) && (isNaN($this.attr('height')) || isNaN($this.attr('width'))))
10415        {
10416          $this.attr('height', 9);
10417          $this.attr('width', 16);
10418        }
10419        var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(),
10420            width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(),
10421            aspectRatio = height / width;
10422        if(!$this.attr('id')){
10423          var videoID = 'fitvid' + Math.floor(Math.random()*999999);
10424          $this.attr('id', videoID);
10425        }
10426        $this.wrap('<div class="fluid-width-video-wrapper"></div>').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+'%');
10427        $this.removeAttr('height').removeAttr('width');
10428      });
10429    });
10430  };
10431// Works with either jQuery or Zepto
10432})( window.jQuery || window.Zepto );
10433
10434
10435(function($){$.prompt=function(message,options){options=$.extend({},$.prompt.defaults,options);$.prompt.currentPrefix=options.prefix;var ie6=($.browser.msie&&$.browser.version<7);var $body=$(document.body);var $window=$(window);var msgbox='<div class="'+options.prefix+'box" id="'+options.prefix+'box">';if(options.useiframe&&(($('object, applet').length>0)||ie6)){msgbox+='<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+options.prefix+'fade" id="'+options.prefix+'fade"></iframe>';}else{if(ie6){$('select').css('visibility','hidden');}msgbox+='<div class="'+options.prefix+'fade" id="'+options.prefix+'fade"></div>';}msgbox+='<div class="'+options.prefix+'" id="'+options.prefix+'">
10435<div class="'+options.prefix+'container"><div class="';msgbox+=options.prefix+'close">X</div><div id="'+options.prefix+'states"></div>';msgbox+='</div></div></div>';var $jqib=$(msgbox).appendTo($body);var $jqi=$jqib.children('#'+options.prefix);var $jqif=$jqib.children('#'+options.prefix+'fade');if(message.constructor==String){message={state0:{html:message,buttons:options.buttons,focus:options.focus,submit:options.submit}};}var states="";$.each(message,function(statename,stateobj){stateobj=$.extend({},$.prompt.defaults.state,stateobj);message[statename]=stateobj;states+='<div id="'+options.prefix+'_state_'+statename+'" class="'+options.prefix+'_state" style="display:none;"><div class="'+options.prefix+'message">'+stateobj.html+'</div><div class="'+options.prefix+'buttons">';$.each(stateobj.buttons,function(k,v){states+='<button name="'+options.prefix+'_'+statename+'_button'+k+'" id="'+options.prefix+'_'+statename+'_button'+k+'" value="'+v+'">'+k+'</button>';});states+='</div></div>';});$jqi.find('#'+options.prefix+'states').html(states).children('.'+options.prefix+'_state:first').css('display','block');$jqi.find('.'+options.prefix+'buttons:empty').css('display','none');$.each(message,function(statename,stateobj){var $state=$jqi.find('#'+options.prefix+'_state_'+statename);$state.children('.'+options.prefix+'buttons').children('button').click(function(){var msg=$state.children('.'+options.prefix+'message');var clicked=stateobj.buttons[$(this).text()];var forminputs={};$.each($jqi.find('#'+options.prefix+'states :input').serializeArray(),function(i,obj){if(forminputs[obj.name]===undefined){forminputs[obj.name]=obj.value;}else if(typeof forminputs[obj.name]==Array){forminputs[obj.name].push(obj.value);}else{forminputs[obj.name]=[forminputs[obj.name],obj.value];}});var close=stateobj.submit(clicked,msg,forminputs);if(close===undefined||close){removePrompt(true,clicked,msg,forminputs);}});$state.find('.'+options.prefix+'buttons button:eq('+stateobj.focus+')').addClass(options.prefix+'defaultbutton');});var ie6scroll=function(){$jqib.css({top:$window.scrollTop()});};var fadeClicked=function(){if(options.persistent){var i=0;$jqib.addClass(options.prefix+'warning');var intervalid=setInterval(function(){$jqib.toggleClass(options.prefix+'warning');if(i++>1){clearInterval(intervalid);$jqib.removeClass(options.prefix+'warning');}},100);}else{removePrompt();}};var keyPressEventHandler=function(e){var key=(window.event)?event.keyCode:e.keyCode;if(key==27){removePrompt();}if(key==9){var $inputels=$(':input:enabled:visible',$jqib);var fwd=!e.shiftKey&&e.target==$inputels[$inputels.length-1];var back=e.shiftKey&&e.target==$inputels[0];if(fwd||back){setTimeout(function(){if(!$inputels)return;var el=$inputels[back===true?$inputels.length-1:0];if(el)el.focus();},10);return false;}}};var positionPrompt=function(){$jqib.css({position:(ie6)?"absolute":"fixed",height:$window.height(),width:"100%",top:(ie6)?$window.scrollTop():0,left:0,right:0,bottom:0});$jqif.css({position:"absolute",height:$window.height(),width:"100%",top:0,left:0,right:0,bottom:0});$jqi.css({position:"absolute",top:options.top,left:"50%",marginLeft:(($jqi.outerWidth()/2)*-1)});};var stylePrompt=function(){$jqif.css({zIndex:options.zIndex,display:"none",opacity:options.opacity});$jqi.css({zIndex:options.zIndex+1,display:"none"});$jqib.css({zIndex:options.zIndex});};var removePrompt=function(callCallback,clicked,msg,formvals){$jqi.remove();if(ie6){$body.unbind('scroll',ie6scroll);}$window.unbind('resize',positionPrompt);$jqif.fadeOut(options.overlayspeed,function(){$jqif.unbind('click',fadeClicked);$jqif.remove();if(callCallback){options.callback(clicked,msg,formvals);}$jqib.unbind('keypress',keyPressEventHandler);$jqib.remove();if(ie6&&!options.useiframe){$('select').css('visibility','visible');}});};positionPrompt();stylePrompt();if(ie6){$window.scroll(ie6scroll);}$jqif.click(fadeClicked);$window.resize(positionPrompt);$jqib.bind("keydown keypress",keyPressEventHandler);$jqi.find('.'+options.prefix+'close').click(removePrompt);$jqif.fadeIn(options.overlayspeed);$jqi[options.show](options.promptspeed,options.loaded);$jqi.find('#'+options.prefix+'states .'+options.prefix+'_state:first .'+options.prefix+'defaultbutton').focus();if(options.timeout>0)setTimeout($.prompt.close,options.timeout);return $jqib;};$.prompt.defaults={prefix:'jqi',buttons:{Ok:true},loaded:function(){},submit:function(){return true;},callback:function(){},opacity:0.6,zIndex:999,overlayspeed:'slow',promptspeed:'fast',show:'fadeIn',focus:0,useiframe:false,top:"15%",persistent:true,timeout:0,state:{html:'',buttons:{Ok:true},focus:0,submit:function(){return true;}}};$.prompt.currentPrefix=$.prompt.defaults.prefix;$.prompt.setDefaults=function(o){$.prompt.defaults=$.extend({},$.prompt.defaults,o);};$.prompt.setStateDefaults=function(o){$.prompt.defaults.state=$.extend({},$.prompt.defaults.state,o);};$.prompt.getStateContent=function(state){return $('#'+$.prompt.currentPrefix+'_state_'+state);};$.prompt.getCurrentState=function(){return $('.'+$.prompt.currentPrefix+'_state:visible');};$.prompt.getCurrentStateName=function(){var stateid=$.prompt.getCurrentState().attr('id');return stateid.replace($.prompt.currentPrefix+'_state_','');};$.prompt.goToState=function(state){$('.'+$.prompt.currentPrefix+'_state').slideUp('slow');$('#'+$.prompt.currentPrefix+'_state_'+state).slideDown('slow',function(){$(this).find('.'+$.prompt.currentPrefix+'defaultbutton').focus();});};$.prompt.nextState=function(){var $next=$('.'+$.prompt.currentPrefix+'_state:visible').next();$('.'+$.prompt.currentPrefix+'_state').slideUp('slow');$next.slideDown('slow',function(){$next.find('.'+$.prompt.currentPrefix+'defaultbutton').focus();});};$.prompt.prevState=function(){var $next=$('.'+$.prompt.currentPrefix+'_state:visible').prev();$('.'+$.prompt.currentPrefix+'_state').slideUp('slow');$next.slideDown('slow',function(){$next.find('.'+$.prompt.currentPrefix+'defaultbutton').focus();});};$.prompt.close=function(){$('#'+$.prompt.currentPrefix+'box').fadeOut('fast',function(){$(this).remove();});};})(jQuery);
10436// set up defaults for artlogic
10437jQuery.prompt.setDefaults({
10438      prefix: 'arprompt',
10439      useiframe: true
10440});
10441
10442
10443

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.