PageSourceSearch

https://www.hollistaggart.com/scripts/main.js?c=6060632af&v=20240223

js hollistaggart.com collected 2026-10-02 08:02:33 UTC 387,600 bytes, 7,285 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    };
16    window.cart.wishlist_summary.quick_wishlist_cart_widget_open_callback = function() {
17        $('#container_outer').removeClass('scrolling-down');
18        h.accessibility.on_popup_opening('#wishlist_quick_cart_widget', '#wishlist_quick_cart_widget a:first', '#wqcw_close');
19    };
20    window.cart.wishlist_summary.quick_wishlist_cart_widget_close_callback = function() {
21        h.accessibility.on_popup_closing();
22    };
23    
24    
25
26    window.site = {
27
28        init: function() {
29			
30            if (false) {
31
32                setTimeout(function() {
33
34                    $('body').addClass('page-transition-active');
35
36                    setTimeout(function() {
37                        $('body').addClass('page-transition');
38                    }, 100);
39                    setTimeout(function() {
40                        $('body').addClass('page-transition-custom');
41                    }, 1000);
42
43                }, 300);
44
45                return;
46            }
47
48
49			window.site.device.init();
50            window.site.pageload.init();
51            window.site.setup();
52            window.site.panel_3001();
53
54        },
55
56        setup: function() {
57            window.site.svg_inline.init();
58            window.site.countdown_clock.init();
59            // window.site.auto_mailto.init();
60            window.site.home.slideshow_color_change();
61            
62            window.site.home.init()
63            window.site.artworks.init();
64            window.site.artwork_filters.init();
65            window.site.publication_filters.init();
66            window.site.layout.init();
67            window.site.video.init();
68            window.site.slideshow.init();
69            window.site.scroll.init();
70            window.site.overlays.init();
71            window.site.lazy_load.init();
72            window.site.artlogic_inview.init();            
73            window.site.pageload_load_more_pagination.init();
74            window.site.social_media.init();
75            window.site.mailing_list_form.init();
76            window.site.enquiry.init();
77            window.site.quick_enquiry.init();
78            window.site.tracking.init();
79            window.site.store.init();
80            window.site.misc.init();
81            window.site.artists.init();
82            window.site.exhibitions.init();
83            window.site.filters.init();
84
85            window.site.objectfit_polyfill.init();            
86            window.site.submit_art.init();
87
88            
89            // var old_url = [];
90            // var new_url = [];
91 
92            
93            // var old_urls = '';
94            // var new_urls = '';
95            
96            // var remaining = '';
97            
98            // $('.subsection-artist-list-standard .image_list .item a').each(function() {
99           
100            //     var old_artist_id = $(this).attr('href').split('/')[2].split('-').shift();
101            //     var old_artist_href = $(this).attr('href').replace(old_artist_id + '-', '');
102    
103            //     old_urls += ',' + old_artist_href;
104            //     new_urls += ',' + $(this).attr('href');
105            //     // old_url.push(old_artist_href);
106            //     // new_url.push($(this).attr('href'));
107         
108            //     // if (! existing.includes(old_artist_href.substring(0, old_artist_href.length - 1)) ){
109            //     //     remaining += ',' + old_artist_href ;
110            //     // }
111                
112            // });
113            
114            
115            // console.log(old_urls);
116            // var existing = '/artists/josef-albers, /artists/ruth-asawa, /artists/pablo-atchugarry, /artists/milton-avery, /artists/will-barnet, /artists/william-baziotes, /artists/romare-bearden, /artists/leon-berkowitz, /artists/nell-blaine, /artists/oscar-bluemner, /artists/norman-bluhm, /artists/lisa-bradley, /artists/quita-brodhead, /artists/james-brooks, /artists/william-buchina, /artists/fritz-bultman, /artists/charles-burchfield, /artists/alexander-calder, /artists/giorgio-cavallon, /artists/lynn-chadwick, /artists/john-chamberlain, /artists/joseph-cornell, /artists/ralston-crawford, /artists/allan-darcangelo, /artists/gene-davis, /artists/stuart-davis, /artists/richard-diebenkorn, /artists/jim-dine, /artists/arthur-dove, /artists/edward-dugmore, /artists/friedel-dzubas, /artists/herbert-ferber, /artists/audrey-flack, /artists/gunther-forg, /artists/sam-francis, /artists/helen-frankenthaler, /artists/arnold-friedman, /artists/marla-friedman, /artists/frederick-carl-frieseke, /artists/daniel-garber, /artists/sam-gilliam, /artists/michael-goldberg, /artists/jack-goldstein, /artists/arshile-gorky, /artists/adolph-gottlieb, /artists/john-d-graham, /artists/keith-haring, /artists/grace-hartigan, /artists/hollis-heichemer, /artists/al-held, /artists/hans-hofmann, /artists/kenichi-hoshine, /artists/ben-isquith, /artists/paul-jenkins, /artists/alfred-jensen, /artists/alex-kanevsky, /artists/alex-katz, /artists/ellsworth-kelly, /artists/franz-kline, /artists/elaine-de-kooning, /artists/willem-de-kooning, /artists/john-knuth, /artists/lee-krasner, /artists/yayoi-kusama, /artists/chloe-lamb, /artists/alfred-leslie, /artists/sol-lewitt, /artists/roy-lichtenstein, /artists/li-lihong, /artists/morris-louis, /artists/sven-lukin, /artists/man-ray, /artists/conrad-marca-relli, /artists/knox-martin, /artists/alfred-h-maurer, /artists/matt-mignanelli, /artists/fred-mitchell, /artists/joan-mitchell, /artists/george-l-k-morris, /artists/ed-moses, /artists/robert-motherwell, /artists/robert-natkin, /artists/louise-nevelson, /artists/kenneth-noland, /artists/kenzo-okada, /artists/richard-pettibone, /artists/pablo-picasso, /artists/larry-poons, /artists/alexis-portilla, /artists/richard-pousette-dart, /artists/robert-rauschenberg, /artists/ad-reinhardt, /artists/milton-resnick, /artists/anne-estelle-rice, /artists/george-rickey, /artists/larry-rivers, /artists/james-rosenquist, /artists/mark-rothko, /artists/kay-sage, /artists/william-scharf, /artists/bill-scott, /artists/leon-polk-smith, /artists/david-smith, /artists/theodoros-stamos, /artists/frank-stella, /artists/irene-monat-stern, /artists/hedda-sterne, /artists/marjorie-strider, /artists/devin-troy-strother, /artists/mark-di-suvero, /artists/dorothea-tanning, /artists/wayne-thiebaud, /artists/alma-woodsey-thomas, /artists/yvonne-thomas, /artists/bob-thompson, /artists/mark-tobey, /artists/julius-tobias, /artists/jack-tworkov, /artists/esteban-vicente, /artists/george-vranesh, /artists/andy-warhol, /artists/idelle-weber, /artists/john-wesley, /artists/tom-wesselmann, /artists/michael-corinne-west, /artists/alan-wolfson, /artists/jonas-wood, /artists/zao-wou-ki';
117            // var existing_array = existing.split(',');
118                
119            // $.each(existing_array, function(index, url){
120 
121            //     if (! old_urls.includes(url)) {
122
123            //         remaining += ',' + url;
124            //     }
125                
126            // });
127            
128            // console.log(old_url);
129            // console.log(new_url);            
130            
131            // console.log(old_urls);
132            // console.log(new_urls);
133            // console.log(remaining);
134            
135            
136        },
137        panel_3001: function(){
138            $('.panel_3001_wrapper .sub_nav li').each(function(){
139                $(this).click(function(){
140                    category = $(this).attr('data-category');
141                    $('.panel_3001_wrapper .sub_nav li').each(function(){
142                        $(this).removeClass('active');
143                    });
144                    $(this).addClass('active');
145                    $('.panel_3001_wrapper .panel_type_3001').each(function(){
146                        if ($(this).attr('data-category') != category) {
147                            $(this).removeClass('panel-3001-active');
148                            $(this).addClass('panel-3001-inactive');
149                        } else {
150                            $(this).addClass('panel-3001-active');
151                            $(this).removeClass('panel-3001-inactive');
152                        }
153                    });
154                });
155            });
156        },
157        svg_inline: {
158
159            init: function() {
160
161                $('img.svg-inline').each(function(){
162                    var $img = jQuery(this);
163                    var imgID = $img.attr('id');
164                    var imgClass = $img.attr('class');
165                    var imgURL = $img.attr('src');
166
167                    jQuery.get(imgURL, function(data) {
168                        // Get the SVG tag, ignore the rest
169                        var $svg = jQuery(data).find('svg');
170
171                        // Add replaced image's ID to the new SVG
172                        if(typeof imgID !== 'undefined') {
173                            $svg = $svg.attr('id', imgID);
174                        }
175                        // Add replaced image's classes to the new SVG
176                        if(typeof imgClass !== 'undefined') {
177                            $svg = $svg.attr('class', imgClass+' replaced-svg');
178                        }
179
180                        // Remove any invalid XML tags as per http://validator.w3.org
181                        $svg = $svg.removeAttr('xmlns:a');
182
183                        // Replace image with new SVG
184                        $img.replaceWith($svg);
185
186                    }, 'xml');
187
188                });
189
190            }
191
192        },            
193        
194        countdown_clock: {
195
196            init: function() {
197
198
199                $('.countdown_clock .timer').each(function () {
200                    
201                    var $this = $(this);
202                    
203                    // Set the date we're counting down to
204                    var start_date = $(this).attr('data-target-time');
205                    var countDownDate = new Date(start_date.replace(/-/g,"/")).getTime();
206                    
207                    // Clock is active
208                    if (!$this.closest('.countdown_clock').hasClass('active')) {
209                        $this.closest('.countdown_clock').addClass('active');
210                    }
211                    
212                    // Set clock on first load
213                    $this.html(window.site.countdown_clock.update_clock_html(countDownDate));
214                    
215                    // Update the countdown every 1 second
216                    setInterval(function() {
217                        $this.html(window.site.countdown_clock.update_clock_html(countDownDate));
218                    }, 1000);
219                
220                });    
221
222            },
223            
224            update_clock_html: function(countDownDate) {
225
226                  // Get today's date and time
227                  var now = new Date().getTime();
228                
229                  // Find the distance between now and the count down date
230                  var distance = countDownDate - now;
231                
232                  var _html_ = '';
233
234                    
235                    if (distance <= 0) {
236                        
237                        // Reload the page to update and get new viewing room link
238                        location.reload();
239                        
240                    } else {
241                        
242                      // Time calculations for days, hours, minutes and seconds
243                      var days = Math.floor(distance / (1000 * 60 * 60 * 24));
244                      var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
245                      var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
246                      var seconds = Math.floor((distance % (1000 * 60)) / 1000);
247                    
248                      _html_ += (days != 0 ? '<span class="numeral">'+ days+ '</span><span class="period">d</span>' : '');
249                      _html_ += (hours != 0 ? '<span class="numeral">'+ hours+ '</span><span class="period">h</span>' : '');
250                      _html_ += (minutes != 0 ? '<span class="numeral">'+ minutes+ '</span><span class="period">m</span>' : '');
251                      _html_ += '<span class="numeral">'+ seconds+ '</span><span class="period">s</span>';
252                      
253                    }
254
255                  return _html_;
256                  
257            }
258            
259        },        
260
261        home: {
262
263            canvas_effect_enabled: false,
264
265            init: function() {
266                window.site.home.setup(); 
267                
268            },
269
270            start_slideshow_pre_init: function() {
271                
272            },
273            slideshow_color_change: function(bg_color,text_color) {
274                // console.log('slideshow_color_change');
275                // console.log(bg_color);
276                // console.log(text_color);
277
278                if (typeof text_color !== 'undefined') {
279                    $('#hero .slide .content, #hero .hero-inner .content, #hero .hero-inner .content h1, #hero .hero-inner .content .subtitle, #top_nav ul li a, #hero .info_module, #header .scw_total_items').css('color', text_color);                    
280                    $('#logo svg path.logo-path, #search_menu .button-icon svg *, #menu .button-icon svg *, .basket-icon svg *').css('fill', text_color);
281                    $('#hero .line-simple-inner, #top_nav ul li a, #hero .content_header .subtitle').css('border-color', text_color);
282                    
283                } else {
284                    //console.log('clearing styles');
285                    $('#hero .slide .content, #hero .hero-inner .content, #hero .hero-inner .content .subtitle, #top_nav ul li a, #header .scw_total_items, #header #menu').attr('style','');                    
286                    $('#logo svg path.logo-path, #search_menu .button-icon svg *, #menu .button-icon svg *, .basket-icon svg *').attr('style','');   
287                    $('#hero .line-simple-inner, #top_nav ul li a').attr('style','');   
288                }
289                
290                            // var $incoming_slide = $('#main_slideshow .slide[data-index='+next_slide_index+']');
291                            // var incoming_bg = $incoming_slide.attr('data-bg-color');
292                            // //console.log(incoming_bg);
293                            // $('#main_slideshow').css('background-color',incoming_bg);
294  
295                if (bg_color){
296                    var color_offset = window.site.home.slideshow_color_lighten_darken(bg_color, 10);
297                    
298                    if ($('#hero').hasClass('fullbleed')){
299                        $('#main_slideshow').css('background-color', color_offset);
300                        $('#main_slideshow .image_media_bg').css('background-color', color_offset);
301                        $('#main_slideshow .slide_bg').css('background-color', color_offset);
302                    } else {
303                    
304                        $('#main_slideshow').css('background-color', bg_color);
305                        $('#main_slideshow .image_media_bg').css('background-color', color_offset);
306                    }
307                    
308
309                }
310                
311                
312                // $('#main_slideshow .slide .image_media_bg, #hero .fallback_image .image_media_bg', this).each(function() {
313
314
315                // });
316                    
317                
318                
319            },            
320            
321            slideshow_color_lighten_darken: function(color, amount) {
322
323                
324                return tinycolor(color).darken(amount).toString();
325
326            },          
327            
328            // Not required anymore
329            getHiddenDimensions: function(includeMargin){
330                var $item = this,
331                props = { position: 'absolute', visibility: 'hidden', display: 'block' },
332                dim = { width: 0, height: 0, innerWidth: 0, innerHeight: 0, outerWidth: 0, outerHeight: 0 },
333                $hiddenParents = $item.parents().andSelf().not(':visible'),
334                includeMargin = (includeMargin == null) ? false : includeMargin;
335            
336                var oldProps = [];
337                $hiddenParents.each(function () {
338                    var old = {};
339            
340                    for (var name in props) {
341                        old[name] = this.style[name];
342                        this.style[name] = props[name];
343                    }
344            
345                    oldProps.push(old);
346                });
347            
348                dim.width = $item.width();
349                dim.outerWidth = $item.outerWidth(includeMargin);
350                dim.innerWidth = $item.innerWidth();
351                dim.height = $item.height();
352                dim.innerHeight = $item.innerHeight();
353                dim.outerHeight = $item.outerHeight(includeMargin);
354            
355                $hiddenParents.each(function (i) {
356                    var old = oldProps[i];
357                    for (var name in props) {
358                        this.style[name] = old[name];
359                    }
360                });
361            
362                return dim;
363            },
364            
365            slide_sizing: function() {
366                
367                var area_width = $('#hero .image.media_wrapper:visible').innerWidth();
368                var area_height = $('#hero .image.media_wrapper:visible').innerHeight();
369                
370                $('#hero .image_media').attr('style', '');
371 
372                var shortest_image;
373                
374                $('#hero .image_media').each(function() {
375                    //console.log('image_media');
376                    var $image_media = $(this);
377                    var area_proportion = area_width / area_height;
378
379                    // console.log('------------------------------------');
380                    // console.log('-----w-----'+area_width);
381                    // console.log('-----h-----'+area_height);
382                    // console.log('-----r-----'+area_proportion);
383                    
384                    // // console.log('-----'+area_width);
385                    var img_width = $image_media.attr('data-width');
386                    var img_height = $image_media.attr('data-height');
387                    
388                    var image_ratio = (img_width / area_width);
389                    var image_proportion = img_width / img_height;
390                    
391                    if ($image_media.hasClass('portrait')) {
392                        
393                        if (image_proportion > area_proportion) {
394                            //Less portratit than area - reduce height
395                            var this_image_ratio = (img_width / area_width);
396                            var new_height = img_height / this_image_ratio;
397                            if (new_height > 0) {
398                                $image_media.css('height', new_height + 'px');
399                                $image_media.css('width', '100%');
400                            }
401                            
402                        } else {
403                            //More portratit than area - reduce width
404                            var this_image_ratio = (img_height / area_height);
405                            var new_width = img_width / this_image_ratio;
406                            if (new_width > 0) {
407                                $image_media.css('width', new_width + 'px');
408                                $image_media.css('height', '100%');
409                            }
410                        }
411
412                    } else {
413                        
414                 
415
416                            var new_height = img_height / image_ratio;
417                       
418                            if (new_height > area_height) {
419                                var scaledown_ratio = area_height / new_height;
420                                new_height = new_height * scaledown_ratio;
421                                var new_width = area_width * scaledown_ratio;
422                                //console.log(scaledown_ratio);
423                                $image_media.css('height', new_height + 'px');
424                                $image_media.css('width', new_width + 'px');
425                            } else {
426                                $image_media.css('height', new_height + 'px');
427                                $image_media.css('width', '100%');
428                            }
429           
430                     
431                    }
432                    
433                    if (new_height && typeof new_height != 'undefined') {
434                        if (!shortest_image) {
435                            shortest_image = new_height;
436                        } else if (new_height < shortest_image) {
437                            shortest_image = new_height;
438                        } 
439                    }
440                });
441
442                $('#hero').css('height', (shortest_image + $('#header').height()) + 'px');
443
444            },
445            
446 
447            start_slideshow: function(run_pre_init) {
448                run_pre_init = typeof run_pre_init != 'undefined' ? run_pre_init : true;
449                $('#main_slideshow').each(function() {
450                    if (!$('#main_slideshow').hasClass('slideshow-paused-by-default')) {
451                        setTimeout(function() {
452                            $('#main_slideshow').cycle('resume');
453                        }, 100);
454                    }
455                    main_slideshow_cycle_before(false, false, false, $('#main_slideshow .slide:eq(0)'), false);
456
457                    $('body').addClass('main_slideshow_active');
458                    
459                    setTimeout(function() {
460                        if (run_pre_init) {
461                            window.site.home.start_slideshow_pre_init();
462                        }
463                        $('body').addClass('main_slideshow_animate');
464                    }, 400, run_pre_init);
465                });
466            },
467
468            setup: function() {
469
470                
471                $('body').removeClass('main_slideshow_active main_slideshow_animate');
472
473                $('#hero').each(function() {
474                    
475                    // Setup each slide (non-canvas)
476                    if ($('#main_slideshow .slide', this).length == 1) {
477                        $(this).addClass('cycle-single-slide');
478                    }
479                    window.site.home.slide_sizing();
480                    $(window).resize(function() {
481                        window.site.home.slide_sizing();
482                    });
483                    
484        
485                    // Play all the videos to force them to load
486                    $('xx#main_slideshow .slide video').each(function() {
487                        $(this).get(0).play();
488                    });
489                    
490                    // $('#main_slideshow .slide', this).each(function() {
491                    //     if ($('a', this).length) {
492                    //         $('.content, .image, .image_hover_area', this).css('cursor', 'pointer').click(function() {
493                    //             $(this).closest('.slide').find('a').trigger('click');
494                    //         });
495                    //     }
496                    // });
497
498
499
500                    
501                    $('#hero .fallback_image').each(function() {
502                        var slide_color = $(this).attr('data-bg-color');
503                        var this_text_color = $(this).attr('data-text-color');
504                        window.site.home.slideshow_color_change(slide_color,this_text_color);
505                    });
506        
507
508                    main_slideshow_cycle_end = function(next_slide_index) {
509                        //console.log('main_slideshow_cycle_end');
510                        // Change image in the canvas element
511                        if (!$('#homepage_overall_container').hasClass('cycle-single-slide')) {
512                            if (next_slide_index && typeof next_slide_index != 'undefined') {
513    
514                            } else {
515                                // assume it is the next slide
516                                next_slide_index = parseInt($('#main_slideshow .slide.cycle-slide-active').attr('data-index')) + 1;
517                                if (next_slide_index > $('#main_slideshow .slide').length) {
518                                    next_slide_index = 1;
519                                }
520                            }
521    
522                            if (!$('#homepage_overall_container').hasClass('device-canvas-fallback-mode')) {
523                                if (window.window.canvasSlideshowInitialized) {
524                                    window.canvasSlideshowChange(next_slide_index-1);
525                                }
526                            }
527                            
528                            $('#main_slideshow').addClass('slide-changing');
529                            //$('.cycle-slide.cycle-slide-active').find('.text_animate').textillate('out');
530                            $('#main_slideshow, .scroll-container').addClass('slide-end');
531                            $('#main_slideshow, .scroll-container').removeClass('slide-active');
532
533
534                            // var $incoming_slide = $('#main_slideshow .slide[data-index='+next_slide_index+']');
535                            // var incoming_bg = $incoming_slide.attr('data-bg-color');
536                            // //console.log(incoming_bg);
537                            // $('#main_slideshow').css('background-color',incoming_bg);
538                            
539                            
540                            $('#main_slideshow:not(.cycle-single-slide) .slide.cycle-slide-active').addClass('slide_exit_animation');
541                        }
542                    }
543
544                    main_slideshow_cycle_before = function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
545                        //console.log('main_slideshow_cycle_before');
546                        var this_index = $(incomingSlideEl).attr('data-index');
547                        this_color = $(incomingSlideEl).attr('data-color');
548                        var prev_slide_index = 1;
549                        
550                        if (typeof $(outgoingSlideEl).attr('data-index') != 'undefined') {
551                            prev_slide_index = $(outgoingSlideEl).attr('data-index');
552                        }
553                        
554                        this_text_color = $(incomingSlideEl).attr('data-text-color');
555                        this_bg_color = $(incomingSlideEl).attr('data-bg-color');
556                        window.site.home.slideshow_color_change(this_bg_color,this_text_color);
557                        
558
559                        $('#main_slideshow').removeClass('slide-changing');
560                        var prev_slide_aria_label = $('#main_slideshow_nav li[data-index="' + prev_slide_index + '"] button').attr("aria-label");
561
562                        $('#main_slideshow_nav li[data-index="' + prev_slide_index + '"] button').attr("aria-label", prev_slide_aria_label.replace(' (Current slide)', ''));
563                        $('#main_slideshow_nav li').removeClass('active');
564                        $('#main_slideshow_nav li[data-index="' + this_index + '"]').addClass('active');
565                        var current_slide_aria_label = $('#main_slideshow_nav li[data-index="' + this_index + '"] button').attr("aria-label");
566                        $('#main_slideshow_nav li[data-index="' + this_index + '"] button').attr("aria-label", current_slide_aria_label + ' (Current slide)');
567                        
568                        $('#main_slideshow_progress .number').text('0' + this_index);
569                        $('#main_slideshow_pagination .number').text('0' + this_index);
570                        
571                        //$('#main_slideshow .slide').removeClass('slide_exit_animation');
572                        // $('#main_slideshow').css('background-color',this_bg_color);
573                        // $(outgoingSlideEl).addClass('slide_exit_animation');
574                        //$(incomingSlideEl).addClass('slide_exit_animation');
575                        
576                        
577                        if (outgoingSlideEl) {
578                            $('.text_animate', outgoingSlideEl).textillate('out');
579                        }
580
581                        // $('body').removeClass('color1 color2 color3 color4 color5 color6')
582
583                        $('#main_slideshow, .scroll-container').removeClass('slide-begin slide-begin2 slide-active');
584                        $('#main_slideshow, .scroll-container').removeClass('slide-end');
585                        $('#main_slideshow .slide').removeClass('custom-slide-active');
586                        
587                        $('#main_slideshow video').each(function() {
588                            $(this).get(0).pause();
589                        });
590
591                        // Play video
592
593                        if ($('video', incomingSlideEl).length) {
594                            $('video', incomingSlideEl).get(0).play();
595                        }
596
597                        // Note: textillate text needs to be brough in at this point because it will flicker if delayed
598                        $('.text_animate', incomingSlideEl).textillate('in');
599
600                        var slideshow_delay = 5200;
601
602                        
603                        $('#main_slideshow')
604                            .stop().clearQueue()
605                            .animate({'display':'block'}, 50, function() {
606                                $('#main_slideshow .slide').removeClass('slide_exit_animation');
607                                $('#main_slideshow, .scroll-container').addClass('slide-active');
608                                $('body').addClass(this_color);
609                                $('#main_slideshow .slide.cycle-slide-active').addClass('custom-slide-active');
610                            })
611                            .animate({'display':'block'}, 100, function() {
612                                $('#main_slideshow').addClass('slide-begin');
613                                
614                                $('body').addClass(this_color);
615                            })
616                            .animate({'display':'block'}, 500, function() {
617                                $('#main_slideshow').addClass('slide-begin2');
618                                //console.log('1');
619                            })
620                            .animate({'display':'block'}, slideshow_delay, function() {
621                                //console.log('2');
622                            })
623                            .animate({'display':'block'}, 0, function() {
624                                //console.log('3');
625                                 
626                                if (!$('#main_slideshow').hasClass('cycle-paused')) {
627                                    next_slide_index = parseInt($('#main_slideshow .slide.cycle-slide-active').attr('data-index')) + 1;
628                                    if (next_slide_index > $('#main_slideshow .slide').length) {
629                                        next_slide_index = 1;
630                                    }
631                                    main_slideshow_cycle_end(next_slide_index);
632                                }
633                            })
634                        ;
635                    }
636                    
637                    main_slideshow_pause_toggle = function() {
638                        if (!$('#main_slideshow').hasClass('cycle-paused')) {
639                            $('#main_slideshow').cycle('pause');
640                            $('#main_slideshow_progress').addClass('paused');
641                        } else {
642                            $('#main_slideshow').cycle('resume');
643                            $('#main_slideshow').stop().clearQueue();
644                            main_slideshow_cycle_end();
645                            $('#main_slideshow_nav')
646                                .stop().clearQueue()
647                                .animate({'display':'block'}, 800, function() {
648                                    $('#main_slideshow').cycle('next');
649                                    $('#main_slideshow_nav').removeClass('slide-changing');
650                                })
651                            ;
652                            $('#main_slideshow_progress').removeClass('paused');
653                        }
654                    }
655
656                    var cycle_timeout = 6620;
657                    cycle_timeout_type = 'standard';
658
659                    var cycle_settings = {
660                        fx:       'fade',
661                        speed:    1,
662                        timeout:  cycle_timeout,
663                        paused:    false,
664                        slides: '>',
665                        autoHeight: false,
666                        swipe: true
667                    };
668                    $('#main_slideshow').unbind().cycle(cycle_settings);
669                    
670                    $('#main_slideshow').on('cycle-before', function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
671                        main_slideshow_cycle_before(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag);
672                    });
673                    
674                    if ($('#main_slideshow >').length == 1 || $('#main_slideshow').hasClass('cycle-paused') || $('#main_slideshow').hasClass('slideshow-paused-by-default')) {
675                        $('#main_slideshow').cycle('pause');
676                        $('#main_slideshow_progress').addClass('paused');
677                    }
678
679                    $('#main_slideshow_pagination .prev').unbind().click(function() {
680                        $('#main_slideshow').cycle('pause');
681                        main_slideshow_change_slide('previous');
682                    });
683                    $('#main_slideshow_pagination .next').unbind().click(function() {
684                        $('#main_slideshow').cycle('pause');
685                        main_slideshow_change_slide('next');
686                    });
687
688                    $('#main_slideshow_progress .pause').click(function() {
689                        main_slideshow_pause_toggle();
690                    });
691                    
692                    // Once setup, pause slideshow and wait for start_slideshow function to be called
693                    main_slideshow_pause_toggle();
694
695                    var total_slides = $('#main_slideshow >').length;
696                    $('#main_slideshow_progress .total').text('0' + total_slides);
697                    $('#main_slideshow_pagination .total').text('0' + total_slides);
698
699                    $('#main_slideshow_nav li')
700                        .click(function() {
701        
702                            if (!$(this).hasClass('active') && !$('#main_slideshow_nav').hasClass('slide-changing')) {
703                                $('#main_slideshow_nav li').removeClass('active');
704                                $('#main_slideshow_nav').addClass('paused');
705                                $('#main_slideshow').cycle('pause');
706                                $('#main_slideshow_nav').addClass('slide-changing');
707                                slide_index = $(this).attr('data-index');
708                                main_slideshow_cycle_end();
709                                $(this).addClass('active');
710                                $('#main_slideshow_nav')
711                                    .stop().clearQueue()
712                                    .animate({'display':'block'}, 500, function() {
713                                        $('#main_slideshow').cycle(parseInt(slide_index) -1);
714                                        $('#main_slideshow_nav').removeClass('slide-changing');
715                                    })
716                                ;
717                            }
718                        })
719                    ;
720
721                    main_slideshow_change_slide = function(direction) {
722
723                        if (direction == 'next') {
724                            // console.log('running next');
725                            //$('#main_slideshow').cycle('pause');
726                            $('#main_slideshow').stop().clearQueue();
727                            $('#main_slideshow_nav').addClass('slide-changing');
728                            next_slide_index = parseInt($('#main_slideshow .slide.cycle-slide-active').attr('data-index')) + 1;
729                            if (next_slide_index > $('#main_slideshow .slide').length) {
730                                next_slide_index = 1;
731                            }
732                            main_slideshow_cycle_end(next_slide_index);
733                            
734                            //$(this).addClass('active');
735                            $('#main_slideshow_nav')
736                                .stop().clearQueue()
737                                .animate({'display':'block'}, 400, function() {
738                                    $('#main_slideshow').cycle('next');
739                                })
740                                .animate({'display':'block'}, 800, function() {
741                                    $('#main_slideshow_nav').removeClass('slide-changing');
742                                })
743                            ;
744                        } else if (direction == 'previous') {
745                            //$('#main_slideshow').cycle('pause');
746                            $('#main_slideshow').stop().clearQueue();
747                            $('#main_slideshow_nav').addClass('slide-changing');
748                            next_slide_index = $('#main_slideshow .slide.cycle-slide-active').attr('data-index') - 1;
749                            if (next_slide_index < 1) {
750                                next_slide_index = $('#main_slideshow .slide').length;
751                            }
752                            main_slideshow_cycle_end(next_slide_index);
753                            //$(this).addClass('active');
754                            $('#main_slideshow_nav')
755                                .stop().clearQueue()
756                                .animate({'display':'block'}, 400, function() {
757                                    $('#main_slideshow').cycle('prev');
758                                })
759                                .animate({'display':'block'}, 800, function() {
760                                    $('#main_slideshow_nav').removeClass('slide-changing');
761                                })
762                            ;
763                        }
764                    };
765
766                    $(document).keydown(funct
766ion(e) {
767                        if (e.which == 38) {
768                            // Up
769                            main_slideshow_change_slide('previous');
770                            e.preventDefault(); // prevent the default action (scroll)
771                        } else if (e.which == 40) {
772                            // Down
773                            main_slideshow_change_slide('next');
774                            e.preventDefault(); // prevent the default action (scroll)
775                        }
776                    });
777
778                    if ($('body').hasClass('first-load-complete')) {
779                        window.site.home.start_slideshow();
780                    }
781                    
782                });
783
784            }
785
786        },
787
788        slideshow: {
789
790            init: function() {
791                window.site.slideshow.cascading();
792                window.site.slideshow.slider.init();
793            },
794
795            slider: {
796
797                image_sizes: function(instance) {   
798                                $(instance).find('.item').each(function(){
799                                    if ($(this).find('.image').length) {
800                                        var current_height = $(this).find('.image').height();
801                                    } else {
802                                        var current_height = $(this).height();
803                                    }
804                                    var ratio_width = $(this).find('.image').attr('data-width');
805                                    var ratio_height = $(this).find('.image').attr('data-height');
806                                    if (current_height > 0 && ratio_width && ratio_height) {
807                                        var new_width = 0;
808                                        var ratio = (ratio_height / current_height);
809                                        var new_width = ratio_width / ratio;
810                                        if (new_width > 0) {
811                                            $(this).find('.image').css('min-width', new_width + 'px');
812                                            
813                                            $(this).css('min-width', new_width + 'px');
814                                        }
815                                    }
816                                });
817                } ,          
818                    
819                init: function() {
820                    $('.records_list_slider').each(function() {
821                        
822                        var $slider_outer = $(this);
823                        var instance = $(this).find('.records_list_inner');
824                        var slider_infinite = false;
825                        var lazyload_amount = 3;
826                        var groupCells = true;
827                        var dotsContainer = $(instance).closest('.area_wrapper').find('.panel_heading')[0];
828                        var cellAlign = 'left';
829                        var show_dots = true;
830                        var $instance = $(instance);
831                        var $area_wrapper = $instance.closest('.area_wrapper');
832                        
833                        if ($instance.find('.item').length) {
834                            
835                            if ($slider_outer.hasClass('fullwidth_image_slider') || $slider_outer.hasClass('related_content_slider')) {
836                                var groupCells = false;
837                                slider_infinite = true;
838                                cellAlign = 'center';
839                                
840                                window.site.slideshow.slider.image_sizes(instance);
841                                $(window).resize(function() {
842                                    window.site.slideshow.slider.image_sizes(instance);
843                                });
844                                var dotsContainer = $area_wrapper.find('.pager-wrapper')[0];
845                            }
846
847                            $instance.flickity({
848                                cellAlign: cellAlign,
849                                resize: true,
850                                prevNextButtons: false,
851                                pageDots: show_dots,
852                                contain: true,
853                                wrapAround: true,
854                                imagesLoaded: true, //required for height on first load
855                                adaptiveHeight: false, //Change height on each slide change
856                                lazyLoad: lazyload_amount,
857                                setGallerySize: true, //Auto set the slideshow height
858                                groupCells: groupCells,
859                                dotsContainer: dotsContainer,
860                                hideSingleDot: true
861                            });
862
863
864                            window.site.slideshow.slider.update_pager($instance, $area_wrapper);
865
866                            
867
868                            if (groupCells) {
869                                var flkty = $instance.data('flickity');
870                                var item_count = $instance.find('.item').length;
871                                var item_width = Math.floor($instance.find('.item:eq(0)')[0].getBoundingClientRect().width);
872                                var instance_width = $instance.width();
873                                var items_per_group = instance_width / item_width;
874    
875                                // If there are not enough items to be scrolled, disable pagination and unbind the drag
876                                if (items_per_group) {
877                                     if (flkty.cells.length <= items_per_group) {
878                                         flkty.unbindDrag();
879                                         $(instance).closest('.records_list_slider').addClass('slider_disabled');
880                                     }
881                                 }
882                            }
883
884
885                            //Initialise controls
886                            $(this).find('.pagination_controls > div, .pagination_controls > button').click(function() {
887                                if ($(this).hasClass('pagination_controls_prev')) {
888                                    $(this).closest('.records_list_slider').find('.records_list_inner').flickity('previous');
889                                    $instance.trigger('dragEnd');
890                                } else if ($(this).hasClass('pagination_controls_next')) {
891                                    $(this).closest('.records_list_slider').find('.records_list_inner').flickity('next');
892                                    $instance.trigger('dragEnd');
893                                }
894                            });
895
896
897                         //Initialise controls
898                            $area_wrapper.find('.slider_pagination_controls .slider_pagination_button').click(function() {
899
900                                if ($(this).hasClass('slider_pagination_controls_prev')) {
901                                    $instance.flickity('previous');
902             
903                                    $instance.trigger('dragEnd');
904                                } else if ($(this).hasClass('slider_pagination_controls_next')) {
905                                   $instance.flickity('next');
906                                   $instance.trigger('dragEnd');
907                                }
908                            });
909 
910
911 
912                            // Event on start of drag
913                            $instance.on('dragStart.flickity', function() {
914                                $('body').addClass('slider-drag');
915                            });
916
917                            // Event on end of drag
918                            $instance.on('dragEnd.flickity', function() {
919
920                                // Find the tallest slide in the current set and scale slider height to this height
921
922                                tallest_item = 0;
923                                var item_count = $instance.find('.item').length;
924                                var item_width = Math.floor($instance.find('.item:eq(0)')[0].getBoundingClientRect().width);
925                                var instance_width = $instance.width();
926                                var items_per_group = instance_width / item_width;
927                                var items_in_viewport = $instance.find('.item.is-selected').nextAll().andSelf().slice(0, items_per_group);
928                                var additional_items_in_viewport = {};
929
930                                if ($instance.closest('.records_list_slider').hasClass('slider_infinite')) {
931                                    // In an infinite slideshow, the end of the slider will include images from the beginning of the list
932                                    // This means we need to check the height of the items at the beginning of the list.
933                                    // Work out the deficit of items in the existing selector then add the items from the beginning of the slider to the end.
934                                    if (items_in_viewport.length < items_per_group) {
935                                        var item_deficit = (items_per_group - items_in_viewport.length);
936                                        var additional_items_in_viewport = $instance.find('.item').slice(0, item_deficit);
937                                        if (additional_items_in_viewport.length) {
938                                            var items_in_viewport = $(items_in_viewport).add(additional_items_in_viewport);
939                                        }
940                                    }
941                                }
942
943                                $(window).trigger('resize');
944
945                            });
946
947                            // Event when slider stops moving completely
948                            $instance.on('settle.flickity', function() {
949                                $('body').removeClass('slider-drag');
950                            });
951
952                            // Event on a new slide being moved into view
953                            $instance.on('select.flickity', function() {
954                                window.site.slideshow.slider.after_change($instance, true, $area_wrapper);
955                            });
956
957
958                            // Fire events once initially to make sure processes have been run on the initial view before a transition has been made
959                            $instance.trigger('dragEnd.flickity');
960                            window.site.slideshow.slider.after_change($instance, true, $area_wrapper);
961                        }
962
963                 
964 
965
966
967                    });
968
969                    $('.records_list_slider.feature_list_slider .item').each(function() {
970                        if ($('.content', this).index() == 0) {
971                            $('.content', this).addClass('responsive-hidden');
972                            $(this).append('<div class="content responsive-only">' + $('.content', this).html() + '</div>');
973                        }
974                    });
975                    
976                    // For accessibilityy - allow flickity dots to work with keyboard
977                    $('.flickity-page-dots').on( 'click', 'button', function() {
978                      var index = $(this).index();
979                      $(this).closest('.area_wrapper').find('.records_list_inner').flickity( 'select', index );
980                    });
981                    
982                },
983
984                after_change: function($instance, forced, $area_wrapper) {
985                    
986                    var flkty = $instance.data('flickity');
987                    var target = flkty.selectedCell.target;
988                    var caption = $(flkty.selectedCell.element).attr('data-caption');
989                    var text_color = $(flkty.selectedCell.element).attr('data-text-color');
990                    
991                    $instance.closest('.records_list_slider').find('.records_list_slider_caption').html('');
992                    if (caption && typeof caption != 'undefined') {
993                        $instance.closest('.records_list_slider').find('.records_list_slider_caption').html(caption);
994                    }
995                    
996                    //console.log($(instance));
997                    $instance.find('.related-panel-heading h2').css('color',text_color); 
998                    $instance.closest('.area_wrapper').find('.dot-text').css('color',text_color);
999                    $instance.closest('.area_wrapper').find('.dot-line').css('background',text_color);
1000                    $instance.closest('.area_wrapper').find('.slider-stats').css('color',text_color);
1001                    $instance.closest('.area_wrapper').find('.slider_pagination_button svg g').css('stroke',text_color);
1002                    
1003                    window.site.slideshow.slider.update_pager($instance, $area_wrapper);
1004                 
1005                    
1006                    
1007                    if (false) {
1008                        
1009                        // Not relevant because slider is continuous
1010                        if (!$(instance).closest('.records_list_slider').hasClass('slider_infinite')) {
1011                            if (target == flkty.cells[0].target) {
1012                                $(instance).closest('.records_list_slider').find('.pagination_controls .pagination_controls_prev').addClass('disabled');
1013                            } else if (target == flkty.getLastCell().target) {
1014                                $(instance).closest('.records_list_slider').find('.pagination_controls .pagination_controls_next').addClass('disabled');
1015                            } else {
1016                                // both buttons enabled
1017                                $(instance).closest('.records_list_slider').find('.pagination_controls .pagination_controls_prev').removeClass('disabled');
1018                                $(instance).closest('.records_list_slider').find('.pagination_controls .pagination_controls_next').removeClass('disabled');
1019                            }
1020                        }
1021                    }
1022                },               
1023                
1024                update_pager: function($instance, $area_wrapper) {
1025                    
1026                    var collapse_dots = 5;
1027                    var $dots = $area_wrapper.find('.flickity-page-dots');
1028                    var dot_length = $area_wrapper.find('.flickity-page-dots .dot').length;
1029
1030            
1031                    if (typeof $instance != 'undefined') {
1032                        
1033                        if ($dots.css("visibility") == "hidden" || dot_length > collapse_dots) {
1034
1035                            // show_dots = false;
1036                            $area_wrapper.find('.slider_pagination_controls').addClass('active');
1037                            $dots.addClass('hidden');
1038                           
1039                            var total_groups = $area_wrapper.find('.flickity-page-dots .dot').length;
1040                            var current_group = $area_wrapper.find('.flickity-page-dots .dot.is-selected').index() + 1;
1041
1042                            $area_wrapper.find('.slider-stats .total-slides').text(total_groups);
1043                            $area_wrapper.find('.slider-stats .active-slide').text(current_group);
1044                            
1045                        } else {
1046                            
1047                            $area_wrapper.find('.slider_pagination_controls').removeClass('active');
1048                            if (dot_length > 1) {
1049                                $dots.removeClass('hidden');
1050                            }
1051                            
1052                        }
1053                    }
1054                }
1055                
1056            },
1057
1058            cascading: function() {
1059                $('.content_slideshow').each(function() {
1060                    var mastersettings = {
1061                        fx:     'fade',
1062                        speed:    1200,
1063                        timeout:  3000,
1064                        pause:   0,
1065                        slides: '> .item',
1066                        autoHeight: 'calc',
1067                        swipe: true
1068                    }
1069                    $(this).cycle(mastersettings);
1070                    $('.slide_pagination_controls .pagination_controls_prev', this).unbind().bind('click', function() {
1071                        $(this).closest('.content_slideshow').cycle('pause').cycle('prev');
1072                        return false;
1073                    });
1074                    $('.slide_pagination_controls .pagination_controls_next', this).unbind().bind('click', function() {
1075                        $(this).closest('.content_slideshow').cycle('pause').cycle('next');
1076                        return false;
1077                    });
1078                });
1079            }
1080
1081        },
1082
1083        video: {
1084
1085        	init: function() {
1086                
1087                // Object-fit for IE/Edge
1088                objectFitVideos();
1089
1090                if ($('body').fitVids) {
1091                    $('body').fitVids({ ignore: '.video_inline'});
1092                }
1093
1094                if (window.site.device.video_inline()) {
1095                    $('body').addClass('device-video-inline-enabled');
1096                } else {
1097                    $('body').addClass('device-video-inline-disabled');
1098                }
1099
1100                if (!window.site.device.video_inline()) {
1101                    $('body').addClass('device-video-fallback');
1102                }
1103
1104               	$('.media_wrapper').each(function() {
1105	                var wrapper = $(this);
1106                    if (!$(this).hasClass('media_wrapper_has_canvas') || ($(this).hasClass('media_wrapper_has_canvas') && !window.site.device.canvas_enabled())){
1107                        // Each media wrapper may be disabled if there is an outside alternative which is currently active (in this case, video within canvas)
1108                        if ($(this).hasClass('media_has_video') && window.site.device.video_mode()) {
1109                            if ($('video', this).length) {
1110                                $(this).addClass('video_loading');
1111                                $('video', this).unbind().get(0).oncanplay = function() {
1112                                    var instance = $(this);
1113                                    window.setTimeout(function() {
1114                                        instance.closest('.media_wrapper').addClass('video_can_start');
1115                                        instance.closest('.media_wrapper').removeClass('video_loading');
1116                                        wrapper.closest('.media_wrapper').addClass('media_started');
1117                                    }, 000, instance);
1118                                };
1119                            }
1120                            window.setTimeout(function() {
1121                            	if (!wrapper.hasClass('video_can_start')) {
1122    	                        	wrapper.addClass('show_fallback');
1123                                    wrapper.closest('.media_wrapper').addClass('media_started');
1124    	                    	}
1125                            }, 1400, wrapper);
1126                        } else {
1127                            //wrapper.find('video').remove();
1128                        	if (wrapper.find('.slideshow').length) {
1129                        		wrapper.addClass('show_slideshow');
1130                        	} else {
1131                        		wrapper.addClass('show_fallback');
1132                        	}
1133                            wrapper.closest('.media_wrapper').addClass('media_started');
1134                        }
1135                    }
1136               	});
1137
1138                
1139                if (!window.site.device.video_mode()) {
1140
1141                    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>';
1142                    if ($('.media_wrapper .video_background video').length) {
1143                        $('.media_wrapper').append(video_fallback_html);
1144                    }
1145                    $('.video_fallback_button').unbind('click').bind('click', function() {
1146                        if (window.site.device.video_mode()) {
1147                            var section_element = $(this).closest('.media_wrapper');
1148                            if (section_element.hasClass('video_fallback_playing')) {
1149                                section_element.find('.video_background video').get(0).pause();
1150                                section_element.removeClass('video_fallback_playing');
1151                            } else {
1152                                section_element.find('.video_background video').get(0).play();
1153                                section_element.addClass('video_fallback_playing');
1154                            }
1155                        } else {
1156                            var video_src = $(this).closest('.media_wrapper').find('.video_background video source').attr('src');
1157                            var video_data_src = $(this).closest('section').find('.video_background video source').attr('data-src');
1158                            if (video_src && typeof video_src != 'undefined') {
1159                                var video_file = video_src;
1160                            } else {
1161                                var video_file = video_data_src;
1162                            }
1163                            if (video_file && typeof video_file != 'undefined') {
1164                                window.open(video_file);
1165                            }
1166                        }
1167                    });
1168                } else {
1169                    video_loading_html = '<div class="video_loading_icon"><span class="loader"></span>Video loading</div>';
1170                    if ($('.media_wrapper .video_background video').length) {
1171                        $('.media_wrapper .video_background').append(video_loading_html);
1172                    }
1173                }
1174
1175                
1176
1177                var vimeo_embeds = $('.video_embed_vimeo');
1178                vimeo_embeds.each(function() {
1179                    var player = $f(this); // Froogaloop selector
1180
1181                    $(this).closest('.video_embed_wrapper').find('.video_embed_play').click(function() {
1182                        var player = $f($(this).closest('.video_embed_wrapper').find('iframe').get(0)); // Froogaloop selector
1183                        player.api("play");
1184                    });
1185                    $(this).closest('.video_embed_wrapper').find('.video_embed_pause').click(function() {
1186                        var player = $f($(this).closest('.video_embed_wrapper').find('iframe').get(0)); // Froogaloop selector
1187                        player.api("pause");
1188                    });
1189                });
1190				
1191        	}
1192
1193        },
1194
1195        layout: {
1196
1197        	init: function() {
1198        	    
1199        	    
1200        		window.site.layout.textillate();
1201        		window.site.layout.grids.init();
1202        		window.site.layout.feature_panels();
1203        		window.site.layout.navigation();
1204                window.site.layout.hero.init();
1205                window.site.layout.hero_text_adjust() 
1206
1207        		$('#main_content').css('min-height', window.site.layout.window_height());
1208        		
1209                $('.notify_panel_mask').unbind().click(function() {
1210                    if ($('#store_quick_cart_widget').hasClass('active')) {
1211                        $('#sqcw_close').trigger('click');
1212                    }
1213                    if ($('#wishlist_quick_cart_widget').hasClass('active')) {
1214                        $('#wishlist_quick_cart_widget .notify_panel_close').trigger('click');
1215                    }
1216                    if ($('.content-overlay').hasClass('active')) {
1217                        $('.content-overlay .overlay-close-button').trigger('click');
1218                    }
1219                });
1220                
1221                var timer, el = $('#container_outer'), flag = false;
1222                $(window).add('#popup_content').scroll(function() {
1223                    var scrolling_element = $(this);
1224                    if (!flag) {
1225                        flag = true;
1226                        //if (!$('body').hasClass('content-swipe')) {
1227                            el.addClass('scrolling').removeClass('not-scrolling');
1228                            $(scrolling_element).addClass('scrolling').removeClass('not-scrolling');
1229		                //}
1230                    }
1231                    clearTimeout(timer);
1232                    timer = setTimeout(function() {
1233                        el.removeClass('scrolling').addClass('not-scrolling');
1234                        $(scrolling_element).removeClass('scrolling').addClass('not-scrolling');
1235                        flag = false;
1236                    }, 300, scrolling_element);
1237                });
1238                $('#container_outer').removeClass('scrolling').addClass('not-scrolling');
1239
1240                $('#popup_content').bind('scroll', window.site.throttle(50, function() {
1241                    if ($('#popup_content').scrollTop() > 30) {
1242                        $('body').addClass('popup-scrolled');
1243                        $('body').removeClass('popup-not-scrolled');
1244                    } else {
1245                        $('body').removeClass('popup-scrolled');
1246                        $('body').addClass('popup-not-scrolled');
1247                    }
1248                }));
1249                $('#popup_content').bind('scroll', window.site.debounce(200, function() {
1250                    if ($('#popup_content').scrollTop() > 30) {
1251                        $('body').addClass('popup-scrolled');
1252                        $('body').removeClass('popup-not-scrolled');
1253                    } else {
1254                        $('body').removeClass('popup-scrolled');
1255                        $('body').addClass('popup-not-scrolled');
1256                    }
1257                }));
1258                window.site.misc.extended_click_area();
1259
1260                // if (!$('.scroll-container .faux_footer').length && $('#footer').length) {
1261                // 	$('.scroll-container').append('<div class="faux_footer"></div>');
1262                // }
1263
1264                $(window).resize(function() {
1265                	window.site.layout.resize();
1266                });
1267                window.site.layout.resize();
1268        	},
1269            hero_text_adjust: function() {
1270             
1271            //   $('#hero .main_title').each(function() {
1272            //         var title = $(this).text(); // Froogaloop selector
1273            //         var char_len = title.length;
1274            //         console.log(title);
1275            //     });
1276    
1277             
1278            },
1279        	resize: function() {
1280        		if (false) {
1281	        		if (window.site.device.breakpoint() <= 2) {
1282	                   // $('body').removeClass('fixed-footer');
1283	                    $('#footer').css('min-height', '')
1284	                    $('.faux_footer').css('height', '');
1285	                } else {
1286	                    if ($('#footer .inner').outerHeight() <= $(window).height()) {
1287	                       // $('body').addClass('fixed-footer');
1288	                        $('#footer').each(function() {
1289	                            $(this).css('min-height', window.site.layout.window_height());
1290	                        });
1291	                        $('.faux_footer').each(function() {
1292	                            $(this).css('height', window.site.layout.window_height());
1293	                        });
1294	                    } else {
1295	                       // $('body').removeClass('fixed-footer');
1296	                        $('#footer').css('min-height', '')
1297	                        $('.faux_footer').css('height', '');
1298	                    }
1299	                }
1300        		}
1301
1302                if ($('.subsection-store-basket').length) {
1303                	var new_min_height = $(window).height();
1304                	$('#content_module').css('min-height', '0');
1305                	$('#sidebar').css('min-height', '0');
1306                	if ($('#sidebar').outerHeight() > $('#content_module').outerHeight()) {
1307                		var sidebar_height = $('#sidebar').outerHeight();
1308                		if (sidebar_height > new_min_height) {
1309                			var sidebar_height = sidebar_height;
1310                		}
1311                	}
1312                	if ($('#content_module').outerHeight() > $('#sidebar').outerHeight()) {
1313                		var content_height = $('#content_module').outerHeight();
1314                		if (content_height > new_min_height) {
1315                			var new_min_height = content_height;
1316                		}
1317                	}
1318                	$('#content_module, #sidebar').css('min-height', new_min_height);
1319				}
1320
1321        	},
1322
1323            window_height: function() {
1324                var window_height = $(window).height();
1325                var toolbar_height = $('body').hasClass('cms-frontend-toolbar-active') ? 28 : 0;
1326                return window_height - toolbar_height;
1327            },
1328
1329            window_height_extended: function() {
1330                var extended_height = (window.site.layout.window_height() / 100) * 10;
1331                return window.site.layout.window_height() + extended_height;
1332            },
1333
1334        	feature_panels: function() {
1335        		feature_panels_index = 0;
1336            	$('.scroll_section_panels section').each(function() {
1337        			feature_panels_index = feature_panels_index + 1;
1338            		$(this).attr('data-scrollinner-index', feature_panels_index);
1339            		$(this).addClass('panel_index_' + feature_panels_index);
1340            	});
1341            	$('.scroll_section_panels section[data-label="News"], .scroll_section_panels section[data-label="Publications"]').each(function() {
1342        			$(this).addClass('detail-linked-content-panel');
1343            	});
1344            	$( ".detail-linked-content-panel" ).last().addClass("last-detail-linked-content-panel");
1345            	$( ".detail-linked-content-panel" ).first().addClass("first-detail-linked-content-panel");
1346        	},
1347
1348        	navigation: function() {
1349
1350        	},
1351
1352        	grids: {
1353
1354        		init: function() {
1355
1356                    $('.image_list ul li')
1357                        .each(function() {
1358                            if ($(this).find("video").length) {
1359                                var el = $(this).find('video')[0];
1360                                el.currentTime = 0;
1361                                el.pause();
1362                            }
1363                        })
1364                        .hover(function () {
1365                            if (!window.site.device.handheld()) {
1366                                if ($(this).find("video").length) {
1367                                    var el = $(this).find('video')[0];
1368                                    el.currentTime = 0;
1369                                    el.play();
1370                                    $(this).addClass('video-reveal');
1371                                }
1372                            }
1373                        }, function () {
1374                            if (!window.site.device.handheld()) {
1375                                $(this).removeClass('video-reveal');
1376                                if ($(this).find("video").length) {
1377                                    var el = $(this).find('video')[0];
1378                                    el.pause();
1379                                }
1380                            }
1381                        })
1382                    ;
1383
1384        			$('.column_list').each(function() {
1385        				$(this).delay(500).queue(function() {
1386		                    $('.column_list ul:not(.visible)').each(function(i){
1387		                        var $item = $(this);
1388		                        setTimeout(function() {
1389		                            $item.addClass('visible');
1390		                        }, 200*i);
1391		                    });
1392        					$(this).clearQueue();
1393        				});
1394        			});
1395
1396        			$('.text_columns, .text_simple').each(function() {
1397        				$('.content_extended_text', this).each(function() {
1398        					$(this).closest('.content').addClass('extended_text_hidden');
1399        					
1400        					$(this).closest('.content').find('.content_reveal_more_link button').unbind().click(function() {
1401        						$(this).closest('.content').removeClass('extended_text_hidden');
1402        						$(this).closest('.content').addClass('extended_text_show');
1403        						$(this).closest('.content').find('.content_extended_text').focus();
1404        						return false;
1405        					});
1406        				});
1407        			});
1408
1409	                $('.records_grid.tile_grid').each(function() {
1410	                	if (!$('.tile_grid_original', this).length) {
1411		                    var original_html = $(this).html();
1412		                    var no_results_message = $(this).find('.filter_no_results_wrapper').clone();
1413		                    $(this).html('');
1414		                    $(this).append(no_results_message);
1415		                    $(this).append('<div class="tile_grid_formatted"></div>');
1416		                    $(this).append('<div class="tile_grid_original"></div>');
1417		                    $('.tile_grid_original', this).html(original_html).css('visibility', 'hidden');
1418	                	}
1419	                });
1420                    
1421        			window.site.layout.grids.resize();
1422        			setTimeout(function() {
1423        			    window.site.layout.grids.resize();
1424        			}, 200);
1425        			$(window).bind('resize', function() {
1426	        			window.site.layout.grids.resize();
1427	        		});
1428
1429	        		$('.records_grid.tile_grid')
1430	                    .each(function() {
1431	                        if ($('.tile_grid_formatted .item.revealable', this).length) {
1432		                        if (!$(this).find('.panel_footer_revealable_link').length) {
1433		                            $(this).append('<div class="panel_footer panel_footer_revealable_link"><div class="link link_more"><a href="#">View more artworks</a></div></div>');
1434		                            $(this).find('.link_more a').click(function() {
1435		                                var link_original_top_offset = $(this).offset().top - ($(window).height() / 2);
1436		                                var current_offset_top = $(window).scrollTop() - ($(window).height() / 2);
1437		                                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);
1438					                    if (window.site.device.breakpoint() <= 2) {
1439					                    	var items_to_reveal = parseInt(items_to_reveal) * 2;
1440					                    }
1441					                    $('body').addClass('scroll_event_disabled, window-forced-scroll-up');
1442
1443		                                // Extend the height of the container for a smoother opening effect
1444		                                var containing_group = $(this).closest('.records_grid').find('.tile_grid_formatted');
1445		                                var new_row_to_be_revealed = $(this).closest('.records_grid').find('.item.revealable').filter(':eq(0)');
1446		                                var containing_group_new_height = containing_group.height() + (new_row_to_be_revealed.height() * items_to_reveal);
1447		                                containing_group.css('height', containing_group.height());
1448		                                window.setTimeout(function() {
1449		                                	containing_group.css('height', containing_group_new_height);
1450		                                }, 20, containing_group);
1451
1452	                                	// Reveal the items
1453		                                $(this).closest('.tile_grid').find('.tile_grid_formatted > .group').each(function() {
1454		                                    $('.item.revealable:lt(' + items_to_reveal + ')', this).removeClass('revealable');
1455		                                });
1456		                                var remaining_revealable_items = $(this).closest('.tile_grid').find('.tile_grid_formatted > .group .item.revealable', this).length;
1457		                                if (remaining_revealable_items == 0) {
1458		                                    $(this).closest('.panel_footer_revealable_link').addClass('disabled');
1459		                                }
1460
1461		                                $('html,body').animate(
1462		                                    {scrollTop: link_original_top_offset},
1463		                                    1200,
1464		                                    'easeInOutExpo',
1465		                                    function() {
1466		                                    	window.setTimeout(function() {
1467			                                        $('body').removeClass('scroll_event_disabled, window-forced-scroll-up');
1468			                                    }, 500);
1469		                                        $(window).trigger('scroll');
1470	                                        	containing_group.css('height', '');
1471		                                    }
1472		                                );
1473		                                return false;
1474		                            });
1475		                        }
1476	                        }
1477	                    })
1478	                ;
1479
1480	                // Progressive grid format
1481
1482	        		$('.records_grid.progressive_grid').each(function() {
1483		        		if ($('.item.revealable', this).length) {
1484	                        if (!$(this).find('.panel_footer_revealable_link').length) {
1485	                            $(this).append('<div class="panel_footer panel_footer_revealable_link"><div class="link link_more"><a href="#">View more</a></div></div>');
1486                                $(this).find('.link_more a').unbind('click.records_grid').bind('click.records_grid', function() {
1487	                                var link_original_top_offset = $(this).offset().top - ($(window).height() / 4);
1488	                                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);
1489	        						if (window.site.device.breakpoint() == 1) {
1490										var rows_to_reveal = rows_to_reveal * 2;
1491	        						}
1492	                                var current_visible_row = $(this).closest('.records_grid').find('.item').not('.revealable').last().attr('data-row-number');
1493	                                $('body').addClass('scroll_event_disabled');
1494
1495	                                // Extend the height of the container for a smoother opening effect
1496	                                var containing_group = $(this).closest('.records_grid').find('.group');
1497	                                var new_row_to_be_revealed = $(this).closest('.records_grid').find('.item.revealable').filter(':eq(0)');
1498	                                var containing_group_new_height = containing_group.height() + (new_row_to_be_revealed.height() * rows_to_reveal);
1499	                                containing_group.css('height', containing_group.height());
1500	                                window.setTimeout(function() {
1501	                                	containing_group.css('height', containing_group_new_height);
1502	                                }, 20, containing_group);
1503
1504	                                // Reveal the items
1505	                                $(this).closest('.records_grid').each(function() {
1506	                                	for(var i=0; i < rows_to_reveal; i++){
1507										    var row_index = parseInt(current_visible_row) + (i + 1);
1508										    $('.item.revealable[data-row-number="' + row_index + '"]', this).addClass('revealed').removeClass('revealable');
1509										}
1510	                                });
1511	                                var remaining_revealable_items = $(this).closest('.records_grid').find('.item.revealable', this).length;
1512	                                if (remaining_revealable_items == 0) {
1513	                                    $(this).closest('.panel_footer_revealable_link').addClass('disabled');
1514	                                }
1515	                                $('html,body').animate(
1516	                                    {scrollTop: link_original_top_offset},
1517	                                    1200,
1518	                                    'easeInOutExpo',
1519	                                    function() {
1520	                                        $('body').removeClass('scroll_event_disabled');
1521	                                        $(window).trigger('scroll');
1522	                                        containing_group.css('height', '');
1523	                                    }
1524	                                );
1525	                                
1526	                                $(window).trigger('resize');
1527	                                return false;
1528	                            });
1529	                        }
1530	                    }
1531	        		});
1532	        		
1533	        		
1534	        		// Aligned grid format
1535
1536	        		$('.records_grid.aligned_grid, .records_list_slider').each(function() {
1537		        		if ($('.item.revealable', this).length) {
1538	                        if (!$(this).find('.panel_footer_revealable_link').length) {
1539	                            $(this).append('<div class="panel_footer panel_footer_revealable_link"><div class="link link_more"><a href="#">View more</a></div></div>');
1540	                            $(this).find('.link_more a').unbind('click.records_grid').bind('click.records_grid', function() {
1541	                                var link_original_top_offset = $(this).offset().top - ($(window).height() / 4);
1542	                                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);
1543	        						if (window.site.device.breakpoint() == 1) {
1544										var rows_to_reveal = rows_to_reveal * 2;
1545	        						}
1546	                                var current_visible_row = $(this).closest('.records_grid').find('.item').not('.revealable').last().attr('data-row-number');
1547	                                $('body').addClass('scroll_event_disabled');
1548	                                $(this).closest('.records_grid').each(function() {
1549	                                	for(var i=0; i < rows_to_reveal; i++){
1550										    var row_index = parseInt(current_visible_row) + (i + 1);
1551										    $('.item.revealable[data-row-number="' + row_index + '"]', this).addClass('revealed').removeClass('revealable');
1552										}
1553	                                });
1554	                                var remaining_revealable_items = $(this).closest('.records_grid').find('.item.revealable', this).length;
1555	                                if (remaining_revealable_items == 0) {
1556	                                    $(this).closest('.panel_footer_revealable_link').addClass('disabled');
1557	                                }
1558	                                $('html,body').animate(
1559	                                    {scrollTop: link_original_top_offset},
1560	                                    400,
1561	                                    'easeInOutExpo',
1562	                                    function() {
1563	                                        $('body').removeClass('scroll_event_disabled');
1564	                                        $(window).trigger('scroll');
1565	                                    }
1566	                                );
1567	                                $(window).trigger('resize');
1568	                                return false;
1569	                            });
1570	                        }
1571	                    }
1572	        		});
1573	        		
1574	        		window.site.layout.grids.css_image_cropping.init();
1575
1576        		},
1577        		set_item_min_height: function($element) {
1578                    // Set the size of the image container as a placeholder for lazyload
1579                    var item_width = $element.find('.image').width();
1580    				var image_width = $element.attr('data-width');
1581    				var image_height = $element.attr('data-height');
1582    				var image_width_proportional = 0;
1583    				var image_height_proportional = 0;
1584
1585
1586    				if (image_width && image_height) {
1587    					var image_width_proportional = item_width / image_width;
1588    					var image_height_proportional = image_height * image_width_proportional;
1589    					if (image_height_proportional) {
1590    						$element.find('.image').css('min-height', image_height_proportional);
1591    						if ($element.parents('.text_columns').length) {
1592                                $element.closest('.text_columns').css('min-height', image_height_proportional);
1593                            }
1594    						
1595    					}
1596    				}
1597    				
1598    				if ($('.text_columns .aside').height() > $('.text_columns').height()) {
1599    				    $('.text_columns').css('min-height', $('.text_columns .aside').height())
1600    				} 
1601    
1602                },
1603                tile_list_append_refresh: function(tile_list_instance) {
1604                    
1605                    //Refreshes the visible tile list (tile_list_formatted) after manually appending list items to the tile_list_original, for example after list-ajax-load-more button is used
1606                    var column_count = tile_list_instance.find('.tile_grid_formatted .group').length;
1607                    var $tile_list_formatted = $('.tile_grid_formatted', tile_list_instance);
1608    
1609                    var columns = {}
1610                    $.each(Array(column_count), function(index, value) {
1611                        columns[index] = {'height': 0, 'objects': []};
1612                    });
1613                    
1614                    
1615                    // Work out columns with all items in tile_list_original, not just the incoming ones. 
1616                    // This ensures that we retain all of the correct column heights - exactly as if we were building the list from scratch.
1617                    
1618                    //TODO this code that sorts items into columns is basically a duplication of the same funcationality in tile_list_init. 
1619                    $('.tile_grid_original .item', tile_list_instance).each(function(index) {
1620                            
1621                        if ($(this).attr('data-width') && $(this).attr('data-height')) {
1622                            var data_width = $(this).attr('data-width');
1623                            var data_height = $(this).attr('data-height');
1624                        } else {
1625                            var data_width, data_height = '400';
1626                            console.warn('tile_list_init: Width and height of each image is required as a data attribute for this script to work.');
1627                        }
1628                        var height_to_width_factor = parseInt(data_width) / tile_list_column_width;
1629                        var relative_item_height = Math.ceil(parseInt(data_height) / height_to_width_factor);
1630                        var lowest_height_index = 0;
1631                        if (columns[0] && typeof columns[0] != 'undefined') {
1632                            var loop_current_lowest_height = columns[0]['height'];
1633                            $.each(columns, function(index, value) {
1634                                if ((value.height < loop_current_lowest_height)) {
1635                                    lowest_height_index = index;
1636                                    loop_current_lowest_height = value.height;
1637                                }
1638                            });
1639                            columns[lowest_height_index]['height'] = columns[lowest_height_index]['height'] + relative_item_height;
1640                            columns[lowest_height_index]['objects'].push($(this).clone().find('.video_inline').remove().end());
1641                        }
1642                    });
1643    
1644    
1645                    $.each(columns, function(index, value) {
1646                        
1647                        var $formatted_column = $tile_list_formatted.find('.group:eq('+index+')');
1648                        
1649                        //Check how many items are already in the visible column
1650                        var existing_items_in_visible_col = $formatted_column.find('.item').length;
1651                        
1652                        //Append all items in column object from the existing length to the total length
1653                        $formatted_column.append(value.objects.slice( existing_items_in_visible_col, value.objects.length));
1654                        
1655                        $tile_list_formatted.find('.video_inline').remove();
1656                        $tile_list_formatted.find('.item').each(function() {
1657                            window.site.layout.grids.set_item_min_height($(this));
1658                        });
1659                        
1660                    });
1661    
1662    	            // Re-initialise functions necessary on the newly created tile list
1663    	            window.site.artlogic_inview.init();
1664    	            window.site.lazy_load.init();
1665                    $.pageload.refresh(tile_list_instance);
1666    	            window.site.overlays.enquire.setup();
1667    	            window.cart.add_to_cart($(tile_list_instance).find('.store_item .store_item_add_to_cart'));
1668                    window.cart.add_to_wishlist($(tile_list_instance).find('.add_to_wishlist'));
1669    	            window.cart.remove_from_wishlist($(tile_list_instance).find('.store_item_remove_from_wishlist'));
1670    
1671                },
1672                css_image_cropping: {
1673                    /*
1674                        Simple polyfill for image grids that use object-fit css for 'soft' cropping.
1675                        Mostly required for all versions of Internet Explorer and older versions of Edge.
1676                    */
1677                    init: function() {
1678                        
1679                        var polyfill_images = '.artwork_detail .images .image.image_half_bleed .image_wrap img,' +
1680                                              '.artwork_detail .image_gallery_multiple_thumbnails ul li a img, ' +
1681                                              '.media_wrapper .video_background video, ' +
1682                                              '.standard_grid .item .image img, ' +
1683                                              '.full_bleed_panel .image img, ' +
1684                                              '.full_bleed_panel_slideshow .image img, ' +
1685                                              '.large_grid .item .image img, ' +
1686                                              '.image_list ul li .image img, ' +
1687                                              '.image_list ul li .image video, ' +
1688                                              '.list-preview-image .list-preview-image-items .item img, ' +
1689                                              '.list-preview-image .list-preview-image-items .item .video video, ' +
1690                                              '.nav_dropdown_grid .item .image img, ' +
1691                                              '.records_list_slider .item .image > span > a > img, ' +
1692                                              '.records_list_slider .item .image > span > img, ' +
1693                                              '.page-track-scroll-container .image-wrapper video, ' +
1694                                              '.content-overlay .overlay-container-inner .image_area img';
1695                        var verbose = false;
1696                        if ($(polyfill_images).length){
1697                            if (verbose){
1698                                console.log('css_image_cropping -- grid imgs on page');
1699                            }
1700                            var objectfitcover_on_page = $(polyfill_images).filter(function() {
1701                                // If css cropping is being used, we pass a flag - a font-family on an impossible pseudo-element (invisible) from user_custom.css
1702                                return window.getComputedStyle($(this)[0]).getPropertyValue('font-family') == ('object-fit');
1703                            });
1704    
1705                            if (objectfitcover_on_page.length) {
1706                                if (verbose){
1707                                    console.log('css_image_cropping -- object-fit used in grid, polyfill checking for support');
1708                                }
1709                                
1710                                var supportsObjectfit;
1711                                
1712                                // Detect whether '@supports' CSS is supported, preventing errors in IE
1713                                var supports_supportsCSS = !!((window.CSS && window.CSS.supports) || window.supportsCSS || false);
1714    
1715                                if (supports_supportsCSS){
1716                                    // Older Edge supports '@supports' but not object-fit
1717                                    supportsObjectfit = CSS.supports('object-fit','cover');
1718                                } else {
1719                                    //IE doesn't support '@supports' or 'object-fit', so we can consider them the same
1720                                    supportsObjectfit = false;
1721                                }
1722    
1723                                if (!supportsObjectfit || typeof supportsObjectfit == 'undefined') {
1724                                   
1725                                    if (verbose){
1726                                        console.log('css_image_cropping -- polyfill running');
1727                                    }
1728                                    $(polyfill_images).each(function() {
1729                                        var $img = $(this);
1730                                        if ($img.attr('data-src') && typeof $img.attr('data-src') != 'undefined') {
1731                                            var imageURL = $img.attr('data-src');
1732                                        } else {
1733                                            var imageURL = $img.attr('src');
1734                                        }
1735                                        if (window.getComputedStyle($img[0], ':first-letter').getPropertyValue('font-family') == 'object-fit' && imageURL) {
1736                                            var bg_positioning = '50% 50%';
1737                                            if ($img.css('object-position')) {
1738                                                var positioning = $img.css('object-position');
1739                                            }
1740                                            $img.parent().addClass('objectfit-fallback-bg').css({'background-image':'url('+imageURL+')','background-position':bg_positioning});
1741                                            $img.css('visibility','hidden');
1742                                            
1743                                            if (!$('body').hasClass('objectfit-polyfill-active')){
1744                                                $('body').addClass('objectfit-polyfill-active')
1745                                            }
1746                                        }
1747                                    });
1748                                } else {
1749                                    if (verbose){
1750                                        console.log('css_image_cropping -- polyfill not required, object-fit supported');
1751                                    }
1752                                }
1753                            }
1754                        }
1755                    },
1756                },
1757        	    resize: function() {
1758
1759        // 			$('.records_grid.medium_grid, .records_grid.large_grid').each(function() {
1760	       // 			$('.item', this).each(function() {
1761	       // 				var item_width = $(this).find('.image').width();
1762	       // 				var image_width = $(this).attr('data-width');
1763	       // 				var image_height = $(this).attr('data-height');
1764	       // 				var image_width_proportional = 0;
1765	       // 				var image_height_proportional = 0;
1766	       // 				if (image_width && image_height) {
1767	       // 					var image_width_proportional = item_width / image_width;
1768	       // 					var image_height_proportional = image_height * image_width_proportional;
1769	       // 					$(this).find('.image').not('.has_video').find('img').css('max-height', '');
1770	       // 					if (image_height_proportional > item_width) {
1771	       // 						// Set a maximum height based on a square proportion
1772	       // 						var image_height_proportional = item_width;
1773	       // 						$(this).find('.image').not('.has_video').css('max-height', image_height_proportional);
1774	       // 						$(this).find('.image').not('.has_video').find('img').css('max-height', image_height_proportional);
1775	       // 					}
1776	       // 			// 		if (image_height_proportional) {
1777	       // 			// 			$(this).find('.image').not('.has_video').css('min-height', image_height_proportional);
1778	       // 			// 		}
1779	       // 				}
1780	       // 			});
1781	       // 		});
1782
1783
1784					$('.records_grid.tile_grid').each(function() {
1785
1786	                    if ($('.tile_grid_original .group', this).length) {
1787
1788	                        // Check if the script has already been run before and set variables
1789	                        if ($(this).hasClass('initialised')) {
1790	                            init_rerun = true;
1791	                            existing_formatted_list_column_count = $('.tile_grid_formatted .group', this).length;
1792	                        } else {
1793	                            $(this).addClass('initialised');
1794	                            init_rerun = false;
1795	                        }
1796
1797	                        // Start initialising the new list
1798
1799	                        init_allowed = true;
1800
1801	                        $('.tile_grid_original', this).removeClass('hidden');
1802
1803	                        tile_list_instance = $(this);
1804	                        tile_list_width = $(this).width();
1805	                        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')));
1806	                        var column_count = 3;
1807	                        var column_count_calculated = Math.floor(tile_list_width / tile_list_column_width);
1808	                        if (column_count_calculated < 7) {
1809	                            var column_count = column_count_calculated;
1810	                        }
1811
1812	                        if (init_rerun) {
1813	                            // If the script is being run again, check if the column count is different to before. If not, stop the list from being rebuilt.
1814	                            if (existing_formatted_list_column_count == column_count) {
1815	                                init_allowed = false;
1816	                            }
1817	                        }
1818
1819	                        if (init_allowed) {
1820	                            var columns = {}
1821	                            var fixed_list_order = $(this).closest('.tile_grid').attr('data-list-order') == 'fixed' ? true : false;
1822	                            column_loop = 0;
1823	                            column_count = Array(column_count).length;
1824	                            $.each(Array(column_count), function(index, value) {
1825                                    var this_height = 0;
1826	                                columns[index] = {'height': this_height, 'objects': []};
1827	                            });
1828	                            $('.tile_grid_original .item', this).each(function() {
1829                                    var content_height = $(this).find('.area').height();
1830                                    var item_index = $(this).index()+1;
1831                                    var total_item_count = $('.tile_grid_original .item').length;
1832	                                if (!$(this).attr('data-width') || !$(this).attr('data-height')) {
1833	                                	$(this).attr('data-width', '400');
1834	                                	$(this).attr('data-height', '400');
1835	                                    console.log('Width and height of each image is required as a data attribute for this script work.');
1836	                                }
1837                                    var height_to_width_factor = parseInt($(this).attr('data-width')) / tile_list_column_width;
1838                                    var relative_item_height = Math.ceil(parseInt($(this).attr('data-height')) / height_to_width_factor);
1839                                    
1840                                    if (Object.keys(columns).length) {
1841                                        if (fixed_list_order) {
1842                                        	// Fixed order, do not automatically find lowest height
1843    	                                    lowest_height_index = column_loop;
1844                                        	column_loop = column_loop + 1;
1845    	                                    if (column_loop >= column_count) {
1846                                        		column_loop = 0;
1847    	                                    }
1848                                        } else {
1849                                        	// Dynamic order based on shortest column height
1850    	                                    lowest_height_index = 0;
1851    	                                    loop_current_lowest_height = columns[0]['height'];
1852    	                                    $.each(columns, function(index, value) {
1853                                                if (item_index == total_item_count && total_item_count > 3) {
1854                                                    // If last item, behave in a different way
1855                                                    // It is more likely the item should be placed on the left hand side
1856                                                    // Check the final height 'after' the item would be placed to determine if it should revert to the first column
1857                                                    if (index == 0) {
1858                                                        lowest_height_index = index;
1859                                                        loop_current_lowest_height = value.height;
1860                                                    }
1861                                                    var first_column_height = columns[0].height;
1862                                                    if ((value.height + (relative_item_height * 0.2) < loop_current_lowest_height)) {
1863                                                        lowest_height_index = index;
1864                                                        loop_current_lowest_height = value.height;
1865                                                    }
1866                                                } else {
1867                                                    if ((value.height < loop_current_lowest_height)) {
1868                                                        lowest_height_index = index;
1869                                                        loop_current_lowest_height = value.height;
1870                                                    }
1871                                                }
1872    	                                    });
1873                                        }
1874                                        columns[lowest_height_index]['height'] = columns[lowest_height_index]['height'] + relative_item_height + content_height;
1875                                        columns[lowest_height_index]['objects'].push($(this).clone().find('.video_inline').remove().end());
1876                                    }
1877	                            });
1878
1879	                            $('.tile_grid_formatted', tile_list_instance).html('');
1880	                            $.each(columns, function(index, value) {
1881	                                $('.tile_grid_formatted', tile_list_instance).append('<div class="group"></div>');
1882	                                $('.tile_grid_formatted', tile_list_instance).find('.group:last-child').append(value.objects);
1883	                            });
1884	                            $('.tile_grid_formatted', tile_list_instance).find('.group:last-child').addClass('last');
1885
1886					            $('.tile_grid_formatted', tile_list_instance).find('.group').each(function() {
1887                                    var column_count = $(this).closest('.tile_grid_formatted').find('.group').length;
1888					                if ($(this).closest('.tile_grid').attr('data-initial-items') == '0') {
1889
1890					                } else if (parseInt($(this).closest('.tile_grid').attr('data-initial-rows'))) {
1891                                        var initial_items = $(this).closest('.tile_grid').attr('data-initial-rows');
1892                                        var initial_items_per_column = parseInt(initial_items / column_count);
1893					                    if (window.site.device.breakpoint() <= 2) {
1894					                    	var initial_items_per_column = parseInt(initial_items_per_column) * 2;
1895					                    }
1896					                    $('.item', this).addClass('revealable');
1897					                    //console.log(initial_items_per_column);
1898					                    $('.item:lt(' + initial_items_per_column + ')', this).removeClass('revealable');
1899					                } else {
1900					                    var initial_items_per_column = window.site.lists.tile_list_options().initial_items_per_column;
1901					                    if (window.site.device.breakpoint() <= 2) {
1902					                    	var initial_items_per_column = parseInt(initial_items_per_column) * 2;
1903					                    }
1904					                    $('.item', this).addClass('revealable');
1905					                    $('.item:lt(' + initial_items_per_column + ')', this).removeClass('revealable');
1906					                }
1907					            });
1908
1909					            // Re-initialise functions necessary on the newly created tile list
1910					            window.site.artlogic_inview.init();
1911                                $.pageload.refresh(tile_list_instance);
1912					            window.site.overlays.enquire.setup();
1913					            window.cart.add_to_cart($(tile_list_instance).find('.store_item .store_item_add_to_cart'));
1914                                window.cart.add_to_wishlist($(tile_list_instance).find('.add_to_wishlist'));
1915					            window.cart.remove_from_wishlist($(tile_list_instance).find('.store_item_remove_from_wishlist'));
1916					            $(".extended_click_area").removeClass('click_event_added')
1917            					window.site.misc.extended_click_area();
1918
1919	                        }
1920
1921                            $('.tile_grid_original', this).addClass('hidden');
1922	                    }
1923
1924						// Set the heights of each image based on the proportion, this defines the available area before the images have loaded
1925	        			$('.tile_grid_formatted .item', this).each(function() {
1926	        				var item_width = $(this).find('.image').width();
1927	        				var image_width = $(this).attr('data-width');
1928	        				var image_height = $(this).attr('data-height');
1929	        				var image_width_proportional = 0;
1930	        				var image_height_proportional = 0;
1931	        				if (image_width && image_height) {
1932	        					var image_width_proportional = item_width / image_width;
1933	        					var image_height_proportional = image_height * image_width_proportional;
1934	        					if (image_height_proportional) {
1935	        						$(this).find('.image').css('min-height', image_height_proportional);
1936	        					}
1937	        				}
1938	        			});
1939
1940						// If there are as many or less items than there are columns, align the items by the bottom of each image
1941				// 		if ($('.tile_grid_formatted .group', this).length >= $('.tile_grid_formatted .item', this).length) {
1942			 //       		$('.tile_grid_formatted .item', this).each(function() {
1943		  //      				var this_image_height = $(this).find('.image').height();
1944		  //      				$(this).closest('.tile_grid_formatted').find('.item').each(function() {
1945	   //     						if ($(this).find('.image').height() < this_image_height) {
1946	   //     							$(this).find('.image').css('min-height', this_image_height);
1947	   //     						}
1948		  //      				});
1949		  //      			});
1950				// 		}
1951	                });
1952
1953
1954					// Progressive grid format
1955
1956	        		$('.records_grid.progressive_grid').each(function() {
1957
1958	        			initial_rows = $(this).attr('data-initial-rows') && typeof $(this).attr('data-initial-rows') != 'undefined' ? $(this).attr('data-initial-rows') : false;
1959	        			if (window.site.device.breakpoint() <= 2) {
1960	        				initial_rows = parseInt(initial_rows) * 4;
1961	        			}
1962	        			row_number = 0;
1963	        			row_offset = 0;
1964
1965	        			// $('.item', this).each(function() {
1966	        			// 	var item_width = $(this).find('.image').width();
1967	        			// 	var image_width = $(this).attr('data-width');
1968	        			// 	var image_height = $(this).attr('data-height');
1969	        			// 	var image_width_proportional = 0;
1970	        			// 	var image_height_proportional = 0;
1971	        			// 	if (image_width && image_height) {
1972	        			// 		var image_width_proportional = item_width / image_width;
1973	        			// 		var image_height_proportional = image_height * image_width_proportional;
1974	        			// 		if (image_height_proportional) {
1975	        			// 			$(this).find('.image').css('min-height', image_height_proportional);
1976	        			// 		}
1977	        			// 	}
1978	        			// 	$(this).removeClass('revealable');
1979	        			// });
1980	        			
1981		        		$('.item', this).each(function() {
1982	        				// Find adjacent elements
1983
1984                        	$(this).addClass('parallax-resizing');
1985	        				var offset_top = $(this).offset().top;
1986	        				var this_image_height = $(this).find('.image').height();
1987	        				if (offset_top > row_offset) {
1988	        					row_number = row_number + 1;
1989	        					row_offset = offset_top;
1990	        				}
1991	        				$(this).attr('data-row-number', row_number);
1992                        	$(this).removeClass('parallax-resizing');
1993	        			});
1994	        			$('.item', this).not('.revealed').each(function() {
1995	        				// Hide revealable elements
1996
1997	        				var row_number = $(this).attr('data-row-number');
1998	        				if (row_number && parseInt(row_number) > parseInt(initial_rows)) {
1999    							$(this).addClass('revealable');
2000    						}
2001	        			});
2002	        		});
2003
2004
2005					// Aligned grid format
2006
2007	        		$('.records_grid.aligned_grid').each(function() {
2008
2009	        			initial_rows = $(this).attr('data-initial-rows') && typeof $(this).attr('data-initial-rows') != 'undefined' ? $(this).attr('data-initial-rows') : false;
2010	        			row_number = 0;
2011	        			row_offset = 0;
2012
2013	        			$('.item', this).each(function() {
2014	        				var item_width = $(this).find('.image').width();
2015	        				var image_width = $(this).attr('data-width');
2016	        				var image_height = $(this).attr('data-height');
2017	        				var image_width_proportional = 0;
2018	        				var image_height_proportional = 0;
2019	        				if (image_width && image_height) {
2020	        					var image_width_proportional = item_width / image_width;
2021	        					var image_height_proportional = image_height * image_width_proportional;
2022	        					if (image_height_proportional) {
2023	        						$(this).find('.image').css('min-height', image_height_proportional);
2024	        					}
2025	        				}
2026	        				$(this).removeClass('revealable');
2027	        			});
2028		        		$('.item', this).each(function() {
2029	        				// Find adjacent elements
2030	        				var offset_top = $(this).offset().top;
2031	        				var this_image_height = $(this).find('.image').height();
2032	        				if (offset_top > row_offset) {
2033	        					row_number = row_number + 1;
2034	        					row_offset = offset_top;
2035	        				}
2036	        				$(this).parent().find('.item').each(function() {
2037	        					if ($(this).offset().top == offset_top) {
2038	        						$(this).attr('data-row-number', row_number);
2039	        						if ($(this).find('.image').height() < this_image_height) {
2040	        							$(this).find('.image').css('min-height', this_image_height);
2041	        						}
2042	        					}
2043	        				});
2044	        			});
2045	        			$('.item', this).not('.revealed').each(function() {
2046	        				// Hide revealable elements
2047
2048	        				var row_number = $(this).attr('data-row-number');
2049	        				if (row_number && parseInt(row_number) > parseInt(initial_rows)) {
2050    							$(this).addClass('revealable');
2051    						}
2052	        			});
2053	        		});
2054
2055	        		
2056	        		
2057					$('.works_grid .item, .standard_grid .item, .medium_grid .item, .large_grid .item').unbind()
2058						// tile mouse actions
2059						.on('mouseover', function(){
2060							var image_width = $(this).find('.image').width();
2061							var scale = '1.02';
2062							if (image_width > 400) {
2063								var scale = '1.01';
2064							}
2065							if (image_width > 600) {
2066								var scale = '1.05';
2067							}
2068							//$(this).find('.image img').css({'transform': 'scale(' + scale + ')'});
2069						})
2070						.on('mouseout', function(){
2071							//$(this).find('.image img').css({'transform': 'scale(1)'});
2072						})
2073						.on('mousemove', function(e){
2074							// 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 +'%'});
2075						})
2076					;
2077
2078        		}
2079
2080        	},
2081
2082        	textillate: function() {
2083
2084        		$('.text_animate').textillate({
2085	              // the default selector to use when detecting multiple texts to animate
2086	              selector: '.texts',
2087
2088	              // enable looping
2089	              loop: false,
2090
2091	              // sets the minimum display time for each text before it is replaced
2092	              minDisplayTime: 2000,
2093
2094	              // sets the initial delay before starting the animation
2095	              // (note that depending on the in effect you may 
2095need to manually apply
2096	              // visibility: hidden to the element before running this plugin)
2097	              initialDelay: 0,
2098
2099	              // set whether or not to automatically start animating
2100	              autoStart: true,
2101
2102	              // in animation settings
2103	              in: {
2104	                // set the effect name
2105	                effect: 'fadeInUp',
2106
2107	                // set the delay between each character
2108	                delay: 7,
2109
2110	                // set to true to animate all the characters at the same time
2111	                sync: false,
2112
2113	                // randomize the character sequence
2114	                // (note that shuffle doesn't make sense with sync = true)
2115	                shuffle: false,
2116
2117	                // reverse the character sequence
2118	                // (note that reverse doesn't make sense with sync = true)
2119	                reverse: false,
2120
2121	                // callback that executes once the animation has finished
2122	                callback: function () {}
2123	              },
2124
2125	              // out animation settings.
2126	              out: {
2127	                // set the effect name
2128	                effect: 'fadeOutUp',
2129
2130	                // set the delay between each character
2131	                delay: 3,
2132	                sync: false,
2133	                shuffle: false,
2134	                reverse: false,
2135	                callback: function () {}
2136	              },
2137
2138	              // callback that executes once textillate has finished
2139	              callback: function () {},
2140
2141	              // set the type of token to animate (available types: 'char' and 'word')
2142	              type: 'char'
2143	            });
2144
2145        	},
2146
2147            hero: {
2148
2149                init: function() {
2150
2151                    $('#hero').each(function() {
2152
2153                        $('#hero .slide .image').each(function() {
2154                            var related_link = $(this).closest('.slide').find('a:eq(0)');
2155                            if (related_link && typeof related_link != 'undefined') {
2156                                $(this).css('cursor', 'pointer').unbind('click').bind('click', function() {
2157                                    related_link.trigger('click');
2158                                });
2159                            }
2160                        });
2161
2162                        scroll_to_content = function() {
2163                            var scroll_offset = $('.scroll_section').not('.scroll_section_top').filter(':eq(0)').offset().top - ($(window).height() * 0.05);
2164                            setTimeout(function() {
2165                                $('html, body').on('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function(){
2166                                    $('html, body').stop();
2167                                });
2168                            }, 400);
2169                            $('html, body').animate({'scrollTop': scroll_offset}, 1200, 'easeInOutExpo', function() {
2170                                $('html, body').off('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove');
2171                            });
2172                        };
2173                        $('#hero .scroll').click(function() {
2174                            scroll_to_content();
2175                            return false;
2176                        });
2177
2178                        $('#hero .arrow').click(function() {
2179                            scroll_to_content();
2180                            return false;
2181                        });
2182                    });
2183                
2184                }
2185
2186            }
2187
2188        },
2189
2190        scroll: {
2191
2192            smooth_scroll_enabled: false, // true
2193            smooth_scroll_active: false,
2194
2195            settings: {
2196                'scroll_section_elements': '.scroll-section',
2197                'scroll_parallax_elements': '.scroll-parallax', // Enable parallax functionality on these elements
2198                'scroll_parallax_overflow_elements': '.scroll-parallax-overflow' // List parallax elements which need to overflow e.g. full screen backgrounds
2199            },
2200
2201            init: function() {
2202                window.site.scroll.layout();
2203                window.site.scroll.smooth_scroll.init();
2204                window.site.scroll.events.init();
2205                window.site.scroll.navigation();
2206                window.site.scroll.dropdown_navigation.init();
2207            },
2208
2209            layout: function() {
2210
2211	            curslide = 0;
2212
2213                last_scroll_position = $(window).scrollTop();
2214            	$('#container_outer').removeClass('scrolling-down scrolling-up');
2215
2216                $('.pageload-content-area').each(function() {
2217                    scroll_section_index = 0;
2218                	$('.scroll_section', this).each(function() {
2219                    	    if ($(this).not(':has(div#hero)').length){
2220                    		//$(this).css('min-height', window.site.layout.window_height());
2221                			scroll_section_index = scroll_section_index + 1;
2222                    		$(this).attr('data-scrollinner-index', scroll_section_index);
2223                    		$(this).addClass('section_index_' + scroll_section_index);
2224                	    }
2225
2226                	});
2227                });
2228
2229	            if (typeof page_intro_timeout != 'undefined') {
2230	            	clearTimeout(page_intro_timeout);
2231	            	clearTimeout(page_intro_timeout2);
2232	            }
2233	            $('#container_outer').addClass('page-intro page-intro-start');
2234	            page_intro_timeout = setTimeout(function() {
2235					$('#container_outer').addClass('page-intro-1');
2236	            }, 400);
2237	            page_intro_timeout = setTimeout(function() {
2238					$('#container_outer').removeClass('page-intro-start');
2239	            }, 1800);
2240	            page_intro_timeout2 = setTimeout(function() {
2241					$('#container_outer').removeClass('page-intro page-intro-1 page-intro-start');
2242	            }, 2800);
2243
2244	            $('#container')
2245	            	.addClass('scroll-section-setup')
2246	            	.delay(1000)
2247	            	.queue(function () {
2248			            $('#container')
2249			            	.removeClass('scroll-section-setup')
2250			            ;
2251			            $(this).dequeue();
2252	            	})
2253	            ;
2254	            
2255	            loopcount = 0;
2256	            $('.scroll_section').each(function(i) {
2257	                $(this).attr('data-scroll-index', i+1);
2258	                if (parseInt($(this).offset().top) == $(window).scrollTop()) {
2259	                    $(this).addClass('active active_completed');
2260	                }
2261	            });
2262            },
2263
2264            events: {
2265
2266                init: function() {
2267
2268                    last_scroll_position = 0;
2269                    scrolling_down_offset = 50;
2270                    // This improves scroll performance in chrome, why?
2271                    $(window).bind('scroll', function() {
2272	                    if ($('.artwork_hero_image_container_outer').length && !$('#popup_content .artwork_hero_image_container_outer').length) {
2273	                    	var hero_max_height = ($(window).height() - $(window).scrollTop()) + 200;
2274	                    	if (hero_max_height < 0) {
2275	                    		var hero_max_height = 0;
2276	                    	}
2277	                    	$('.artwork_hero_image_container_outer').css('max-height', hero_max_height);
2278	                    }
2279                    });
2280                    $(window).bind('scroll', window.site.throttle(50, function() {
2281                        window.site.scroll.events.run();
2282                    }));
2283                    $(window).bind('scroll', window.site.debounce(200, function() {
2284                        window.site.scroll.events.run();
2285                    }));
2286                    window.site.scroll.events.run();
2287                },
2288
2289                run: function() {
2290                    if ($(window).scrollTop() > 0) {
2291                        if (last_scroll_position > $(window).scrollTop()) {
2292                            if (last_scroll_position + 5 > $(window).scrollTop()) {
2293                                if (!$('body').hasClass('window-forced-scroll-up')) {
2294                                    if (!$('body').hasClass('page-popup-active') && !$('body').hasClass('overlay-open')) {
2295                                        $('#container_outer').addClass('scrolling-up');
2296                                        $('#container_outer').removeClass('scrolling-down');
2297                                    }
2298                                }
2299                            }
2300                        } else {
2301                            if ($(window).scrollTop() > last_scroll_position) {
2302                                if ($(window).scrollTop() > scrolling_down_offset) {
2303                                    if (!$('body').hasClass('page-popup-active') && !$('body').hasClass('overlay-open')) {
2304                                        $('#container_outer').removeClass('scrolling-up');
2305                                        $('#container_outer').addClass('scrolling-down');
2306                                    }
2307                                }
2308                            }
2309                        }
2310                    } else {
2311                        $('#container_outer').removeClass('scrolling-down scrolling-up');
2312                    }
2313                    if ($('body').hasClass('page-popup-visible')) {
2314                        $('#container_outer').removeClass('page-top');
2315                    } else {
2316                        if ($(window).scrollTop() > 100) {
2317                            if ($('#container_outer').hasClass('page-top')) {
2318                                $('#container_outer').addClass('page-scrolled');
2319                                $('#container_outer').removeClass('page-top');
2320                            }
2321                        } else {
2322                            if (!$('#container_outer').hasClass('page-top')) {
2323                                $('#container_outer').removeClass('page-scrolled');
2324                                $('#container_outer').addClass('page-top');
2325                            }
2326                        }
2327                    }
2328                    window.site.scroll.subnav_active_change();
2329                    last_scroll_position = $(window).scrollTop();
2330                }
2331                    
2332            },
2333
2334            navigation: function() {
2335         
2336        		$('#header #page_header').remove();
2337        		$('#header').removeClass('page-header-subsections');
2338        		
2339                if ($('.scroll_section_panels').hasClass('scroll_section_panels_has_nav')) {
2340                        
2341                    if (!$('#feature_panel_section_nav').length) {
2342                        $('.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>')
2343                    }
2344                    
2345                    if ($('#main_content h1').length) {
2346                        var page_heading_element = $('#main_content h1:eq(0)');
2347                        if (page_heading_element.find('.text_animate .texts li').length) {
2348                            var page_heading = page_heading_element.find('.text_animate .texts li:eq(0)').text();
2349                        } else {
2350                            var page_heading = $('#main_content h1:eq(0)').text();
2351                        }
2352                        $('#feature_panel_section_nav h2').text(page_heading).wrap('<span class="page_header_wrapper"><span class="page_header_inner"></span></span>');
2353                    }
2354    
2355                    if ($('#feature_panel_section_nav').length && !$('#feature_panel_section_nav').hasClass('side_nav_filters')) {
2356                        jQuery.fn.reverse = [].reverse;
2357                        $('.feature_panels section').each(function() {
2358                            var this_label = $(this).attr('data-label');
2359                            var this_index = $(this).attr('data-scrollinner-index');
2360                            if (this_label && this_index && typeof this_label != 'undefined' && typeof this_index != 'undefined') {
2361                                $('#feature_panel_section_nav ul').append('<li data-index="' + this_index + '"><a tabindex="-1">' + this_label + '</a></li>');
2362                            } else {
2363                                $('#feature_panel_section_nav ul').append('<li data-index="' + this_index + '" class="no-label"></li>');
2364                            }
2365                        });
2366    
2367                        if ($('#feature_panel_section_nav ul li').not('.no-label').length <= 1) {
2368                            $('#feature_panel_section_nav').addClass('nav-hidden');
2369                        } else {
2370                            $('#feature_panel_section_nav').removeClass('nav-hidden');
2371                        }
2372                    }
2373                    
2374            		var new_page_header_content = $('#feature_panel_section_nav').length ? $('#feature_panel_section_nav').html() : '';
2375            		if (!$('#header #page_header').length) {
2376            			$('#header_main_inner').append('<div id="page_header"></div>')
2377            		}
2378            		$('#header #page_header').html(new_page_header_content);
2379            		if (new_page_header_content != '') {
2380            			$('#header').addClass('page-header-subsections');
2381            		}
2382                    
2383                    $('#feature_panel_section_nav ul li, #page_header ul li').unbind().click(function() {
2384                        $('body').addClass('window-forced-scroll-up');
2385                        var this_index = $(this).attr('data-index');
2386                        var related_item = $('.feature_panels section[data-scrollinner-index="' + this_index + '"]');
2387                        if (related_item.length) {
2388                            var direction = (related_item.offset().top > $(window).scrollTop() ? 'down' : 'up');
2389                            if (false && $('#header').length > 0 && direction == 'up') {
2390                                var offset = 100;
2391                                var offset = offset + $('#header').outerHeight();
2392                            } else {
2393                                var offset = 40;
2394                            }
2395                            if ($('#cms-frontend-toolbar-container').length > 0) {
2396                                var offset = offset + $('#cms-frontend-toolbar-container').outerHeight();
2397                            }
2398                            var related_item_offset = related_item.offset().top - offset;
2399                            var related_item_offset = (related_item_offset < 1 ? 0 : related_item_offset);
2400                            $('html,body').animate(
2401                                {scrollTop: related_item_offset},
2402                                800,
2403                                'easeInOutExpo',
2404                                function() {
2405                                    $('body').delay(100).queue(function() {
2406                                        $(this).removeClass('window-forced-scroll-up');
2407                                        $(this).dequeue();
2408                                    });
2409                                    window.site.scroll.subnav_active_change();
2410                                }
2411                            );
2412                        }
2413                        return false;
2414                    });
2415                }
2416
2417            },
2418            
2419            dropdown_navigation: {
2420                
2421                init: function() {
2422                    
2423                    //console.log('drop');
2424                    
2425            		if ($('#dropdown_nav').length) {
2426            		    
2427
2428                        mouse_already_there = true;
2429                        
2430                        $(document).one('mousemove', function() {  
2431                            if ($('#header').is(":hover")) {
2432                                //Hovering on load - block hover
2433                                $('#header').one('mouseleave', function() {
2434                                   //Leaving header, reinstate hover
2435                                   mouse_already_there = false;
2436                                });
2437                            } else {
2438                                mouse_already_there = false;
2439                            }
2440                        });
2441            		    
2442            		    
2443            		    $('#top_nav li').each(function() {
2444            		        var this_path_name = $(this).find('a').attr('href').replace('/', '').replace('/', '');
2445            		        $(this).attr('data-dropdown-id', this_path_name);
2446            		        if ($('#dropdown_nav .dropdown_nav_item[data-related-nav-item="' + this_path_name + '"]').length) {
2447            		            $(this).addClass('has_dropdown');
2448            		        }
2449            		    });
2450            		    
2451            		    $('.dropdown_menu_mask').unbind().bind('click', function() {
2452            		         window.site.scroll.dropdown_navigation.close();
2453            		    });
2454            		    
2455                        $('#header').addClass('dropdown-nav-not-hover');
2456                        $('#top_nav li.has_dropdown, #dropdown_nav').each(function() {
2457                            $(this).unbind('mouseover.dropnav, mouseout.dropnav').bind('mouseover.dropnav', function() {
2458                                if (!$('body').hasClass('page-transition-delay') && !$('body').hasClass('page-transition') && !$('body').hasClass('scrolling-down') && !mouse_already_there) {
2459                                    
2460                                    var instance = $(this);
2461                                    
2462                                    if (typeof dropdown_nav_hover_initial_display_timeout != 'undefined') {
2463                                        clearTimeout(dropdown_nav_hover_initial_display_timeout);
2464                                    }
2465                                    if (typeof dropdown_nav_close_timeout != 'undefined') {
2466                                        clearTimeout(dropdown_nav_close_timeout);
2467                                    }
2468                                    
2469                                    var hover_open_delay = 300;
2470                                    if ($('body').hasClass('dropdown-nav-active')) {
2471                                        var hover_open_delay = 0;
2472                                    }
2473                                    
2474                                    dropdown_nav_hover_initial_display_timeout = setTimeout(function() {
2475                                        
2476                                        var this_dropdown_id = $(instance).attr('data-dropdown-id');
2477                                        if (this_dropdown_id && typeof this_dropdown_id != 'undefined') {
2478                                            var dropdown_element = $('#dropdown_nav .dropdown_nav_item[data-related-nav-item="' + this_dropdown_id + '"]');
2479                                            if (dropdown_element.length) {
2480                                                $('#dropdown_nav .dropdown_nav_item.active').removeClass('animate active');
2481                                                dropdown_element.addClass('active');
2482                                                var dropdown_element_height = dropdown_element.height();
2483                                                setTimeout(function() {
2484                                                    dropdown_element.addClass('animate');
2485                                                    $('#dropdown_nav').height(dropdown_element_height);
2486                                                }, 50, dropdown_element);
2487                                            } else {
2488                                                $('#dropdown_nav .dropdown_nav_item.animate').removeClass('animate');
2489                                                $('#dropdown_nav').height('0');
2490                                                dropdown_nav_close_timeout = setTimeout(function() {
2491                                                    $('#dropdown_nav .dropdown_nav_item.active').removeClass('active');
2492                                                }, 800);
2493                                            }
2494                                        }
2495                                            
2496                                        $(instance).addClass('hovering');
2497                                        $('body').addClass('dropdown-nav-active');
2498                                        if (typeof dropdown_nav_hover_timeout != 'undefined') {
2499                                            clearTimeout(dropdown_nav_hover_timeout);
2500                                        }
2501            
2502                                        if (typeof dropdown_nav_hover_over_timeout != 'undefined') {
2503                                            clearTimeout(dropdown_nav_hover_over_timeout);
2504                                        }
2505                                        dropdown_nav_hover_over_timeout = setTimeout(function() {
2506                                            $('body').addClass('dropdown-nav-animate');
2507                                            $('#header').addClass('dropdown-nav-hover');
2508                                            $('#header').removeClass('dropdown-nav-not-hover');
2509                                        }, 10);
2510                                        
2511                                    }, hover_open_delay, instance);
2512                                }
2513                            }).bind('mouseout.dropnav', function() {
2514                                $(this).removeClass('hovering');
2515                                if (!$('#header.hovering').length) {
2516                                    if (typeof dropdown_nav_hover_over_timeout != 'undefined') {
2517                                        clearTimeout(dropdown_nav_hover_over_timeout);
2518                                    }
2519                                    if (typeof dropdown_nav_hover_timeout != 'undefined') {
2520                                        clearTimeout(dropdown_nav_hover_timeout);
2521                                    }
2522                                    dropdown_nav_hover_timeout = setTimeout(function() {
2523                                        window.site.scroll.dropdown_navigation.close();
2524                                    }, 1000);
2525                                }
2526                                
2527                                if (typeof dropdown_nav_hover_initial_display_timeout != 'undefined') {
2528                                    clearTimeout(dropdown_nav_hover_initial_display_timeout);
2529                                }
2530                            });
2531                        });
2532            		}
2533                },
2534                
2535                close: function() {
2536                    $('#header').removeClass('dropdown-nav-hover');
2537                    $('#header').addClass('dropdown-nav-not-hover');
2538                    $('body').removeClass('dropdown-nav-animate');
2539                    
2540                    $('#dropdown_nav .dropdown_nav_item.animate').removeClass('animate');
2541                    $('#dropdown_nav').height('0');
2542                    dropdown_nav_close_timeout = setTimeout(function() {
2543                        $('#dropdown_nav .dropdown_nav_item.active').removeClass('active');
2544                        $('body').removeClass('dropdown-nav-active');
2545                    }, 800);
2546                }
2547            },
2548            
2549            subnav_active_change: function() {
2550                var windowPos = $(window).scrollTop(); // get the offset of the window from the top of page
2551                var windowHeight = $(window).height(); // get the height of the window
2552                var docHeight = $(document).height();
2553
2554                $('#feature_panel_section_nav ul li, #page_header ul li')
2555                    .each(function() {
2556                        var this_index = $(this).attr('data-index');
2557                        var related_item = $('.feature_panels section[data-scrollinner-index="' + this_index + '"]');
2558                        if (related_item.length) { 
2559                            var item_theme = related_item.attr('data-theme');
2560                            var offset = windowHeight/2;
2561                            if ($('#cms-frontend-toolbar-container').length > 0) {
2562                                var offset = offset + $('#cms-frontend-toolbar-container').outerHeight();
2563                            }
2564                            var divPos = related_item.offset().top - offset; // get the offset of the div from the top of page
2565                            var divHeight = related_item.outerHeight(); // get the height of the div in question
2566                            if (windowPos >= divPos && windowPos < (divPos + divHeight)) {
2567                                // This item is active
2568                                if (!$("#feature_panel_section_nav ul li[data-index='" + this_index + "']").hasClass('active')) {
2569                                    $("#feature_panel_section_nav ul li[data-index='" + this_index + "']").closest('li').addClass("active");
2570                                    $("#page_header ul li[data-index='" + this_index + "']").closest('li').addClass("active");
2571
2572                                    if (item_theme == 'reversed') {
2573                                        $('body').addClass('content-type-reversed');
2574                                    } else {
2575                                        $('body').removeClass('content-type-reversed');
2576                                    }
2577                                    if (related_item.find('.panel_heading_splash').length) {
2578                                        if (typeof section_intro_timeout != 'undefined') {
2579                                            clearTimeout(section_intro_timeout);
2580                                            clearTimeout(section_intro_timeout2);
2581                                        }
2582                                        $('#feature_panel_section_heading_content').html(related_item.find('.panel_heading_splash').text());
2583                                        var initial_timeout = $('#feature_panel_section_heading').hasClass('visible') ? 0 : 0; 
2584                                        section_intro_timeout = setTimeout(function() {
2585                                            $('#feature_panel_section_heading').addClass('visible');
2586                                        }, initial_timeout, related_item);
2587
2588                                        section_intro_timeout2 = setTimeout(function() {
2589                                            $('#feature_panel_section_heading').removeClass('visible');
2590                                        }, 2000, related_item);
2591                                    } else {
2592                                        $('#feature_panel_section_heading').removeClass('visible');
2593                                    }
2594                                }
2595                            } else {
2596                                // This item is not active
2597                                $("#feature_panel_section_nav ul li[data-index='" + this_index + "']").closest('li').removeClass("active");
2598                                $("#page_header ul li[data-index='" + this_index + "']").closest('li').removeClass("active");
2599                            }
2600                        }
2601                    })
2602                    .promise()
2603                    .done(function() {
2604                        
2605                    })
2606                ;
2607
2608                // General events - revert or figure out what to do if no items are active
2609                if ($('#feature_panel_section_nav li').length > 1 && $('#feature_panel_section_nav .active').length < 1) {
2610                    var first_item = $('#feature_panel_section_nav li').filter(':eq(0)');
2611                    var first_item_index = first_item.attr('data-index');
2612                    var related_item = $('.feature_panels section[data-scrollinner-index="' + first_item_index + '"]').length ? $('.feature_panels section[data-scrollinner-index="' + first_item_index + '"]') : false;
2613                    var related_item_below_scroll = false;
2614                    if (related_item) {
2615                        if (related_item.offset().top > $(window).scrollTop()) {
2616                            var related_item_below_scroll = true;
2617                        }
2618                    }
2619                    if (related_item_below_scroll) {
2620                        // We are above the first item, the initial theme should be set as the first item theme
2621                        var item_theme = related_item.attr('data-theme');
2622                        if (item_theme == 'reversed') {
2623                            $('body').addClass('content-type-reversed');
2624                        } else {
2625                            $('body').removeClass('content-type-reversed');
2626                        }
2627                    } else {
2628                        // No items are active, revert theme
2629                        $('body').removeClass('content-type-reversed');
2630                        $('#feature_panel_section_heading').removeClass('visible');
2631                        if (typeof section_intro_timeout != 'undefined') {
2632                            clearTimeout(section_intro_timeout);
2633                            clearTimeout(section_intro_timeout2);
2634                        }
2635                    }
2636                }
2637
2638                if(windowPos + windowHeight == docHeight) {
2639                    if (!$("#feature_panel_section_nav ul li:last-child").closest('li').hasClass("active")) {
2640                        var navActiveCurrent = $(".active").attr("href");
2641                        $("#feature_panel_section_nav ul li[href='" + navActiveCurrent + "']").closest('li').removeClass("active");
2642                        $("#feature_panel_section_nav ul l li:last-child").closest('li').addClass("active");
2643                    }
2644                }
2645            },
2646
2647            smooth_scroll: {
2648
2649                init: function() {
2650                    $(window).bind('resize', window.site.scroll.smooth_scroll.resize);
2651                    window.site.scroll.smooth_scroll.scroll_init();
2652                    if (window.site.scroll.smooth_scroll.device_enabled()) {
2653                        window.site.scroll.smooth_scroll.setup();
2654                        window.site.scroll.smooth_scroll.resize_container();
2655	                    $(window).load(function() {
2656	                        window.site.scroll.smooth_scroll.resize_container();
2657	                    });
2658                    } else {
2659                        window.site.scroll.smooth_scroll.fallback();
2660                    }
2661                },
2662
2663                setup: function() {
2664                    $('.scroll-container').addClass('active');
2665                    $('body').addClass('smooth-scroll-enabled');
2666                    window.site.scroll.smooth_scroll_active = true;
2667                    requestAnimationFrame(window.site.scroll.smooth_scroll.loop);
2668                },
2669
2670                fallback: function() {
2671                    $('.scroll-container').addClass('standard');
2672                    $('body').addClass('smooth-scroll-fallback');
2673                    window.site.scroll.smooth_scroll_active = false;
2674                },
2675
2676                resize: function() {
2677                    $(window).trigger('scroll');
2678                    if (window.site.scroll.smooth_scroll_active) {
2679                        window.site.scroll.smooth_scroll.resize_container();
2680                    }
2681                    window.site.scroll.smooth_scroll.resize_elements();
2682                },
2683
2684                scroll_init: function() {
2685                    var scrollElements = $(window.site.scroll.settings.scroll_parallax_elements);
2686                    scrollElements.each(function() {
2687                        if (!$(this).attr('data-level') || typeof $(this).attr('data-level') == 'undefined') {
2688                            var level = $(this).css('zIndex');
2689                            if (level == 0) {
2690                                var level = 1;
2691                            }
2692                            $(this).attr('data-level', level);
2693                        }
2694                    });
2695                    window.site.scroll.smooth_scroll.resize_elements();
2696                },
2697
2698                resize_elements: function() {
2699                	if (window.site.scroll.smooth_scroll_active) {
2700	                    $(window.site.scroll.settings.scroll_parallax_elements + ', ' + window.site.scroll.settings.scroll_section_elements).each(function() {
2701	                        var element = $(this);
2702	                        var transform = element.css('transform');
2703	                        element.addClass('parallax-resizing');
2704	                        element.attr('data-top', element.offset().top);
2705	                        element.attr('data-scrollheight', window.site.layout.window_height());
2706	                        element.attr('data-bottom', element.offset().top + element.outerHeight());
2707	                        element.attr('data-start', element.offset().top - window.site.layout.window_height());
2708	                        element.attr('data-stop', element.offset().top + element.outerHeight());
2709	                        element.css({
2710	                            transform: transform,
2711	                            backgroundColor: 'transparent'
2712	                        });
2713	                        element.removeClass('parallax-resizing');
2714	                    });
2715	                    $(window.site.scroll.settings.scroll_parallax_overflow_elements).each(function() {
2716	                        var element = $(this);
2717	                        var wh = $(window).height();
2718	                        var offsetTop = element.attr('data-top');
2719	                        var offsetBottom = element.attr('data-bottom');
2720	                        var level = Number(element.attr('data-level'));
2721	                        var amplitude = -wh;
2722	                        var movement = amplitude / (5 / level);
2723	                        var start = element.attr('data-start');
2724	                        var stop = element.attr('data-stop');
2725	                        var percent = (start - start) / (stop - start);
2726	                        percent = percent - 0.5;
2727	                        var maximum_offset = movement * percent;
2728	                        var maximum_offset_top = maximum_offset;
2729	                        if (element.offset().top < 20) {
2730	                            var maximum_offset_top = 0;
2731	                        }
2732	                        element.css({'top': -maximum_offset_top + 'px', 'bottom': -maximum_offset + 'px'});
2733	                    });
2734                	}
2735                },
2736
2737                translate_y: function(element) {
2738                    var style = window.getComputedStyle(element.get(0));
2739                    var matrix = style.getPropertyValue("-webkit-transform") || style.getPropertyValue("-moz-transform") || style.getPropertyValue("-ms-transform") || style.getPropertyValue("-o-transform") || style.getPropertyValue("transform");
2740                    if (matrix === 'none') {
2741                        matrix = 'matrix(0,0,0,0,0)';
2742                    }
2743                    var values = matrix.match(/([-+]?[\d\.]+)/g);
2744                    return values[14] || values[5] || 0;
2745                },
2746
2747                new_translate_y: function(element) {
2748                    var computed_style = window.getComputedStyle(element.get(0));
2749                    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');
2750                    if (!position || typeof position == 'undefined' || position === 'none') {
2751                        return 0;
2752                    } else {
2753                        var split_position_keys = position.replace(/matrix(3d)?\(|\)/g, '').split(',');
2754                        if (split_position_keys[14]) {
2755                            return split_position_keys[14];
2756                        } else if (split_position_keys[5]) {
2757                            return split_position_keys[5];
2758                        } else {
2759                            return 0;
2760                        }
2761                    }
2762                },
2763
2764                loop: function() {
2765                    var container = $('.scroll-container');
2766                    var wh = $(window).height();
2767                    var windowScrollTop = $(window).scrollTop();
2768                    var activeOffset = $(window).height() / 2;
2769                    var windowScrollTopActiveOffset = windowScrollTop + activeOffset;
2770                    var destY = windowScrollTop;
2771                    var currentY = -window.site.scroll.smooth_scroll.translate_y(container);
2772                    var containerY = -window.site.scroll.smooth_scroll.translate_y(container);
2773
2774                    if (Math.round(currentY) != Math.round(destY)) {
2775                        var newY = Math.round(currentY + ((destY - currentY) * 0.1));
2776                        container.css({
2777                            transform: 'translate3d(0, -' + newY + 'px, 0)'
2778                        });
2779                        $(window).trigger('smoothscroll');
2780                    }
2781                    var parallax_elements = $(window.site.scroll.settings.scroll_parallax_elements);
2782                    if (parallax_elements != null) {
2783                        parallax_elements.each(function() {
2784                            var element = $(this);
2785                            var offsetTop = element.attr('data-top');
2786                            var offsetBottom = element.attr('data-bottom');
2787                            var level = Number(element.attr('data-level'));
2788                            var amplitude = -wh;
2789                            var movement = amplitude / (5 / level);
2790                            if (offsetTop > (windowScrollTop + (wh * 1.3))) {
2791                                element.css({
2792                                    transform: 'translate3d(0, ' + (-movement * 0.5) + 'px, 0)'
2793                                });
2794                            } else if (offsetBottom < (windowScrollTop * 0.7)) {
2795                                element.css({
2796                                    transform: 'translate3d(0, ' + (movement * 0.5) + 'px, 0)'
2797                                });
2798                            } else {
2799                                var start = element.attr('data-start');
2800                                var stop = element.attr('data-stop');
2801                                var percent = (windowScrollTop - start) / (stop - start);
2802                                percent = percent - 0.5;
2803                                var destY = movement * percent;
2804                                var currentY = 0;
2805                                var transform = element.css('transform');
2806                                if (transform != 'none')
2807                                    currentY = parseFloat(element.css('transform').split(',')[5]);
2808                                if (level > 0)
2809                                    var newY = currentY + ((destY - currentY) * 0.1);
2810                                else
2811                                    var newY = currentY + ((destY - currentY) * 0.5);
2812                                element.css({
2813                                    transform: 'translate3d(0, ' + (newY) + 'px, 0)'
2814                                });
2815                                var image = element.find('> .image, .image-container > .image').not('.fixed');
2816                                if (image.length == 1) {
2817                                    image.css({
2818                                        top: 100 * percent
2819                                    });
2820                                }
2821                            }
2822                        });
2823                    }
2824
2825                    requestAnimationFrame(window.site.scroll.smooth_scroll.loop);
2826                },
2827
2828                resize_container: function() {
2829                    var container = $('.scroll-container');
2830                    $('body').css({
2831                        height: container.outerHeight()
2832                    });
2833                },
2834
2835                device_enabled: function() {
2836                    if (window.site.scroll.smooth_scroll_enabled) {
2837                        var mobile_version = window.site.device.handheld() || $(window).width() < 900 || ($.browser.msie && $.browser.version < 10);
2838                        return !mobile_version;
2839                    } else {
2840                        return false;
2841                    }
2842                }
2843
2844            }
2845        },
2846
2847        pageload: {
2848
2849            splash_dev_mode: false, 
2850            splash_act_as_server: false,
2851
2852            init: function() {
2853            	if ($('body').hasClass('section-error')) {
2854            		$('body').addClass('first-load-complete');
2855            		return false;
2856            	}
2857                if ('scrollRestoration' in history) {
2858                	if (window.site.scroll.smooth_scroll_enabled) {
2859                    	history.scrollRestoration = 'manual';
2860                    } else {
2861                    	history.scrollRestoration = 'auto';
2862                    }
2863                }
2864                $('a[href^="/store/artworks/"]').each(function() {
2865                    if (!$(this).closest('.artwork_detail').length) {
2866                        if (!$(this).hasClass('pageload-link-type-popup-enabled-content')) {
2867                            $(this).addClass('pageload-link-type-popup-enabled-content');
2868                        }
2869                    }
2870                });
2871                $('a[href^="/content/feature/"]').each(function() {
2872                    if ($(this).attr('href').indexOf('/detail/') > -1) {
2873                        if (!$(this).closest('.artwork_detail').length) {
2874                            if (!$(this).hasClass('pageload-link-type-popup-enabled-content')) {
2875                                $(this).addClass('pageload-link-type-popup-enabled-content');
2876                            }
2877                        }
2878                    }
2879                });
2880
2881                $('a.pageload-link-type-popup-enabled-content').click(function() {
2882                    // Assume background will be reversed - popups are reversed by default
2883                    //$('body').addClass('content-type-reversed-popup');
2884                });
2885
2886                $.pageload({
2887                    
2888                    ///////////////////////////////////
2889                    // Ajax navigation removed for development
2890                    ///////////////////////////////////
2891                    'ajax_navigation_enabled': true,
2892
2893
2894                    'splash_screen_enabled': true,
2895                    
2896                	'splash_screen_always_enabled': true || !$('body').hasClass('site-version-development-mode') || window.site.pageload.splash_dev_mode || window.site.pageload.splash_act_as_server ? true : false,
2897                	'development_mode': window.site.pageload.splash_dev_mode ? true : false,
2898                    'development_mode_pause_splash_screen': window.site.pageload.splash_dev_mode ? true : false,
2899                    'development_mode_show_splash_screen_on_refresh': false,
2900
2901           			'splash_screen_cookie_expiry': 300, // 5m
2902                    'splash_screen_delay_after_complete': 1000,
2903                    'splash_screen_auto_delays_enabled': false,
2904                    //'page_transition_delay': 1200,
2905                    'page_transition_delay': 810,
2906                    'popup_content_enabled': true,
2907                    'verbose': false,
2908                    'content_area_selector': '.pageload-content-area',
2909                    'content_load_adjacent': false,
2910
2911                    'splash_screen_primary_preload_images_selector': '',
2912                    'preload_images_selector': '',
2913                    'preload_videos_selector': '',
2914                    'x_popstate_custom_functions': {
2915                        '/artworks/': function(e) {
2916                            var relative_id = e.originalEvent.state.customArtworksDefaultCategory;
2917                            $('.artworks-overlay-button:eq(0)').trigger('click');
2918                            if (relative_id) {
2919                                $('.artworks-overlay .artwork-nav-top-level[data-id="' + relative_id + '"]').trigger('click');
2920                            }
2921                        }
2922                    },
2923                    'destroy_after_load': function() {
2924                        if ($('.artworks-overlay').hasClass('active')) {
2925                            var default_category = false;
2926                            if ($('.artwork-navigation .artwork-nav-top-level.active').length) {
2927                                var default_category = $('.artwork-navigation .artwork-nav-top-level.active').attr('data-id');
2928                            }
2929                            history.pushState({'ajaxPageLoad': true, 'customArtworksDefaultCategory': default_category}, null, '/artworks/');
2930                        }
2931
2932                        if ($('body').hasClass('page-popup-active')) {
2933                            // A popup is open, close it
2934                            window.site.pageload.popup_after_close();
2935                            //$.pageload.popup_close(true);
2936                        }
2937
2938	                    if ($('.artworks-overlay').hasClass('active')) {
2939	                    	$('.artworks-overlay-close-button').trigger('click');
2940	                    }
2941
2942                        $('video').remove();
2943                        $('.image_gallery_multiple').cycle('destroy');
2944                        $('#hero_slideshow').cycle('destroy');
2945                        $('.content_slideshow').cycle('destroy');
2946                        $('#main_slideshow').cycle('destroy');
2947                        $('#hero_slideshow').stop().clearQueue().unbind();
2948                        $('body').removeClass('page-transition-delay');
2949                        window.site.artlogic_inview.destroy();
2950                    },
2951                    'popup_before': function() {
2952                        window.site.pageload.popup_after_open('before');
2953                        
2954                    },
2955                    'popup_after': function() {
2956                        window.site.pageload.popup_after_open('after');
2957                    },
2958                    'popup_after_close': function() {
2959                        window.site.pageload.popup_after_close();
2960                    },
2961                    'before_load': function(incoming_content_type) {
2962                        
2963                        if ($('.search-overlay').hasClass('active') && !$('.search-overlay').hasClass('search-loading')) {
2964                            
2965                            var is_popup = false;
2966                            var sections = ["/works/", "/publications/", "/artworks/", "/news/", "/art-fairs/"];
2967                            var i;
2968                            for (i = 0; i < sections.length; i++) { 
2969                                if (incoming_content_type.indexOf(sections[i]) != -1) {
2970                                    var is_popup = true;
2971                                }
2972                            }
2973                            if (!is_popup) {
2974                                window.site.overlays.search.close();
2975                            }
2976                            
2977                    	}
2978                        if ($('.enquire-overlay').hasClass('active')) {
2979                    		window.site.overlays.enquire.close();
2980                    	}
2981                        if ($('.content-overlay').hasClass('active')) {
2982                            window.site.overlays.content.close();
2983                        }
2984                        if ($('#main_slideshow').length) {
2985                            if (window.window.canvasSlideshowInitialized) {
2986                                window.canvasPauseVideo(parseInt($('#main_slideshow .slide.cycle-slide-active').attr('data-index'))-1);
2987                            }
2988                        }
2989                        if ($('#store_quick_cart_widget').hasClass('active')) {
2990                            $('#store_quick_cart_widget .notify_panel_close').trigger('click');
2991                        }
2992                        if ($('#wishlist_quick_cart_widget').hasClass('active')) {
2993                            $('#wishlist_quick_cart_widget .notify_panel_close').trigger('click');
2994                        }
2995                        //window.site.home.slideshow_color_change();
2996                        
2997                    },
2998                    'preloader_in': function(short_load) {
2999                        if (!short_load) {
3000                            window.site.splash_screen.init();
3001                        } else {
3002                            // Start the homepage slideshow (can be done anywhere in the code, e.g. after the splash screen has finished)
3003                            window.site.home.start_slideshow();
3004                        }
3005                    },
3006                    'splash_screen_in': function() {
3007                        
3008                    },
3009                    'splash_screen_out': function() {
3010                        //console.log('run splash_screen_end');
3011                        window.site.splash_screen.splash_screen_end();
3012                    },
3013                    'init_after_splash_screen': function() {
3014                        
3015                    },
3016                    'page_transition_start': function() {
3017                        
3018                    },
3019                    'page_transition_end': function() {
3020                            // if ($('#g_recaptcha').length && !grecaptcha) {
3021                             //  onloadCallback();
3022                            // }
3023                    }
3024                });
3025                $('.nav-overlay .nav-wrapper ul li a').unbind().click(function() {
3026                    if ($(this).hasClass('link-no-ajax')) {
3027                        return true;
3028                        
3029                    } else {
3030                        $('.nav-close-button').trigger('click');
3031                        $.pageload.load($(this).attr('href'), true, false);
3032                    }
3033                	return false;
3034                });
3035                $('#sqcw_checkout a').unbind().click(function() {
3036                	$.pageload.load($(this).attr('href'), true, function() {
3037	                    $('#sqcw_close').trigger('click');
3038                	});
3039                	return false;
3040                });
3041                
3042            },
3043
3044            close_popup: function() {
3045                window.history.back();
3046                //$('#popup_box > .inner > .close').trigger('click');
3047                $('body').removeClass('content-reversed content-not-reversed content-type-reversed-popup');
3048                $('body').removeClass('user-distraction-free')
3049                $('body').removeClass('page-artwork-detail-standard');
3050                $('#popup_box').animate({'scrollTop': 0}, 600);
3051                $('#popup_content').html('');
3052            },
3053
3054            popup_after_open: function(type) {
3055                $('body').addClass('popup-not-scrolled');
3056                window.site.slideshow.slider.init();
3057                
3058                if (type == 'after') {
3059                    //$('#popup_container').addClass('popup-content-reversed');
3060                    //$('body').addClass('content-type-reversed-popup');
3061                }
3062                if (type == 'after' && !$('#popup_content .content-reversed').length) {
3063                    //$('#popup_container').removeClass('popup-content-reversed');
3064                    //$('body').removeClass('content-type-reversed-popup');
3065                }
3066                $('body').removeClass('user-inactive user-idle window-scrolled');
3067            	$('#container_outer').removeClass('scrolling-up');
3068                window.cart.init();
3069                window.cart.cart_summary.get_summary(false);
3070                
3071                window.site.social_media.init();
3072                window.site.overlays.enquire.init();
3073
3074                window.site.lazy_load.setup();
3075                
3076                window.site.artworks.setup();
3077                window.site.artlogic_inview.init();
3078                window.site.lazy_load.fire('#popup_box .inview_element,#popup_box .image_lazy_load');
3079                $(window).trigger('resize');
3080                window.site.misc.init('popup');
3081                window.site.video.init();
3082            },
3083
3084            popup_after_close: function() {
3085                $('body').removeClass('content-type-reversed-popup');
3086                $('body').removeClass('popup-hidable-content user-distraction-free');
3087                $('body').removeClass('content-reversed content-not-reversed');
3088                $('body').removeClass('zoom-active user-distraction-free');
3089                $('body').removeClass('popup-scrolled popup-not-scrolled');
3090                $('html').removeClass('page-popup-active');
3091                $('body').removeClass('page-popup-active page-popup-force-close page-popup-clicked-close');
3092                $('#popup_box .artwork_detail.artwork_detail_variant_video .video').html('');
3093                $('.image_gallery_multiple').cycle('destroy');
3094                window.site.scroll.events.run();
3095                $('#popup_content').scrollTop(0);
3096            }
3097
3098        },
3099
3100        splash_screen: {
3101            init: function() {
3102
3103                $('body').addClass('main-content-hide');
3104                window.setTimeout(function() {
3105                    $('body').addClass('active-init');
3106                    $('body').addClass('splash-init');
3107                }, 10);
3108                window.setTimeout(function() {
3109                    $('.splash-bg').addClass('open start');
3110                    $('body').addClass('splash-open');
3111                    // start letter transition
3112                    $('.hero video').each(function() {
3113                    	$(this).get(0).pause();
3114                    });
3115                }, 500);
3116                window.setTimeout(function() {
3117                    window.site.splash_screen.splash_screen_start();
3118                }, 400);
3119            },
3120
3121            splash_screen_start: function() {
3122                setTimeout(function() {
3123                	$('.splash-container').addClass('start');
3124                }, 800);
3125                
3126                setTimeout(function() {
3127                    
3128                    $(".splash-text").each(function(i){
3129                        var $item = $(this);
3130                        setTimeout(function() {
3131                            $item.addClass('visible')
3132                        }, 600*i);
3133                    });
3134                }, 1000);
3135                
3136            },
3137            
3138            splash_screen_end: function() {
3139                setTimeout(function() {
3140                    // Start the homepage slideshow
3141                    setTimeout(function() {
3142                        window.site.home.start_slideshow_pre_init();
3143                    }, 1000);
3144                    setTimeout(function() {
3145                        window.site.home.start_slideshow(false);
3146                    }, 1500);
3147
3148                    setTimeout(function() {
3149                        $('body').removeClass('main-content-hide');
3150                        $('.splash-container').addClass('end');
3151                        window.site.splash_screen.hide_splash();
3152                    }, 1500);
3153                }, 1000);
3154            },
3155
3156            hide_splash: function() {
3157                $('.splash-bg').removeClass('open start');
3158                // stop letter transition
3159                $('body').removeClass('splash-open');
3160
3161                $('body').delay(1200).queue(function() {
3162                    $('body').removeClass('active-init');
3163                    $('body').removeClass('splash-init');
3164                    $(window).trigger('resize');
3165                    $(this).dequeue();
3166                });
3167            }
3168
3169        },
3170
3171        overlays: {
3172
3173            init: function() {
3174                window.site.overlays.content.init();
3175                window.site.overlays.search.init();
3176                window.site.overlays.enquire.init();
3177                window.site.overlays.navigation();
3178                window.site.overlays.artworks();
3179            },
3180
3181	        search: {
3182
3183	            init: function() {
3184                	window.site.overlays.search_form.init();
3185	                window.site.overlays.search.setup();
3186
3187	            },
3188
3189	            setup: function() {
3190
3191	                //window.site.overlays.search.open($('#search'));
3192
3193	                $('#search_menu, .search-close-button').unbind().click(function() {
3194	                	var clicked_element = $(this);
3195	                    $('body').addClass('active-init');
3196	                    window.setTimeout(function() {
3197	                        if ($('.search-overlay').hasClass('active')) {
3198                        		window.site.overlays.search.close();
3199                        		h.accessibility.on_popup_closing('#search_menu');
3200	                        } else {
3201                        		window.site.overlays.search.open(clicked_element);
3202                        		h.accessibility.on_popup_opening('.search-overlay', false, '.search-close-button');
3203	                        }
3204	                    }, 50, clicked_element);
3205	                    return false;
3206	                });
3207
3208	                $('#sw_form').each(function() {
3209	                	if (!$(this).find('.form_row .loader').length) {
3210	                		$(this).find('.form_row').append('<span class="loader"></span>');
3211	                	}
3212	                });
3213
3214	                $('#quick_search_widget .button a').unbind().click(function() {
3215	                    window.site.overlays.search.submit_form($(this).closest('#quick_search_widget').find('form'));
3216	                    return false;
3217	                });
3218
3219	            },
3220
3221	            close: function() {
3222                    window.setTimeout(function() {
3223                        $('body').removeClass('active-init');
3224                    }, 600);
3225                    $('.search-overlay .overlay-bg').removeClass('open');
3226                    $('.search-overlay').removeClass('active');
3227                    $('body, html').removeClass('overlay-open search-overlay-open');
3228                    $('.search-wrapper.visible').removeClass('visible');
3229	            },
3230
3231	            open: function(clicked_element, data) {
3232                	$('#container_outer').removeClass('scrolling-down scrolling-up');
3233                    $('.search-overlay .overlay-bg').addClass('open');
3234                    $('.search-overlay').addClass('active');
3235                    $('body, html').addClass('overlay-open search-overlay-open');
3236                    
3237                    $('.search-wrapper:not(.visible)').each(function(i) {
3238                        var $item = $(this);
3239                        setTimeout(function() {
3240                            $item.addClass('visible')
3241                        }, 300*i);
3242                    });
3243
3244	                if (window.ga) {
3245	                    // Track the click in Analytics
3246                        analytics_params = {
3247                          'hitType': 'event',
3248                          'eventCategory': 'Search form opened',
3249                          'eventAction': window.location.pathname,
3250                          'eventLabel': $(document).attr('title')
3251                        };
3252                        ga('send', analytics_params);
3253                        ga('tracker2.send', analytics_params);
3254	                }
3255	                
3256	                $('input#sw_field_search')[0].focus();
3257
3258	            },
3259
3260	            clear_form: function() {
3261	                window.site.overlays.search_form.reset_form();
3262	            },
3263
3264	            submit_form: function(instance) {
3265
3266	            },
3267
3268	            after_submit: function() {
3269
3270	            }
3271
3272	        },
3273
3274	        search_form: {
3275
3276	            init: function() {
3277
3278	                window.site.overlays.search_form.setup();
3279
3280	            },
3281
3282	            setup: function() {
3283
3284
3285	                $('input#sw_field_search')
3286	                    .unbind()
3287	                    .each(function() {
3288
3289	                    })
3290	                    .blur(function() {
3291	                        if ($(this).val() == '') {
3292	                            $(this).removeClass('active');
3293	                        }
3294	                    })
3295	                    .focus(function() {
3296	                        if ($(this).val() == '') {
3297	                            $(this).addClass('active');
3298	                        }
3299	                    })
3300	                    .keypress(function(e) {
3301	                        window.site.overlays.search_form.form_submit();
3302	                    })
3303	                ;
3304
3305	                $('#sw_field_search_button').unbind().bind('click', function() {
3306	                    window.site.overlays.search_form.form_submit();
3307	                    return false;
3308	                });
3309
3310	                $('input#sw_field_search').closest('form').submit(function() {
3311	                    return false;
3312	                });
3313
3314	                $('#sw_more').unbind('click.search_view_more_actions').bind('click.search_view_more_actions', function() {
3315	                    
3316	                });
3317	                
3318	            },
3319
3320	            form_submit: function() {
3321	                var search_value = $('input#sw_field_search').val();
3322	                if (search_value && search_value.length >= 2) {
3323	                    $('input#sw_field_search').stop().clearQueue();
3324	                    $('.search-overlay').addClass('search-loading');
3325	                    $('input#sw_field_search')
3326	                        .animate({'opacity': '1'}, 600, function() {
3327	                            var element_href = '/search/results/?s=' + search_value + '&instant=1';
3328	                            $.pageload.load(element_href, true, function() {
3329	                                if (new_page_inner_content) {
3330	                                    $('#quick_search_widget .notify_panel_content').scrollTop(0);
3331	                                    $('#sw_results').html(new_page_inner_content);
3332	                                    $('.search-overlay').removeClass('search-loading search-results-active');
3333	                                    if ($('#sw_results .item').not('.search-grid-no-results').length) {
3334	                                        $('.search-overlay').addClass('search-results-active');
3335	                                        $('#sw_more').attr('href', element_href.replace('&instant=1', ''));
3336	                                    }
3337	                                    window.site.layout.grids.init();
3338                                        window.site.lazy_load.setup();
3339                                        //window.site.lazy_load.fire($('#sw_results .image_lazy_load'));
3340	                                    window.site.artlogic_inview.init();
3341	                                    $(window).trigger('resize');
3342	                                    $.pageload.refresh($('#quick_search_widget'));
3343	                                }
3344	                            }, null, null, null, '');
3345	                        })
3346	                    ;
3347	                }
3348	            },
3349
3350	            reset_form: function(instance) {
3351	                $('input#sw_field_search').val($('input#sw_field_search').attr('data-default-value'));
3352	                $('#sw_results').html('');
3353	            }
3354
3355	        },
3356
3357            enquire: {
3358
3359                init: function() {
3360                    window.site.overlays.enquire.setup();
3361                },
3362
3363                setup: function() {
3364
3365                    $('.enquire_link, .enquire-close-button').unbind().click(function() {
3366                        var clicked_element = $(this);
3367                        $('body').addClass('active-init');
3368                        window.setTimeout(function() {
3369                            if ($('.enquire-overlay').hasClass('active')) {
3370                                window.site.overlays.enquire.close();
3371                            } else {
3372                                // For accessibility - tracks which element to refocus on
3373                                try {
3374                                    h.accessibility.global_variables.element_to_refocus_to = $(this);
3375                                } catch(error) {
3376                                    console.error(error);
3377                                }
3378                                window.site.overlays.enquire.open(clicked_element);
3379                            }
3380                        }, 50, clicked_element);
3381                        return false;
3382                    });
3383
3384                    $('input, textarea', '#quick_contact_widget')
3385                        .each(function() {
3386                            $(this).attr('default-value', $(this).parent().find('> label').text());
3387                            if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
3388                                $(this).addClass('active');
3389                            } else {
3390                                $(this).val($(this).attr('default-value'));
3391                            }
3392                        })
3393                        .change(function() {
3394                            $(this).closest('.form_row').removeClass('error');
3395                        })
3396                        .focus(function() {
3397                            $(this).closest('.form_row').removeClass('error');
3398                            if ($(this).val() == $(this).attr('default-value')) {
3399                                $(this).addClass('active');
3400                                $(this).val('');
3401                            }
3402                            var field_offset_top = $(this).offset().top - 200;
3403                            $('#quick_contact_widget .notify_panel_content').animate({'scrollTop': field_offset_top}, 0);
3404                        })
3405                        .blur(function() {
3406                            $(this).attr('default-value', $(this).parent().find('label').text());
3407                            if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
3408                                $(this).val($(this).attr('default-value'));
3409                                $(this).removeClass('active');
3410                            }
3411                        })
3412                    ;
3413
3414                    $('select', '#quick_contact_widget')
3415                        .each(function() {
3416                            $(this).attr('default-value', $(this).val());
3417                        })
3418                        .change(function() {
3419                            if ($(this).val() != '') {
3420                                $(this).addClass('active');
3421                            } else {
3422                                $(this).removeClass('active');
3423                            }
3424                        })
3425                    ;
3426
3427                    $('#quick_contact_widget .notify_panel_close').unbind().click(function() {
3428                        window.site.enquiry.close();
3429                    });
3430
3431                    $('#quick_contact_widget .button a').unbind().click(function() {
3432                        window.site.overlays.enquire.submit_form($(this).closest('#quick_contact_widget').find('form'));
3433                        return false;
3434                    });
3435
3436                    $('#quick_contact_widget').each(function() {
3437                        if (!$(this).hasClass('initialized')) {
3438                            if (false) {
3439                                $.ajax({
3440                                    url: "/custom/get_user_data/",
3441                                    cache: false,
3442                                    method: 'POST',
3443                                    success: function(data) {
3444                                        if (data) {
3445                                            var parsed_data = JSON.parse(data);
3446                                            $.each(parsed_data, function(k, v) {
3447                                                if (v && v != '') {
3448                                                    $('#quick_contact_widget').find('input[name="' + k + '"]').val(v).addClass('active');
3449                                                }
3450                                            });
3451                                        }
3452                                    }
3453                                });
3454                            }
3455                        }
3456                        $(this).addClass('initialized');
3457                    });
3458
3459                },
3460
3461                close: function() {
3462                    window.setTimeout(function() {
3463                        if (!$('.overlay.active').not('.enquire-overlay').length) {
3464                            $('body').removeClass('active-init');
3465                        }
3466                    }, 600);
3467
3468                    if (!$('.overlay.active').not('.enquire-overlay').length) {
3469                        $('body, html').removeClass('overlay-open ui-overlay-open');
3470                    }
3471                    $('body, html').removeClass('ui-overlay-open');
3472
3473                    $('body').removeClass('quick_contact_widget_active');
3474                    $('.enquire-overlay .overlay-bg').removeClass('open');
3475                    $('.enquire-overlay').removeClass('active');
3476
3477                    $(".enquire-input-wrapper.visible, .enquire-contact-wrapper.visible").removeClass('visible');
3478                    h.accessibility.on_popup_closing();
3479                },
3480
3481                open: function(clicked_element, data, form_type) {
3482                    $('#container_outer').removeClass('scrolling-down scrolling-up');
3483                    $('.enquire-overlay .overlay-bg').addClass('open');
3484                    $('.enquire-overlay').addClass('active');
3485                    $('body, html').addClass('overlay-open ui-overlay-open');
3486                    
3487                    $(".enquire-input-wrapper:not(.visible),.enquire-contact-wrapper:not(.visible)").each(function(i){
3488                        var $item = $(this);
3489                        setTimeout(function() {
3490                            $item.addClass('visible')
3491                        }, 300);
3492                    });
3493
3494                    if (window.ga) {
3495                        // Track the click in Analytics
3496                        analytics_params = {
3497                          'hitType': 'event',
3498                          'eventCategory': 'Enquiry form opened',
3499                          'eventAction': window.location.pathname,
3500                          'eventLabel': $(document).attr('title')
3501                        };
3502                        ga('send', analytics_params);
3503                        ga('tracker2.send', analytics_params);
3504                    }
3505
3506                    var form_type = form_type && typeof form_type != 'undefined' ? form_type : 'standard';
3507                    var data = data && typeof data != 'undefined' ? data : {};
3508
3509                    $('body').addClass('quick_contact_widget_active');
3510                    $('#quick_contact_widget').addClass('active');
3511                    $('#quick_contact_widget').clearQueue().delay(10).queue(function() {
3512                        $(this).addClass('animate').dequeue();
3513                    });
3514                    $('#quick_contact_widget').removeClass('success enquiry-type-event-interest');
3515
3516                    $('#quick_contact_widget form #qcw_field_originating_page').val(window.location.pathname);
3517                    
3518                    if (clicked_element && typeof clicked_element != 'undefined') {
3519                        var additional_field_content = $(clicked_element).attr('data-contact-form-details');
3520                        var additional_field_image = $(clicked_element).attr('data-contact-form-image');
3521                        var additional_field_parent_id = $(clicked_element).attr('data-contact-form-parent-id');
3522                        var form_type = $(clicked_element).attr('data-type') && typeof $(clicked_element).attr('data-type') != 'undefined' ? $(clicked_element).attr('data-type') : form_type;
3523                        var form_subtype = $(clicked_element).attr('data-subtype') && typeof $(clicked_element).attr('data-subtype') != 'undefined' ? $(clicked_element).attr('data-subtype') : '';
3524                    }
3525
3526                    $('#qcw_field_contact_type').val(form_type);
3527                    
3528                    var artist_name = $(clicked_element).attr('data-contact-form-artist-name');
3529                    if (typeof artist_name !== typeof undefined && artist_name !== false) {
3530                        $('#qcw_field_artist_name').val(artist_name);
3531                    }
3532                    
3533                    var publication_title = $(clicked_element).attr('data-contact-form-publication-title');
3534                    if (typeof publication_title !== typeof undefined && publication_title !== false) {
3535                        $('#qcw_field_publication_title').val(publication_title);
3536                    }
3537
3538                    if (form_type == 'event-interest') {
3539                        $('#quick_contact_widget').addClass('enquiry-type-event-interest');
3540                    }
3541
3542                    if (additional_field_content || form_type == 'sales') {
3543
3544                        // Sales / artwork enquiry form type
3545                        if (additional_field_content) {
3546                            if ($('#quick_contact_widget .notify_panel_items').length) {
3547                                $('#quick_contact_widget .notify_panel_items').html('<ul><li></li></ul>');
3548                                $('#quick_contact_widget .notify_panel_items li').html('<div class="content">' + decodeURIComponent(additional_field_content) + '</div>');
3549                                if (additional_field_image) {
3550                                    var website_domain = '';
3551                                    if (additional_field_image.substr(0,7) != 'http://' && additional_field_image.substr(0,8) != 'https://') {
3552                                        var website_domain = 'http://' + document.location.host;
3553                                    }
3554                                    $('#quick_contact_widget .notify_panel_items li').prepend('<div class="image"><div><img src="' + website_domain + additional_field_image + '" alt=""/></div></div>');
3555                                }
3556                                $('#quick_contact_widget form #qcw_field_item').val(encodeURIComponent($('#quick_contact_widget .notify_panel_items li').html()));
3557                            }
3558                        }
3559                    }
3560                    
3561                    // focus trap the popup
3562                    h.accessibility.on_popup_opening('.enquire-overlay', '.enquire-overlay #qcw_field_name', '.enquire-overlay .enquire-close-button');
3563                    
3564                },
3565
3566                clear_form: function() {
3567                    $('#qcw_field_item').val('');
3568                    $('#qcw_field_artist_name').val('');
3569                    $('#qcw_field_publication_title').val('');
3570                    $('#qcw_field_message', '#quick_contact_widget').each(function() {
3571                        $(this).val($(this).attr('default-value')).removeClass('active');
3572                    });
3573                    $('#qcw_field_subject', '#quick_contact_widget').each(function() {
3574                        $(this).val('').removeClass('active');
3575                    });
3576                    $('#quick_contact_widget .notify_panel_items').html('');
3577                },
3578
3579                submit_form: function(instance) {
3580
3581                    if (instance) {
3582                        $('#quick_contact_widget .button').addClass('loading');
3583                        $('.error_row', instance).removeClass('active');
3584
3585                        data = 'submit=1&';
3586                        $('input, select, textarea', instance).each(function() {
3587                            var field_value = $(this).val();
3588                            if (field_value != $(this).attr('default-value')) {
3589                                if ($(this).attr('type') == 'checkbox') {
3590                                    if ($(this).attr('name') == 'terms') {
3591                                        var field_value = $(this).is(':checked') ? '1' : '';
3592                                    } else {
3593                                        var field_value = $(this).is(':checked') ? 'Yes' : 'No';
3594                                    }
3595                                }
3596
3597                                if ($(this).attr('name') == 'message') {
3598                                    data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />').replace('%', 'percent') + '&';
3599                                } else {
3600                                    data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
3601                                }
3602                            }
3603                        });
3604
3605                        data = data + 'originating_page=' + encodeURIComponent(window.location.pathname + window.location.search) + '&';
3606
3607                        $.ajax({
3608                            url: "/enquiry/",
3609                            data: data,
3610                            cache: false,
3611                            method: 'POST',
3612                            dataType: 'json',
3613                            success: function(data) {
3614                                setTimeout(function() {
3615                                    $('#quick_contact_widget .button').removeClass('loading');
3616                                }, 1600);
3617                                $('#quick_contact_widget')
3618                                    .delay(400)
3619                                    .queue(function() {
3620                                        if (data['success'] == 1) {
3621                                            window.archimedes.archimedes_core.analytics.track_campaigns.save_form_data($('#quick_contact_widget'));
3622
3623                                            $('#quick_contact_widget').addClass('success');
3624                                            if (window.ga) {
3625                                                // Track in Analytics
3626                                                analytics_params = {
3627                                                  'hitType': 'event',
3628                                                  'eventCategory': 'Enquiry form submit success',
3629                                                  'eventAction': window.location.pathname,
3630                                                  'eventLabel': $(document).attr('title')
3631                                                };
3632                                                ga('send', analytics_params);
3633                                                ga('tracker2.send', analytics_params);
3634                                            }
3635
3636                                            window.site.overlays.enquire.close();
3637
3638                                            $('#quick_contact_widget')
3639                                                .delay(200)
3640                                                .queue(function() {
3641                                                    h.alert('<h2>Thank you</h2><div>Your Inquiry has been sent.</div>');
3642                                                    $(this).dequeue();
3643                                                })
3644                                            ;
3645
3646                                        } else {
3647                                            var error_message = '';
3648                                            if (data['error_message'] && typeof data['error_message'] != 'undefined') {
3649                                                var error_message = data['error_message'];
3650                                            }
3651                                            var field_errors = [];
3652                                            if (data['field_errors'] && typeof data['field_errors'] != 'undefined') {
3653                                                var field_errors = data['field_errors'];
3654                                            }
3655                                            $.each(field_errors, function(i, v) {
3656                                                $('#quick_contact_widget').find('[name="' + v + '"]').closest('.form_row').addClass('error');
3657                                            });
3658                                            if (error_message) {
3659                                                h.alert(error_message);
3660                                            }
3661
3662                                            if (window.ga) {
3663                                                // Track in Analytics
3664                                                analytics_params = {
3665                                                  'hitType': 'event',
3666                                                  'eventCategory': 'Enquiry form submit error',
3667                                                  'eventAction': window.location.pathname,
3668                                                  'eventLabel': $(document).attr('title')
3669                                                };
3670                                                ga('send', analytics_params);
3671                                                ga('tracker2.send', analytics_params);
3672                                            }
3673
3674                                        }
3675                                        $(this).dequeue();
3676                                    })
3677                               ;
3678                            }
3679                        });
3680                    }
3681
3682                },
3683
3684                after_submit: function() {
3685
3686                }
3687
3688            },
3689
3690            content: {
3691
3692                init: function() {
3693                    window.site.overlays.content.setup();
3694                },
3695
3696                setup: function() {
3697
3698                    $('.content_overlay_link_example, .content-overlay .overlay-close-button').unbind().click(function() {
3699                        var clicked_element = $(this);
3700
3701                        if ($('.content-overlay').hasClass('active')) {
3702                            window.site.overlays.content.close();
3703                        } else {
3704                            window.site.overlays.content.open(cl
3704icked_element);
3705                        }
3706
3707                        return false;
3708                    });
3709
3710                },
3711
3712                close: function() {
3713                    window.setTimeout(function() {
3714                        $('body').removeClass('active-init');
3715                    }, 600);
3716                    $('.content-overlay .overlay-bg').removeClass('open');
3717                    $('.content-overlay').removeClass('active');
3718                    $('body, html').removeClass('overlay-open content-overlay-open ui-overlay-open');
3719                    $(".content-overlay-wrapper.visible").removeClass('visible');
3720
3721                    $('.content-overlay .overlay-container-inner').scrollTop(0);
3722
3723                    $('.list-preview-track-list .item').removeClass('active');
3724                    $('.list-preview-track-list').removeClass('item-preview-active');
3725                },
3726
3727                open: function(clicked_element, received_html) {
3728                    var received_html = (received_html && typeof received_html != 'undefined' ? received_html : '');
3729
3730                    $('#content-overlay-content').html(received_html);
3731
3732                    $('body').addClass('active-init');
3733
3734                    $(clicked_element).closest('.item').addClass('active');
3735                    $(clicked_element).closest('.list-preview-track-list').addClass('item-preview-active');
3736
3737                    setTimeout(function() {
3738                        $('#container_outer').removeClass('scrolling-down scrolling-up');
3739                        $('.content-overlay .overlay-bg').addClass('open');
3740                        $('.content-overlay').addClass('active');
3741                        $('body, html').addClass('overlay-open content-overlay-open ui-overlay-open');
3742                        
3743                        setTimeout(function() {
3744                            $('.content-overlay-wrapper:not(.visible)').each(function(i){
3745                                $(this).addClass('visible')
3746                            });
3747                        }, 700, clicked_element);
3748                    }, 50, clicked_element);
3749
3750                    if (window.ga) {
3751                        // Track the click in Analytics
3752                        analytics_params = {
3753                          'hitType': 'event',
3754                          'eventCategory': 'Whats on event preview opened',
3755                          'eventAction': window.location.pathname,
3756                          'eventLabel': $(document).attr('title')
3757                        };
3758                        ga('send', analytics_params);
3759                        ga('tracker2.send', analytics_params);
3760                    }
3761
3762                }
3763
3764            },
3765
3766            navigation: function() {
3767                
3768            
3769                $('#menu, .nav-close-button').unbind().click(function() {
3770                    
3771                	$('#container_outer').removeClass('scrolling-down scrolling-up');
3772                    $('body').addClass('active-init');
3773                    
3774                    
3775                    window.setTimeout(function() {
3776                        if ($('.nav-overlay').hasClass('active')) {
3777                            window.setTimeout(function() {
3778                                $('body').removeClass('active-init');
3779                                
3780                                $(".nav-contact-module.visible, .nav-wrapper li.visible, .nav-overlay .sidenav-contact-details.visible")
3781                                    .removeClass('visible');
3782                            }, 600);
3783                            $('.nav-overlay').removeClass('active');
3784                            $('.nav-overlay .overlay-bg').removeClass('open');
3785                            
3786                            $('body, html').removeClass('overlay-open nav-overlay-open ui-overlay-open');
3787
3788                            
3789                            h.accessibility.on_popup_closing('#menu');
3790                        } else {
3791                            $('.nav-overlay .overlay-bg').addClass('open');
3792                            $('.nav-overlay').addClass('active');
3793                            // $('body, html').addClass('overlay-open nav-overlay-open ui-overlay-open');
3794
3795                        
3796                            $(".nav-contact-module:not(.visible)").each(function(i){
3797                                var $item = $(this);
3798                                setTimeout(function() {
3799                                    $item.addClass('visible')
3800                                }, 300*i);
3801                            });
3802                            $(".nav-wrapper li:not(.visible), .nav-overlay .sidenav-contact-details").each(function(i){
3803                                var $item = $(this);
3804                                setTimeout(function() {
3805                                    $item.addClass('visible')
3806                                }, 100*i);
3807                            });
3808                            h.accessibility.on_popup_opening('.nav-overlay', false, '.nav-close-button');
3809                        }
3810                    }, 50);
3811
3812                });
3813                
3814                $('.fire-pageload').unbind().click(function() {
3815
3816                    var this_link = $(this).attr('data-link');
3817                    
3818                    $('.nav-overlay').addClass('animate-out').removeClass('active');
3819                    
3820                    $(".nav-contact-module.visible").each(function(i){
3821                        var $item = $(this);
3822                        setTimeout(function() {
3823                            $item.removeClass('visible');
3824                        }, 300*i);
3825                    });
3826                    $(".nav-wrapper li.visible").each(function(i){
3827                        var $item = $(this);
3828                        setTimeout(function() {
3829                            $item.removeClass('visible');
3830                        }, 100*i);
3831                    });
3832
3833                    window.setTimeout(function() {
3834                        window.location.href = this_link;
3835                    }, 1500, this_link);
3836                });
3837
3838            },
3839
3840            artworks: function() {
3841                
3842                        //history.pushState({'ajaxPageLoad': true}, null, '/artworks/');
3843                        //$('body').addClass('page-popup-clicked-close');
3844                        //window.history.back();
3845                $('.artworks-overlay-button, .artworks-overlay-close-button').unbind('click.artworks-overlay-click').bind('click.artworks-overlay-click', function(e) {
3846                    var clicked_element = $(this);
3847                	$('#container_outer').removeClass('scrolling-down scrolling-up');
3848                    $('body').addClass('active-init');
3849                    window.setTimeout(function() {
3850                        if ($('.artworks-overlay').hasClass('active')) {
3851                            $('.artworks-overlay').removeClass('show-content');
3852
3853                            $(".nav-contact-module.visible, .nav-wrapper li.visible").removeClass('visible');
3854                            
3855
3856                            setTimeout(function() {
3857	                            $('.artworks-overlay .overlay-bg').removeClass('open');
3858	                            $('.artworks-overlay').removeClass('active');
3859                            	$('body, html').removeClass('overlay-open artworks-overlay-open ui-overlay-open');
3860
3861	                            setTimeout(function() {
3862	                                $('body').removeClass('active-init');
3863                                    $('.artwork-nav-top-level').removeClass('active not-active');
3864                                    $('.artworks-overlay-content').removeClass('second-level-active');
3865	                            }, 600);
3866                            }, 200);
3867                            
3868		                    $('.artwork-nav-top-level .artwork-nav-hero').each(function() {
3869		                    	$(this).find('.image').filter(':eq(0)').addClass('active');
3870		                    });
3871                        } else {
3872                            var relative_id = clicked_element.attr('data-relative-id') && typeof clicked_element.attr('data-relative-id') != 'undefined' ? clicked_element.attr('data-relative-id') : false;
3873                            
3874                            window.site.lazy_load.fire($('.artworks-overlay .image_lazy_load'));
3875                            
3876                        
3877                            $('.artworks-overlay .overlay-bg').addClass('open');
3878                            $('.artworks-overlay').addClass('active');
3879                            $('body, html').addClass('overlay-open artworks-overlay-open ui-overlay-open');
3880
3881                            setTimeout(function() {
3882                                $('.artworks-overlay').addClass('show-content');
3883                            }, 400);
3884                        
3885                            setTimeout(function() {
3886	                        	if ($('body, html').hasClass('nav-overlay-open')) {
3887		                            $('.nav-overlay .overlay-bg').removeClass('open');
3888		                            $('.nav-overlay').removeClass('active');
3889		                            $('body, html').removeClass('nav-overlay-open');
3890		                            $('.nav-contact-module.visible, .nav-wrapper li.visible').removeClass('visible');
3891	                        	}
3892                            }, 800);
3893
3894                            if (relative_id) {
3895                                $('.artworks-overlay .artwork-nav-top-level[data-id="' + relative_id + '"]').trigger('click');
3896                            }
3897                        }
3898                    }, 50, clicked_element);
3899                    return false;
3900                });
3901
3902                $('.artwork-navigation a').unbind().click(function() {
3903                	var selected_element = $(this).closest('li');
3904                	var this_href = $(this).attr('href');
3905                	//$('.artworks-overlay-close-button').trigger('click');
3906                	$(this).closest('li').addClass('selected');
3907                	//$(this).closest('ul').find('li').not('.selected').each(function() {
3908                	//	$(this).slideUp(800);
3909                	//});
3910
3911                	$('.artwork-navigation').addClass('nav-selected');
3912                	//setTimeout(function() {
3913                	//	$(selected_element).addClass('selected2')
3914                	//}, 600, selected_element);
3915                	//setTimeout(function() {
3916                		$.pageload.load(this_href, true, false);
3917                	//}, 1200, this_href);
3918                	return false;
3919                });
3920
3921                $('.artworks-overlay-content').each(function() {
3922                	$('.artwork-nav-top-level').unbind().bind('click.artist-nav-click', function() {
3923                		var this_instance = $(this);
3924                		if (!this_instance.hasClass('active') && !$('.artworks-overlay-content').hasClass('nav-transitioning')) {
3925	                		$(this).closest('.artworks-overlay-content').find('.artwork-nav-top-level').not(this_instance).removeClass('active').addClass('not-active');
3926	                		$(this).addClass('active').removeClass('not-active');
3927	                		$(this).closest('.artworks-overlay-content').addClass('second-level-active');
3928
3929		                    $(this).closest('.artworks-overlay-content').find('.artwork-nav-top-level').not(this_instance).find('.artwork-nav-wrapper li.visible').each(function(i){
3930		                        var $item = $(this);
3931		                        setTimeout(function() {
3932		                            $item.removeClass('visible');
3933		                        }, 100*i);
3934		                    });
3935
3936		                    $(this).closest('.artwork-nav-top-level').find('.artwork-nav-wrapper li').each(function(i){
3937		                        var $item = $(this);
3938		                        setTimeout(function() {
3939		                            $item.addClass('visible');
3940		                        }, 100*i);
3941		                    });
3942
3943                            if (false) {
3944                    			$('.artworks-overlay-content').addClass('nav-transitioning');
3945    							$('.artworks-overlay-content').removeClass('nav-not-transitioning');
3946                    			setTimeout(function() {
3947    								$('.artworks-overlay-content').removeClass('nav-transitioning');
3948    								$('.artworks-overlay-content').addClass('nav-not-transitioning');
3949                    			}, 600);
3950                            }
3951
3952                            var this_top_level_category_offset_top = $(this).offset().top - $('.artwork-navigation').offset().top;
3953                            if (this_top_level_category_offset_top > 0) {
3954                                $('.overlay-container-inner').animate({'scrollTop': this_top_level_category_offset_top}, 600, 'easeInOutExpo');
3955                            }
3956                		}
3957                	});
3958                	$('.artwork-nav-top-level').hover(
3959                		function() {
3960                			$('.artworks-overlay-content').addClass('top-level-hover');
3961                			$(this).parent().find('.artwork-nav-top-level').not(this).removeClass('last-hover');
3962                			//$(this).addClass('last-hover');
3963                		},
3964                		function() {
3965                			$('.artworks-overlay-content').removeClass('top-level-hover');
3966                		}
3967            		);
3968
3969                    if (!window.site.device.handheld() && window.site.device.breakpoint() > 2) {
3970                    	$('.artwork-nav-top-level .artwork-nav-wrapper ul li').hover(
3971                    		function() {
3972                    			if (!$('.artwork-navigation').hasClass('nav-selected')) {
3973    	                			var hero_instance = $(this).closest('.artwork-nav-top-level').find('.artwork-nav-hero');
3974    	                			var this_index = $(this).index() + 1;
3975    	                			hero_instance.find('.artwork-image').removeClass('active');
3976    	                			hero_instance.find('.artwork-image').filter(':eq(' + this_index + ')').addClass('active');
3977    	                			$(this).closest('.artwork-nav-top-level').addClass('subnav-hover');
3978    	                		}
3979                    		},
3980                    		function() {
3981                    			if (!$('.artwork-navigation').hasClass('nav-selected')) {
3982    	                			var hero_instance = $(this).closest('.artwork-nav-top-level').find('.artwork-nav-hero');
3983    	                			hero_instance.find('.artwork-image').removeClass('active');
3984    	                			hero_instance.find('.artwork-image').filter(':eq(0)').addClass('active');
3985    	                			$(this).closest('.artwork-nav-top-level').removeClass('subnav-hover');
3986    	                		}
3987                    		}
3988                		);
3989                    }
3990
3991            		// Reset everything in case we have loaded from a previous page and some of the settings remain from before
3992                    $('.artwork-nav-top-level .artwork-nav-hero').each(function() {
3993                    	$(this).find('.artwork-image').filter(':eq(0)').addClass('active');
3994                    });
3995                    $('.artwork-navigation').removeClass('nav-selected');
3996                    $('.artwork-nav-wrapper ul li').removeClass('selected').attr('style', '');
3997                });
3998
3999                // Artwork menu permalink page
4000                if (window.location.pathname.indexOf('/artworks/section/') == 0) {
4001                    var relative_id = window.location.pathname.replace('/artworks/section/', '').replace('/', '');
4002                    if (relative_id) {
4003                        $('.artwork-nav-top-level[data-id="' + relative_id + '"]').trigger('click');
4004                    }
4005                }
4006                if (window.location.pathname == '/artworks/' || window.location.pathname.indexOf('/artworks/section/') == 0) {
4007                    window.site.lazy_load.fire($('.artwork-navigation .image_lazy_load'));
4008                }
4009
4010                ///////////////////////////////////////////
4011                ///////////////////////////////////////////
4012                // OPEN AUTOMATICALLY FOR DEVELOPMENT
4013                //$('.artworks-overlay-button').trigger('click');
4014                ///////////////////////////////////////////
4015                ///////////////////////////////////////////
4016                /*
4017                $('.fire-pageload').unbind().click(function() {
4018
4019                    var this_link = $(this).attr('data-link');
4020                    
4021                    $('.nav-overlay').addClass('animate-out').removeClass('active');
4022                    
4023                    $(".nav-contact-module.visible").each(function(i){
4024                        var $item = $(this);
4025                        setTimeout(function() {
4026                            $item.removeClass('visible');
4027                        }, 300*i);
4028                    });
4029                    $(".nav-wrapper li.visible").each(function(i){
4030                        var $item = $(this);
4031                        setTimeout(function() {
4032                            $item.removeClass('visible');
4033                        }, 100*i);
4034                    });
4035
4036                    window.setTimeout(function() {
4037                        window.location.href = this_link;
4038                    }, 1500, this_link);
4039                });
4040                */
4041
4042
4043
4044            }
4045
4046        },
4047        artwork_filters: {
4048            
4049          
4050            init: function() {
4051                
4052                window.site.artwork_filters.checked_items();
4053                window.site.artwork_filters.clear_filters();
4054                window.site.artwork_filters.responsive_filter_btn();
4055                // Responsive show/hide filter menu handler
4056                $('.artwork-filter-responsive-btn').on('click', function(e){
4057                    $('#artwork-filter-panel').toggleClass('show')
4058                });
4059                
4060                // Stop enter key from submitting the form and make it trigger checkbox change instead
4061                $('#filterpanel_form input').off().on('keydown', function (e) {
4062                    var keyCode = e.which;
4063                    if ($("this:focus") && (keyCode == 13)) {
4064                        e.preventDefault();
4065                        if ($(this).attr('checked')) {
4066                            $(this).attr('checked',false);
4067                            $(this).trigger("change");
4068                        } else {
4069                            $(this).attr('checked',true);
4070                            $(this).trigger("change");
4071                        }
4072                    }
4073                });
4074              
4075                // Individual filter item click handler
4076                $('#filterpanel_form input').on('change', function(e){
4077                    
4078                    
4079                    
4080                    // Updates the selected filter count if .group-count exists
4081                    window.site.artwork_filters.checked_items();
4082                    
4083                    /**
4084                     * SUBMITS THE FORM, DISPLAYS THE CONTENT
4085                     */
4086                    window.site.artwork_filters.load_works();
4087                    
4088                    $('.fp-module').removeClass("open");
4089                });
4090                
4091                $('#filterpanel_form label').on('click', function(e) {
4092                    // Prevents a bug where the checkbox click event was triggered twice.
4093                    e.stopPropagation();
4094                });
4095                
4096                //CLICK FOR MOBILE ONLY
4097                $('body.device-handheld .fp-module button').click(filter_handler);
4098                
4099                //KEYDOWN FOR ADA
4100                $('.fp-module button').keydown(filter_handler);
4101                
4102                
4103                function filter_handler(e){
4104                    
4105                    console.log('drop handler');
4106                    
4107                    if(e.type == "keydown"){
4108                    
4109                        var keyCode = e.which;
4110                        var dropdown_type = '.fp-module--' + $(this).attr("data-dropdown");
4111                        if ($("this:focus") && (keyCode == 13 || keyCode == 32)) {
4112                            if ($(dropdown_type).hasClass('open')) {
4113                                $(this).attr("aria-expanded", "false");
4114                                $(dropdown_type).removeClass('open');
4115                            } else {
4116                                $(this).attr("aria-expanded", "true");
4117                                $(dropdown_type).addClass("open");
4118                            }
4119                        } else if ($("this:focus") && (keyCode == 9 && e.shiftKey) && $(dropdown_type).hasClass('open')) {
4120                            $(this).attr("aria-expanded", "false");
4121                            $(dropdown_type).removeClass('open');
4122                        }
4123                        
4124                    } else if(e.type == "click") {
4125                        
4126                        var $fpmodule = $(this).closest('.fp-module');
4127                        
4128                        if ($fpmodule.hasClass('open')) {
4129                            console.log('true');
4130                            $(this).attr("aria-expanded", "false");
4131                            $fpmodule.removeClass('open');
4132                        } else {
4133                            console.log('false');
4134                            $('.fp-module').removeClass('open');
4135                            $(this).attr("aria-expanded", "true");
4136                            $fpmodule.addClass("open");
4137                        }
4138                    }
4139                }
4140                
4141                function closeFilterDropdown(dropdown_name) {
4142                    $('.fp-module--' + dropdown_name).removeClass("open");
4143                    $('.fp-module--' + dropdown_name + ' button').attr("aria-expanded", "false");
4144                }
4145                
4146                // Close dropdown menu if tab focus goes off dropdown menu
4147                $('#filterpanel_form input').on('keydown', function (e) {
4148                    var keyCode = e.which;
4149                    if ($(this).hasClass('first_item') && $("this:focus") && (keyCode == 9 && e.shiftKey)) {
4150                        closeFilterDropdown($(this).attr("data-dropdown"));
4151                    } else if ($(this).hasClass('last_item') && $("this:focus") && (keyCode == 9 && !e.shiftKey)) {
4152                        closeFilterDropdown($(this).attr("data-dropdown"));
4153                    } else if ($("this:focus") && (keyCode == 27)) {
4154                        closeFilterDropdown($(this).attr("data-dropdown"));
4155                        $('.fp-module--' + $(this).attr("data-dropdown") + ' button').focus();
4156                    }
4157                });
4158                
4159                // Close keyword dropdown menu if tab focus goes off input
4160                $('#filterpanel_form .fp-module--keyword input').on('keydown', function (e) {
4161                    var keyCode = e.which;
4162                    if ($("this:focus") && (keyCode == 9)) {
4163                        var dropdown_name = $(this).attr("data-dropdown")
4164                        $('.fp-module--keyword').removeClass("open");
4165                        $('.fp-module--keyword button').attr("aria-expanded", "false");
4166                    }
4167                });
4168              
4169                // /**
4170                //  * OPEN/CLOSE THE FILTER LIST CONTAINER
4171                //  */
4172                // $('.fp-legend').on('click', function(e){
4173                    
4174                //     if(!$(this).closest('.fp-module').hasClass('visible')){
4175                //         // Prevent the window handler from being triggered.
4176                //         e.stopPropagation();
4177                //         // Hide any already open panels
4178                //         $('.fp-module').removeClass('visible');
4179                //         // Show the list attached to the clicked heading
4180                //         $(this).closest('.fp-module').toggleClass('visible');
4181                      
4182                //         // Clicking anywhere else on the page will close the opened group
4183                //         $(window).one('click', function(){
4184                //             $('.fp-module').removeClass('visible');
4185                //         });
4186                //     } else {
4187                //         // No need to do anything as the click listener on window will remove the visible class.
4188                //         return;
4189                //     }
4190                // });
4191            },
4192            
4193            checked_items: function(){
4194                
4195                $('#filterpanel_form .fp-module').each(function(){
4196                    var checked_count = $(this).find('input:checked').length;
4197                    //console.log(checked_count)
4198                    if(checked_count > 0) {
4199                        $(this).addClass('active');
4200                        $(this).find('.fp-group-count').html('('+ String(checked_count) + ')');
4201                    } else {
4202                        $(this).find('.fp-group-count').html('');
4203                    }
4204                });
4205                
4206            },
4207            
4208            processRangeCheckbox: function(){
4209                /**
4210                 * 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.
4211                 * For all the selected checkboxes find the data-min and data-max values(which should be set on the input element). 
4212                 * Assign the min/max values to relevant array selectedMins/selectedMaxs and then use the ARRAY.sort() func to order them in ascending order.
4213                 * 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.
4214                 * Assign these to the hidden inputs so they are passed when the form is serialized/submitted.
4215                 */
4216                $('.range-parent').each(function(){
4217                    var selectedRanges = $(this).find('input:checked');
4218                    
4219                    if(!selectedRanges.length){ 
4220                        $(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.
4221                        return; // Don't bother to process if there aren't any checked checkboxes
4222                    } 
4223                    
4224                    // Remove the disabled attribute for the min and max inputs as a checkbox is selected
4225                    $(this).find('.range_min, .range_max').removeAttr('disabled');
4226                    
4227                    var parent = $(this).closest('.range-parent');
4228                    var selectedMins = [];
4229                    var selectedMaxs = [];
4230                    for (var i = 0; i < selectedRanges.length; i++) {
4231                        selectedMins.push(parseInt( ($(selectedRanges[i]).data('min') || 0) ));
4232                        selectedMaxs.push(parseInt( ($(selectedRanges[i]).data('max') || 100000000) ));
4233                    }
4234                    // Order the min and max arrays in ascending order
4235                    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.
4236                    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.
4237                    
4238                    var minValue = selectedMinsSorted[0];
4239                    var maxValue = selectedMaxsSorted[selectedMaxsSorted.length - 1]; // the last item
4240                    
4241                    // Update the hidden inputs with the corresponding values
4242                    $(this).find('.range_min').val(minValue);
4243                    $(this).find('.range_max').val(maxValue);
4244                });  
4245            },
4246            
4247            load_works: function($filterPanelForm) {
4248                /**
4249                 * Serializes and submits the form.
4250                 * The result will be loaded into the inner_content_selector element.
4251                 */
4252                if(typeof $filterPanelForm == 'undefined') {
4253                    $filterPanelForm = $('#filterpanel_form');
4254                }
4255                
4256                var pathToSubmitForm = $filterPanelForm.attr('action');
4257                if (pathToSubmitForm){
4258                    
4259                    //process the range checkboxes
4260                    window.site.artwork_filters.processRangeCheckbox();
4261                    
4262                    var serializedForm = $filterPanelForm.serialize();
4263                    
4264                    if(serializedForm.length){
4265                        var updated_url = pathToSubmitForm + '?' + serializedForm;
4266                    } else {
4267                        var updated_url = pathToSubmitForm
4268                    }
4269                    
4270                    // console.log(updated_url);
4271                    
4272                }   
4273
4274                var incoming_content_type = 'inner';
4275                
4276                // $.pageload.load(updated_url, false, function(new_page_inner_content, element_href, new_page_main_content) {
4277                //     if (new_page_inner_content) {
4278                //         $('.filter_results')
4279                //             .addClass('filter_transition')
4280                //             .delay(400)
4281                //             .queue(function() {
4282    
4283                //                 //if ($('body').hasClass('navigation-filters-open') || clear_filters || filter_text_active) {
4284                //                     history.replaceState({'ajaxPageLoad': true}, null, updated_url);
4285                //                 //}
4286                                
4287                //                 var full_html = $(new_page_main_content);
4288                //                 $('.filter_results').html(full_html.find('.filter_results').html());
4289                //                 $('.filter_results').removeClass('filter_transition');
4290
4291                //                 window.cart.init();
4292                //                 window.site.enquiry.init();
4293                //                 window.site.overlays.enquire.init(
4293);
4294                //                 window.site.artlogic_inview.init();
4295                //                 window.site.lazy_load.setup();
4296                //                 window.site.lazy_load.fire($('.image_lazy_load'));
4297                //                 window.site.layout.grids.init();
4298                                
4299                //                 $(window).trigger('resize');
4300                //                 $.pageload.refresh();
4301                                
4302                                
4303                //                 $(this).dequeue();
4304                //             })
4305                //         ;
4306                //     }
4307                // }, null, null, null, incoming_content_type);
4308 
4309 
4310                $.pageload.load(updated_url, true, function() {
4311                    
4312
4313                    $new_page_inner_content = $(new_page_main_content);
4314                        
4315                    // console.log(new_page_inner_content);    
4316                        
4317                        
4318                    if (new_page_inner_content) {
4319                        
4320                        $('.filter_results')
4321                            .addClass('filter_transition')
4322                            .delay(400)
4323                            .queue(function() {
4324    
4325                                //if ($('body').hasClass('navigation-filters-open') || clear_filters || filter_text_active) {
4326                                    history.replaceState({'ajaxPageLoad': true}, null, updated_url);
4327                                //}
4328                                var $full_html = $(new_page_main_content);
4329                                var $dynamic_filter_results = $full_html.find('.filter_results')
4330                                
4331                                // console.log(full_html.find('.filter_results .item').length);
4332                              
4333                                $('.filter_results').html($dynamic_filter_results.html());
4334                                
4335                                $('.list-ajax-load-more-wrapper').remove();
4336                                
4337                                if ($full_html.find('.page_stats').length) {
4338                                    
4339                                    if (!$('.page_stats').length) {
4340                                        $full_html.find('.page_stats').insertAfter( ".filter_results" );
4341                                        $('.page_stats').data($dynamic_filter_results.data());
4342                                    } else {
4343                                        $('.page_stats').html($full_html.find('.page_stats').html());
4344                                    }
4345                                } else {
4346                                    $('.page_stats').remove();
4347                                }
4348                                
4349                                window.site.pageload_load_more_pagination.init();
4350                                
4351                                $('.filter_results').removeClass('filter_transition');
4352                                
4353
4354
4355                                window.cart.init();
4356                                window.site.enquiry.init();
4357                                window.site.overlays.enquire.init();
4358                                window.site.artlogic_inview.init();
4359                                window.site.lazy_load.setup();
4360                                window.site.lazy_load.fire($('.image_lazy_load'));
4361                                window.site.layout.grids.init();
4362                                
4363                                $(window).trigger('resize');
4364                                $.pageload.refresh();
4365                                
4366                                
4367                                $(this).dequeue();
4368                            })
4369                        ;
4370                    }
4371
4372              
4373                    
4374                }, null, null, null, incoming_content_type, '.section-artwork-grid');
4375 
4376
4377 
4378            },
4379            
4380            clear_filters: function(){
4381                
4382                $('.clear_filters').on('click', function(e){
4383                    e.preventDefault();
4384                    $('#filterpanel_form input').prop('checked', false);
4385                    $('#filterpanel_form').find('.group-count').html('');
4386                    window.site.artwork_filters.load_works();
4387                });
4388                
4389            },
4390            
4391            responsive_filter_btn: function() {
4392                
4393                $('.artwork-filter-open-btn').on('click', function() {
4394                    //console.log('open responsive');
4395                    if($('#filterpanel_form').hasClass('open')){
4396                        $('#filterpanel_form').removeClass('open');
4397                        $('#filterpanel_form').attr('style','')
4398                    } else {
4399                        $('#filterpanel_form').addClass('open');
4400                        window.site.helpers.animate_height($('#filterpanel_form'));
4401                    }
4402                });
4403                
4404            }
4405            
4406        },
4407        
4408        publication_filters: {
4409            
4410            init: function(){
4411                
4412                if ($('body').hasClass('section-publications') || $('body').hasClass('section-shop') || $('body').hasClass('section-vi
4412deo')) {
4413                        
4414                    window.site.publication_filters.lists_artist_filter_reveal();
4415                    window.site.publication_filters.lists_artist_filter_height();
4416                    
4417                    $(window).resize(function(){
4418                        window.site.publication_filters.lists_artist_filter_height();
4419                    });
4420    
4421            
4422                }
4423            },
4424                
4425            lists_artist_filter_height: function() {
4426                $('#list-filter-style').remove();
4427                
4428                var artists_nav_height = $("#publications_artists_nav").height() + 20;
4429                var year_nav_height = $("#publications_years_nav").height() + 20;
4430                
4431                $('head').append('<style id="list-filter-style" type="text/css">.publications_artists_nav_wrapper.open { max-height:' +artists_nav_height+ 'px}; .publications_years_nav_wrapper.open { max-height:' +year_nav_height+ 'px}</style>');
4432            },
4433            
4434            
4435            lists_artist_filter_reveal: function() {
4436                
4437                $('#publications_nav li a').click(function(event) {
4438                    event.preventDefault();
4439                    var filter_id = $(this).data('filter-reveal');
4440                    
4441                    if ($(filter_id).hasClass('open')) {
4442                        
4443                        $(filter_id).removeClass('open');
4444                        $(filter_id).removeClass('forced-open');
4445                    } else {
4446                        $('.list-reveal-wrapper').removeClass('open');
4447                        $(filter_id).addClass('open');
4448                    }
4449                });
4450                
4451                // if ($('#nav_artists.active').length && window.innerWidth > 767) {
4452                //     $('#filters_artists_nav').addClass('forced-open');
4453                //     $('body').css('min-height', '6000px');
4454                //     setTimeout(function() {
4455                //         $('#filters_artists_nav').addClass('forced-open');
4456                //         var artists_nav_offset_top = $("#filters_artists_nav").offset().top + $("#filters_artists_nav").height() - 50;
4457                //         $("#filters_artists_nav").addClass('open');
4458                //         $('html,body').animate({'scrollTop': artists_nav_offset_top + 'px'}, 0);
4459                //         $('body').css('min-height', '0');
4460                //     }, 200);
4461                // }
4462            }
4463            
4464        },
4465
4466        
4467        artlogic_inview: {
4468
4469        	default_elements: '.inview_element, .hide-off-screen, .scroll_section_top, .faux_footer, .records_slider_panel',
4470
4471        	options: {
4472				rootMargin: '0px', //Viewport margins 10px 20px 30px 40px
4473				threshold: [0, 0.1, 0.3, 0.5, 0.7, 1]  //how much needs to be showing. Fires IN and Out by that amount
4474            },
4475            
4476            
4477            intersection_supported: function() {
4478                
4479                if (!('IntersectionObserver' in window) ||
4480                    !('IntersectionObserverEntry' in window) ||
4481                    !('intersectionRatio' in window.IntersectionObserverEntry.prototype)||
4482                    !('isIntersecting' in window.IntersectionObserverEntry.prototype))  {
4483                    return false;
4484                } else {
4485                    return true;
4486                }
4487            },
4488            
4489
4490            init: function(context) {
4491                
4492                $('#container').removeClass('hero-section-visible');
4493                $('#container').addClass('hero-section-not-visible');
4494                $('#container_outer').removeClass('page-enquiry-visible');
4495                $('#container_outer').addClass('page-enquiry-not-visible');
4496
4497                if (!window.site.artlogic_inview.intersection_supported()) {
4498                    
4499                	// Compatability mode if intersection observer does not work
4500   
4501                    console.log('fallback  scroll dectection');
4502                	
4503                	$(window.site.artlogic_inview.default_elements).each(function() {
4504                	    
4505	                    var $entry = $(this);
4506
4507                    	if ($entry.hasClass('inview_element')) {
4508                    	    
4509                    	    $entry.css('visibility','visible');
4510                    	    
4511	                    	$entry.addClass('visible');
4512                            var video_element = $entry.find('video');
4513                            var lazy_load_context = $('.image_lazy_load');
4514                            var lazy_load_element = $entry.find('.image_lazy_load').not('.loaded, .loading');
4515                            var position_of_lazy_load_element = lazy_load_context.
4515index($entry.find('.image_lazy_load'));
4516
4517                            var lazy_load_element_to_fire = lazy_load_element;
4518                            if (position_of_lazy_load_element > 0) {
4519                            	var adjacent_lazy_load_elements = lazy_load_context.slice(position_of_lazy_load_element, position_of_lazy_load_element + 4);
4520                            	lazy_load_element_to_fire = adjacent_lazy_load_elements;
4521                            }
4522
4523                            if (lazy_load_element_to_fire.length) {
4524                            	window.site.lazy_load.fire(lazy_load_element_to_fire);
4525                            }
4526
4527                            if (video_element.length && window.site.device.video_inline()) {
4528                                video_element.get(0).play();
4529                            }
4530                        }
4531                	});
4532                    $(window).bind('scroll', window.site.throttle(50, function() {
4533                        
4534                        
4535                        
4536                        $(window.site.artlogic_inview.default_elements).each(function() {
4537                            
4538                            var $entry = $(this);
4539                            
4540                            if ($entry.hasClass('faux_footer')) {
4541                                 if ($(window).scrollTop() + $(window).height() > $entry.offset().top) {
4542                                    $('#container').addClass('footer-visible');
4543                                 } else {
4544                                    $('#container').removeClass('footer-visible');
4545                                 }
4546                            }
4547                            
4548                            if ($entry.hasClass('scroll_section_top') && $entry.hasClass('hide-off-screen')) {
4549                                
4550                                if ($(window).scrollTop() > $(window).height()) {
4551                                    
4552                                    if (!$entry.hasClass('hidden-off-screen')) {
4553                                        $entry.addClass('hidden-off-screen')
4554                                    }
4555                                    if (!$('#container').hasClass('hero-section-not-visible')) {
4556                                        $('#container').addClass('hero-section-not-visible')
4557                                        $('#container').removeClass('hero-section-visible');
4558                                    }
4559                                } else {
4560                                    if ($entry.hasClass('hidden-off-screen')) {
4561                                        $entry.removeClass('hidden-off-screen ')
4562                                    }
4563                                    if (!$('#container').hasClass('hero-section-visible')) {
4564                                        $('#container').removeClass('hero-section-not-visible')
4565                                        $('#container').addClass('hero-section-visible');
4566                                    }
4567                                }
4568                            }
4569                        });
4570                    }));
4571                    
4572                    $(window).trigger('scroll');
4573                    
4574                } else {
4575
4576	                var default_context = window.site.artlogic_inview.default_elements;
4577	                var context = (context && typeof context != 'undefined' ? context : default_context);
4578
4579	                // SETUP THE OBSERVER
4580	                artlogic_observer = new IntersectionObserver(window.site.artlogic_inview.callback, window.site.artlogic_inview.options);
4581
4582	                /// SET TARGETS
4583	                var targets = document.querySelectorAll(context);
4584	                // Watch the targets
4585	                for (var i = targets.length - 1; i >= 0; i--) {
4586	                	// UNBIND OBSERVERS IF THEY ARE ALREADY RUNNING
4587	                	artlogic_observer.unobserve(targets[i]);
4588	                }
4589	                for (var i = targets.length - 1; i >= 0; i--) {
4590	                	// OBSERVE ELEMENTS
4591	                    artlogic_observer.observe(targets[i]);
4592	                }
4593	                $('.inview_element').addClass('animate-from-bottom');
4594                }
4595
4596    
4597            },
4598
4599            destroy: function() {
4600            	if (typeof artlogic_observer == 'undefined') {
4601            		artlogic_observer = false;
4602            	}
4603            	if (artlogic_observer && typeof artlogic_observer != 'undefined') {
4604	            	var elements = window.site.artlogic_inview.default_elements;
4605	                var targets = document.querySelectorAll(elements);
4606	                for (var i = targets.length - 1; i >= 0; i--) {
4607	                	artlogic_observer.unobserve(targets[i]);
4608	                }
4609            	}
4610            },
4611            
4612            callback: function(entries, observer) {
4613
4614                entries.forEach(function(entry) {
4615                    
4616                    var $entry = $(entry.target);
4617                    var ratio_onscreen = entry.intersectionRatio;
4618
4619                    /////GALLERY SECTIONS
4620                    if ($entry.hasClass('inview_element')) {
4621                        var video_element_embed = $entry.find('.video_embed_wrapper');
4622                        var video_element = $entry.find('video');
4623                        var intro_content = $entry.hasClass('inview_element_intro');
4624                        $entry.attr('data-ratio_onscreen', ratio_onscreen);
4625                        if (!entry.isIntersecting) {
4626                            // SETTING ABOVE AND BELOW CLASSES
4627                            if (entry.boundingClientRect.top >= 0){
4628                                //Scrolling down
4629                                $entry.addClass('animate-from-bottom').removeClass('animate-from-top');
4630                            } else {
4631                                //Scrolling up
4632                                $entry.addClass('animate-from-top').removeClass('animate-from-bottom');
4633                            }
4634                            $entry.removeClass('visible');
4635                            if (video_element.length) {
4636                                video_element.get(0).pause();
4637                            }
4638                            if (video_element_embed.length) {
4639                                if (video_element_embed.hasClass('video_playing')) {
4640                                    video_element_embed.removeClass('video_playing');
4641                                    video_element_embed.find('.video_embed_pause').trigger('click');
4642                                }
4643                            }
4644                            if (intro_content) {
4645                            	//$entry.removeClass('inview_element_intro_timeout');
4646                            }
4647                            if ($entry.hasClass('page_enquiry_widget')) {
4648                            	if (!entry.boundingClientRect.top >= 0){
4649	                            	$('#container_outer').removeClass('page-enquiry-visible');
4650                                    $('#container_outer').addClass('page-enquiry-not-visible');
4651	                            }
4652                            }
4653                        } else {
4654                            $entry.css('visibility','visible');
4655                            $entry.addClass('visible');
4656                            
4657                            var lazy_load_context = $('.image_lazy_load');
4658                            var lazy_load_element = $entry.find('.image_lazy_load').not('.loaded, .loading');
4659                            var position_of_lazy_load_element = lazy_load_context.index($entry.find('.image_lazy_load'));
4660
4661                            var lazy_load_element_to_fire = lazy_load_element;
4662                            if (position_of_lazy_load_element > 0) {
4663                            	var adjacent_lazy_load_elements = lazy_load_context.slice(position_of_lazy_load_element, position_of_lazy_load_element + 12);
4664                            	lazy_load_element_to_fire = adjacent_lazy_load_elements;
4665                            }
4666
4667                            if (lazy_load_element_to_fire.length) {
4668                            	window.site.lazy_load.fire(lazy_load_element_to_fire);
4669                            }
4670
4671                            if (video_element.length && window.site.device.video_inline()) {
4672                           	    video_element.get(0).play();
4673                            }
4674                            
4675                            if (video_element_embed.length) {
4676                                if (!video_element_embed.hasClass('video_playing')) {
4677                                    video_element_embed.addClass('video_playing');
4678                                    video_element_embed.find('.video_embed_play').trigger('click');
4679                                }
4680                            }
4681
4682                            if (intro_content) {
4683                            	window.setTimeout(function() {
4684                            		$entry.addClass('inview_element_intro_timeout');
4685                            	}, 2000, $entry);
4686                            }
4687                            if ($entry.hasClass('page_enquiry_widget')) {
4688                            	$('#container_outer').addClass('page-enquiry-visible');
4689                                $('#container_outer').removeClass('page-enquiry-not-visible');
4690                            }
4691                        }
4692                    }
4693
4694                    ///// Footer
4695                    if ($entry.hasClass('faux_footer')) {
4696                        if (entry.isIntersecting) {
4697                        	$('#container').addClass('footer-visible');
4698                        	if ( ratio_onscreen > 0.5) {
4699                        		$('#container').addClass('footer-visible2');
4700                        	}
4701                        	if ( ratio_onscreen > 0.75) {
4702                        		$('#container').addClass('footer-visible3');
4703                        	}
4704                    	} else {
4705                        	$('#container').removeClass('footer-visible footer-visible2 footer-visible3');
4706                    	}
4707                    }
4708                    
4709                    ///// DEACTIVATE EXPENSIVE STUFF WHEN OUT OF SITE
4710                    if ($entry.hasClass('hide-off-screen')) {
4711                        if (entry.isIntersecting) {
4712                            $entry.removeClass('hidden-off-screen');
4713                        } else {
4714                            $entry.addClass('hidden-off-screen');
4715                        }
4716                    }
4717
4718                    if ($entry.hasClass('scroll_section_top')) {
4719                        
4720                        if (entry.isIntersecting) {
4721                            
4722                            
4723                            $('#container').removeClass('hero-section-not-visible');
4724                            $('#container').addClass('hero-section-visible');
4725                        } else {
4726                            $('#container').addClass('hero-section-not-visible');
4727                            $('#container').removeClass('hero-section-visible');
4728                        }
4729                    }
4730                    if ($entry.hasClass('scroll_section_top') && $entry.find('.main_slideshow')) {
4731                        if (entry.isIntersecting) {
4732                           $('#main_slideshow').cycle('resume');
4733                        } else {
4734                            $("#main_slideshow:not('.slide-changing'):not('.cycle-paused')").cycle('pause');
4735                           
4736                        }
4737                    }
4738                });
4739            }
4740        },
4741
4742        lazy_load: {
4743
4744        	init: function() {
4745        		window.site.lazy_load.setup();
4746        		// Fire lazy load on the first few elements
4747        		window.site.lazy_load.fire($('.image_lazy_load').slice(0,3));
4748        	},
4749
4750        	setup: function() {
4751                $('.image_lazy_load').each(function() {
4752                    // Only process lazy load images if they do not already have a loading class
4753                    if ($(this).find('img').length && !$(this).hasClass('loading') && !$(this).hasClass('initialized')) {
4754                    	if (false) {
4755                    		// Development functionality to show an initial low resolution image before the high-res is lazy-loaded
4756	                    	var image_src_init = $(this).find('img').attr('data-src-init');
4757	                    	if (image_src_init && typeof image_src_init != 'undefined') {
4758	                    		$(this).append('<img class="init_img" src="' + image_src_init + '" />');
4759	                    	}
4760                    	} else {
4761                    		$(this).append('<i class="loader spinning"></i>');
4762                    	}
4763                    }
4764                    
4765                    $(this).addClass('initialized');
4766                });
4767        	},
4768
4769        	fire: function(element) {
4770                $(element).each(function() {
4771                    
4772                    var image_elem;
4773                    if ($(this).hasClass('image_lazy_load')){
4774                        image_elem = $(this);
4775                    } else {
4776                        image_elem = $(this).closest('.image_lazy_load');
4777                    }
4778                    
4779                // 	if ((!$(this).hasClass('loaded') || $(this).hasClass('loading')) && $(this).hasClass('initialized')) {
4780                    if (!$(this).hasClass('loaded')) {
4781	                	$(this).addClass('loading');
4782	                    $(this).find('img[data-src]').each(function() {
4783	                        var image_src = $(this).attr('data-src');
4784	                        $(this).attr('src', image_src)
4785	                        
4786	                        function imageLoaded(img_element) {
4787	                            image_elem.trigger('change.lazyload');
4788                                $(img_element).trigger('change.lazyload');
4789                                
4790                                if (image_elem.hasClass('loading')) {
4791                                    $(img_element)
4792                                        .delay(300)
4793                                        .queue(function() {
4794                                            image_elem.removeClass('loading').addClass('loaded');
4795                                            $(img_element).dequeue();
4796                                        })
4797                                        .delay(600)
4798                                        .queue(function() {
4799                                            image_elem.removeClass('loading-init');
4800                                            image_elem.find('.loader').remove();
4801                                            $(img_element).dequeue();
4802                                        })
4803                                    ;
4804                                }
4805	                        }
4806	                        
4807	                        if (this.complete) {
4808                                imageLoaded(this);
4809                            } else {
4810                                $(this).load(function() {
4811                                    imageLoaded(this);
4812                                });
4813                            }
4814	                        
4815	                    });
4816                	}
4817                });
4818        	}
4819
4820        },
4821
4822        artworks: {
4823
4824        	init: function() {
4825        		window.site.artworks.setup();
4826        	},
4827
4828        	setup: function() {
4829
4830        		window.site.artworks.resize();
4831                $(window).resize(function() {
4832                    window.site.artworks.resize();
4833                });
4834
4835        		$('.artwork_detail').each(function() {
4836        			$(this).addClass('visible');
4837        			//console.log('ssss');
4838	        		window.site.lazy_load.fire($('.artwork_hero_image_container'));
4839	        		window.site.lazy_load.fire($('.artwork_detail .image_lazy_load'));
4840	        		
4841
4842                    if ($('.artwork_detail_add_to_cart_wrapper .fallback_cart_wrapper', this).length) {
4843                        $('.tools .enquire_link', this).parent().remove();
4844                    }
4845        		});
4846
4847        		$('.artwork_detail .image:not(.has_video)').unbind('click.zoom-activate').bind('click.zoom-activate', function() {
4848                    if (window.site.device.breakpoint() >= 3) {
4849                        if (!$('body').hasClass('user-distraction-free')) {
4850                            $('body').addClass('user-distraction-free');
4851                        } else if (!$('body').hasClass('zoom-active') && $(this).hasClass('super_zoom_enabled')) {
4852                            $(this).closest('.artwork_detail').addClass('zoom-active');
4853                            $('body').addClass('zoom-active');
4854                        } else {
4855                            $(this).closest('.artwork_detail').removeClass('zoom-active');
4856                            setTimeout(function() {
4857                                $('body').removeClass('zoom-active user-distraction-free');
4858                            }, 400);
4859                        }
4860                    }
4861        		});
4862                
4863                $('.artwork_detail .image.has_video').click(function(e) {
4864                    var iframe = $(this).find('iframe');
4865           
4866                    if (iframe.length && e.screenX) {
4867                        $(this).find('.video_placeholder').fadeOut();
4868                        
4869                        var iframe_src = iframe.attr('src').replace('autoplay=0', 'autoplay=1');
4870                        iframe.attr('src', iframe_src);
4871                    }
4872                });
4873
4874
4875                $('.artwork_detail .image_container, .artwork_detail .image_container .image .image_inner').each(function() {
4876
4877                    
4878                    if (!window.site.device.handheld()) {
4879                        
4880                        var $this_image = $(this);
4881                        $this_image.addClass('image-hover-disabled');
4882                        setTimeout(function() {
4883                            $this_image.removeClass('image-hover-disabled');
4884                        }, 2000);
4885                        
4886                        // Disabled on handheld as this stops users from swiping through the works.
4887                        var zoom_image = $this_image.attr('data-zoom-url');
4888                        var zoom_type = $('.artwork_detail_type_standard').length || window.site.device.handheld() ? 'click' : 'mouseover';
4889                        if (zoom_image && typeof zoom_image != 'undefined') {
4890                            $this_image.zoom({
4891                                url: zoom_image,
4892                                duration: 400,
4893                                on: zoom_type,
4894                                onZoomIn: function(){
4895                                    $('body').addClass('zoom-active');
4896                                },
4897                                onZoomOut: function(){
4898                                    $('body').removeClass('zoom-active');
4899                                }}
4900                            );
4901                        }
4902                    }
4903                });
4904
4905
4906                $('.image_gallery_multiple')
4907                    .each(function() {
4908                        $(this)
4909                            .cycle({
4910                                fx:       'fade',
4911                                speed:    600,
4912                                timeout:  12000,
4913                                paused:    true,
4914                                slides: '>',
4915                                autoHeight: false,
4916                                swipe: true
4917                            })
4918                            .on('cycle-before', function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
4919                                var hero_slide = $(incomingSlideEl).hasClass('image_hero_placeholder');
4920                                if (hero_slide) {
4921                                    $('.artwork_hero_image_container').addClass('active');
4922                                } else {
4923                                    $('.artwork_hero_image_container').removeClass('active');
4924                                }
4925                            })
4926                        ;
4927                        
4928                        $(this).parent().find('.pagination_controls_previous').unbind().bind('click', function() {
4929                            $(this).closest('.image_gallery_multiple_container').find('.image_gallery_multiple').cycle('pause').cycle('prev');
4930                            return false;
4931                        });
4932                        $(this).parent().find('.pagination_controls_next').unbind().bind('click', function() {
4933                            $(this).closest('.image_gallery_multiple_container').find('.image_gallery_multiple').cycle('pause').cycle('next');
4934                            return false;
4935                        });
4936                    })
4937                ;
4938
4939
4940
4941
4942
4943                    if ($(".roomview-image").length) {
4944                        $(".roomview-image").each(function(){
4945                            const rv_options = {
4946                                wall_type: 'standard', // Options: 'standard', 'concrete', 'brick'
4947                                verbose_mode: false
4948                            }
4949                            // Supply a json config in the html:  data-roomview-custom-config='{"furniture_type":"my_chair","furniture_items": {"rs_chair":{"classname_suffix":"my_chair","furniture_width_cm":148}}}'
4950                            var custom_config = $(this).data('roomview-custom-config');
4951    
4952                            if (custom_config && typeof custom_config != 'undefined') {
4953                                if (custom_config.furniture_type && typeof custom_config.furniture_type != 'undefined') {
4954                                    rv_options["furniture_type"] = custom_config.furniture_type;
4955                                }
4956                                if (custom_config.furniture_items && typeof custom_config.furniture_items != 'undefined') {
4957                                    rv_options.furniture_items = custom_config.furniture_items;
4958                                }
4959                            }
4960                            $(this).roomView(rv_options);
4961                        });
4962                }
4963
4964
4965        		$('.roomview-button-custom').unbind().click(function(e) {
4966                    e.preventDefault();
4967                    
4968                    // For accessibility - tracks which element to refocus on
4969                    try {
4970                        h.accessibility.global_variables.element_to_refocus_to = $(this).children('a');
4971                    } catch(error) {
4972                        console.error(error);
4973                    }
4974                    
4975                    var roomview_id = $(this).attr('data-roomview-id');
4976                    if (roomview_id && typeof roomview_id != 'undefined') {
4977                        if ($('.artwork_detail_main .image_container').find('.image_gallery_multiple').length) {
4978                            var roomview_instance = $('.artwork_detail_main .image_container .image:not(.cycle-sentinel) .roomview-image[data-roomview-id="' + roomview_id + '"]');
4979                            
4980                        } else {
4981                            var roomview_instance = $('.artwork_detail_main .image_container .roomview-image[data-roomview-id="' + roomview_id + '"]');
4982                        }
4983                        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')) {
4984                            // Change slide before view in a room starts
4985                            var this_slide_index = roomview_instance.closest('.cycle-slide').index($('.artwork_detail_main .image_container .image_gallery_multiple .cycle-slide').not('.cycle-sentinel'));
4986                            var timeout_length = 600;
4987                            if (roomview_instance.closest('.cycle-slide').hasClass('cycle-slide-active')) {
4988                                var timeout_length = 0;
4989                            }
4990                            if (this_slide_index > -1) {
4991                                $('.image_gallery_multiple').cycle(this_slide_index);
4992                                setTimeout(function() {
4993                                    roomview_instance.roomView('open');
4994                                }, timeout_length, roomview_instance);
4995                            }
4996                        } else {
4997                            roomview_instance.roomView('open');
4998                        }
4999                    }
5000                });
5001
5002
5003
5004
5005
5006                if (false) {
5007                	// Add shipping info next to add to cart buttons
5008	                $('.artwork_detail .store_item').each(function() {
5009	                    if (!$('.delivery_info', this).length && !$('.price.sold_out', this).length) {
5010	                        $(this).append('<div class="delivery_info">Free UK shipping</div>')
5011	                    }
5012	                });
5013                }
5014
5015                $('.artwork_detail').each(function() {
5016                    $('.artwork_detail_type_editions').append('<div class="footer">' + $('#footer').html() + '</div>');
5017                    window.site.mailing_list_form.init();
5018                });
5019
5020                $('.artwork_hero_image_container').on('change.lazyload', function() {
5021                    var hero_image_path = $(this).find('.image_hero_full_image_duplicate').attr('src');
5022                    $('.artwork_hero_image_container .image').css({'background-image': "url('" + hero_image_path + "')"});
5023                });
5024
5025                $('.image_gallery_multiple .image:eq(0)')
5026                    .each(function() {
5027                        var hero_slide = $(this).hasClass('image_hero_placeholder');
5028                        if (hero_slide) {
5029                            $('.artwork_hero_image_container').addClass('active');
5030                        }
5031                    })
5032                ;
5033
5034                $('.image_gallery_multiple_thumbnails a')
5035                	.unbind()
5036                    .click(function() {
5037                    	$('.artwork_detail').removeClass('zoom-active');
5038                        if ($('body').hasClass('page-popup-active')) {
5039                            var container_scroll_top = $('#popup_content').scrollTop();
5040                            var scroll_context = $('#popup_content');
5041                        } else {
5042                            var container_scroll_top = $(window).scrollTop();
5043                            var scroll_context = $('html,body');
5044                        }
5045                        if (container_scroll_top > $('.image_gallery_multiple').offset().top - scroll_context.offset().top + 20) {
5046                            scroll_context.animate({'scrollTop': 0}, 600, 'easeInOutExpo');
5047                        }
5048                        $('.image_gallery_multiple').cycle(parseInt($(this).attr('data-index')));
5049                        return false;
5050                    })
5051                ;
5052        
5053
5054                if (window.site.device.handheld()) {
5055                    prevous_drag_percentage = 0;
5056                    var x;
5057
5058                    var freezeVp = function(e) {
5059                        e.preventDefault();
5060                    };
5061                    function stopBodyScrolling (bool) {
5062                        if (bool === true) {
5063                            document.body.addEventListener("touchmove", function(e) {
5064                                e.preventDefault();
5065                            }, {passive: false});
5066                        } else {
5067                            document.body.removeEventListener("touchmove", function(e) {
5068                                e.preventDefault();
5069                            }, {passive: false});
5070                        }
5071                    }
5072
5073                    $('.artwork_detail')
5074                        .on('touchstart', function(e) {
5075                            x = e.originalEvent.targetTouches[0].pageX // anchor point
5076                        })
5077                        .on('touchmove', function(e) {
5078                            $('.artwork_detail').addClass('dragging');
5079                            var change = e.originalEvent.targetTouches[0].pageX - x;
5080                            var percentage = 100 * change / window.innerWidth;
5081                            var drag_element = $('.artwork_detail .draginner');
5082                            if (change < -10 || change > 10) {
5083                                var condition_context = $('.artwork_detail').closest('#popup_content').length ? '#popup_content' : '#container_outer';
5084                                var condition = !$(condition_context).hasClass('scrolling');
5085                                if (condition) {
5086                                    // not yet working ios: stopBodyScrolling(true);
5087                                    $('body').addClass('content-swipe');
5088                                    drag_element.css({'transform': 'translate3d(' + percentage + '%, 0, 0)'});
5089                                    $('.artwork_detail .draginner').attr('data-left', percentage);
5090                                    prevous_drag_percentage = percentage;
5091                                } else {
5092
5093                                }
5094                            }
5095                        })
5096                        .on('touchend', function(e) {
5097                            // not yet working ios: stopBodyScrolling(false);
5098                            $('.artwork_detail').removeClass('dragging');
5099                            var percentage = $('.artwork_detail .draginner').attr('data-left');
5100                            var drag_element = $('.artwork_detail .draginner');
5101                            $('.artwork_detail').removeClass('dragging');
5102                            window.setTimeout(function() {
5103                                $('body').removeClass('content-swipe');
5104                            }, 200);
5105                            if (percentage > 30) {
5106                                // Previous
5107                                if ($('body').hasClass('page-popup-active')) {
5108                                    var link = $('#popup_box > .inner > .pagination_controls .previous').not('.disabled');
5109                                } else {
5110                                    var link = $('.artwork_detail .pagination_controls .previous a').not('.disabled');
5111                                }
5112                                if (link.length) {
5113                                    drag_element.css({'transform': 'translate3d(201%, 0, 0)'});
5114                                    link.trigger('click');
5115                                } else {
5116                                    prevous_drag_percentage = 0;
5117                                    drag_element.css({'transform': 'translate3d(0, 0, 0)'});
5118                                    $('.artwork_detail .draginner').attr('data-left', '0');
5119                                }
5120                            } else if (percentage < -30) {
5121                                // Next
5122                                if ($('body').hasClass('page-popup-active')) {
5123                                    var link = $('#popup_box > .inner > .pagination_controls .next').not('.disabled');
5124                                } else {
5125                                    var link = $('.artwork_detail .pagination_controls .next a').not('.disabled');
5126                                }
5127                                if (link.length) {
5128                                    drag_element.css({'transform': 'translate3d(-201%, 0, 0)'});
5129                                    link.trigger('click');
5130                                } else {
5131                                    prevous_drag_percentage = 0;
5132                                    drag_element.css({'transform': 'translate3d(0, 0, 0)'});
5133                                    $('.artwork_detail .draginner').attr('data-left', '0');
5134                                }
5135                            } else {
5136                                prevous_drag_percentage = 0;
5137                                drag_element.css({'transform': 'translate3d(0, 0, 0)'});
5138                                $('.artwork_detail .draginner').attr('data-left', '0');
5139                            }
5140                        })
5141                    ;
5142                }
5143            },
5144
5145            resize: function() {
5146                $('.artwork_detail .artwork_detail_main').each(function() {
5147                    // var min_height = $(window).width() * 0.62;
5148                    
5149                    var min_height = $(window).height();
5150                    
5151                    if (min_height < 850) {
5152                        var min_height = 850;
5153                    }
5154                    if (min_height > $(window).height()) {
5155                        var min_height = $(window).height();
5156                    }
5157                    if (min_height < 500) {
5158                        var min_height = 500;
5159                    }
5160                    $(this).css('min-height', min_height);
5161                    $('.artwork_hero_image_container').css('height', min_height);
5162
5163                    $(this).find('.image_container').css('min-height', min_height);
5164
5165                    var pagination_controls_height = $(this).height();
5166                    if (pagination_controls_height > $(window).height()) {
5167                        var pagination_controls_height = $(window).height();
5168                    } else if (pagination_controls_height < min_height) {
5169                        var pagination_controls_height = min_height;
5170                    }
5171                    $('#popup_box .pagination_controls > div, .artwork_detail .pagination_controls > div').css('height', pagination_controls_height - 170);
5172
5173                });
5174            }
5175
5176        },
5177        pageload_load_more_pagination: {
5178            
5179            // Dynamically loads in new items into a records_list, rather than traditional pagination
5180
5181            init: function() {
5182                
5183                var verbose_mode = false;
5184
5185                if ($('.page_stats').length && $('.ajax_load_more_pagination_enabled').length) {
5186       
5187                    window.site.pageload_load_more_pagination.setup(verbose_mode);
5188                }
5189            },
5190            
5191            setup: function (verbose_mode) {
5192
5193                $('.page_stats').each(function(i, element) {
5194                    // console.log('page_stats');
5195                    var $this = $(this),
5196                        incoming_url = $this.find('.ps_next').attr('href');
5197                        page_stats_id = $this.attr('id'),
5198                        corresponding_list_ref = $this.attr('id');
5199                        var $list = $('[data-pagestats-id="'+corresponding_list_ref+'"]');
5200                        ajax_load_more_auto = $this.hasClass('pagination_type_ajax_load_more_auto');
5201 
5202                        // console.log($list);
5203                        // console.log(page_stats_id);
5204                        if (!$list.length && verbose_mode){
5205                            console.log("Can't find a corresponding list that relates to your pagination. Supply 'data-
5205pagestats-id' to list that matches your page_stats_id.")
5206                        }
5207                        
5208 
5209                    if (typeof page_stats_id !== 'undefined' && $list){
5210  
5211                        // Hide the original pagination 
5212                        $this.addClass('hidden'); 
5213                        
5214                        if (typeof incoming_url !== 'undefined'){
5215                            
5216                            // Create our new dynamic button
5217                            $this.after('<div class="list-ajax-load-more-wrapper ' + (ajax_load_more_auto ? 'list-ajax-load-more-auto': '') + ' clearwithin"><button class="btn list-ajax-load-more" data-list="'+page_stats_id+'" data-url="'+incoming_url+'" aria-label="Load more items"><span class="list-ajax-load-more-label"><span><span>Load more</span></span></span></button></div>');
5218                            
5219                            $this.next('.list-ajax-load-more-wrapper').find('.list-ajax-load-more')
5220                                .bind("click", function(e) {
5221                                    e.preventDefault();
5222                                    var $button = $(this),
5223                                        incoming_url = $button.attr('data-url'); // URL detected at this level, later may be data-attr or any value
5224                                    //Load the new records
5225                                    window.site.pageload_load_more_pagination.load_content($button, incoming_url, $list, verbose_mode);
5226                                })
5227                            ;
5228                            /////window.galleries.layout.inview.init('.list-ajax-load-more-auto');
5229                            $this.next('.list-ajax-load-more-wrapper')
5230                                .on('inview.visible', function() {
5231                                    //console.log($('.list-ajax-load-more', this));
5232                                    if (!$('.list-ajax-load-more', this).hasClass('loading')) {
5233                                        $('.list-ajax-load-more', this).trigger('click');
5234                                    }
5235                                })
5236                            ;
5237                        }
5238                        
5239                        // If this URL already has a skip value, prepend a load previous button
5240                        if (window.location.search && typeof window.location.search != 'undefined') {
5241                            if (window.location.search.indexOf('skip=') != -1) {
5242                                $list.before('<div class="list-ajax-load-previous-wrapper clearwithin"><button class="list-ajax-load-previous btn" data-list="'+page_stats_id+'" aria-label="Load previous items"><span class="list-ajax-load-previous-label"><span><span>Load previous items</span></span></span></button></div>');
5243                                    
5244                                $('.list-ajax-load-previous').bind("click", function(e) { 
5245                                    e.preventDefault();
5246                                    //Load the initial records list
5247                                    $.pageload.load(window.location.pathname, true, function() {
5248                                        
5249                                    });
5250                                });
5251                            }
5252                        }
5253                    }
5254                });
5255
5256            },
5257
5258            load_content: function ($button, incoming_url, $list, verbose_mode) {
5259                
5260                $button.addClass('loading');
5261                
5262                var incoming_content_type = 'inner',
5263                    current_button_offset,
5264                    corresponding_list_ref = $list.data('pagestats-id'),
5265                    inner_content_selector = '[data-pagestats-id="'+corresponding_list_ref+'"]';
5266                    
5267                    
5268                    if ($(window).height() / ($button.offset().top - $(window).scrollTop()) < 2) {
5269                        var current_button_offset = $button.offset().top - ($(window).height() / 3);
5270                    }
5271 
5272
5273                $.pageload.load(incoming_url, true, function() {
5274                    $button.removeClass('loading');
5275                    if (new_page_inner_content) {
5276
5277                        $new_page_inner_content = $(new_page_main_content);
5278                        
5279                      
5280                        
5281                        var updated_url = $new_page_inner_content.find('.page_stats#'+corresponding_list_ref).find('.ps_next').attr('href'),
5282                            $new_list = $new_page_inner_content.find('[data-pagestats-id="'+corresponding_list_ref+'"]'),
5283                            $new_list_items = $new_list.find('.item').addClass('ajax-loaded-list-item');
5284                        
5285                        //console.log($new_list_items)
5286                        
5287                        if ($list.hasClass('tile_grid')){
5288                            $list.find('.tile_grid_original .group').append($new_list_items);
5289                        } else if ($list.hasClass('standard_grid')) {
5290                            $list.find('.group').append($new_list_items);
5291                            $new_list_items.first().find('a:not([tabindex="-1"])').focus();
5292                        } else {
5293                            $list.find('ul').append($new_list_items);
5294                        }
5295                        
5296
5297                        if (updated_url){
5298                            $button.attr('data-url', updated_url);
5299                        } else {
5300                            $button.attr('data-url', '');
5301                            $button.addClass('disabled');
5302                            $button.closest('.list-ajax-load-more-wrapper').addClass('disabled');
5303                        }
5304
5305                        //General resets
5306                        window.site.layout.grids.tile_list_append_refresh($list);
5307               
5308                        $(window).trigger('resize');
5309                        $(window).trigger('scroll');
5310                        
5311                        
5312                        if (current_button_offset && current_button_offset != 'undefined') {
5313                            setTimeout(function() {
5314                                $('html,body').stop().animate({
5315                                    scrollTop: current_button_offset
5316                                }, 800, 'easeInOutQuad', function() {
5317                                    //Refresh pageload only on the new list items
5318                                    $.pageload.refresh('.ajax-loaded-list-item:not(.pageload-refreshed)');
5319                                    $('.ajax-loaded-list-item').addClass('pageload-refreshed');
5320                                });
5321                            }, 0);
5322                        } else {
5323                                $.pageload.refresh('.ajax-loaded-list-item:not(.pageload-refreshed)');
5324                                $('.ajax-loaded-list-item').addClass('pageload-refreshed');
5325                        }
5326                        window.site.misc.extended_click_area();
5327                    }
5328                    
5329                }, null, null, null, incoming_content_type, inner_content_selector);
5330            }
5331
5332        },
5333        social_media: {
5334            
5335            init: function() {
5336
5337                $('.share_links').each(function() {
5338                    $('.link button', this)
5339                        .unbind()
5340                        .blur(function(e) {
5341                            
5342                            var next_focus_element = e.relatedTarget;
5343                            if (next_focus_element) {
5344                                var next_focus_element_class_list = next_focus_element.classList
5345                            } else {
5346                                var next_focus_element_class_list = [];
5347                            }
5348                            
5349                            if (!String(next_focus_element_class_list).includes("social_link")) {
5350                                $(this).attr("aria-expanded", "false")
5351                                var element_context = $(this).closest('.share_links');
5352                                if (element_context.hasClass('active')) {
5353                                    element_context.addClass('closing').removeClass('active');
5354                                    $(this).attr("aria-expanded", "false").focus();
5355                                    element_context.delay(400).queue(function() {
5356                                        $(this).removeClass('closing');
5357                                        $(this).dequeue();
5358                                    });
5359                                }
5360                            }
5361                        })
5362                        .click(function() {
5363                            if ($(this).closest('.share_links').hasClass('active') || $(this).closest('.share_links').hasClass('closing')) {
5364                                $(this).closest('.share_links').removeClass('active');
5365                                $(this).attr("aria-expanded", "false").focus();
5366                            } else {
5367                                $(this).closest('.share_links').addClass('active');
5368                                $(this).attr("aria-expanded", "true").focus();
5369                            }
5370                            return false;
5371                        })
5372                    ;
5373                    $('.social_links_item a', this).unbind().click(function() {
5374                        if ($(this).attr('href').indexOf('http') == 0) {
5375                            var new_window = window.open($(this).attr('href'), 'social_media_share', 'width=600,height=500');
5376                            return false;
5377                        }
5378                    });
5379                    
5380                    // Close dropdown menu if tab focus goes off dropdown menu item (first item listener)
5381                    $('.social_links_item a.first_item').on('keydown', function (e) {
5382                        var keyCode = e.which;
5383                        if ($("this:focus") && (keyCode == 9 && e.shiftKey)) {
5384                            var dropdown_name = $(this).attr("data-dropdown")
5385                            $(this).closest('.share_links').removeClass("active");
5386                            $(this).closest('.share_links').find('.link button').attr("aria-expanded", "false");
5387                        }
5388                    });
5389                    
5390                    // Close dropdown menu if tab focus goes off dropdown menu item (last item listener)
5391                    $('.social_links_item a.last_item').on('keydown', function (e) {
5392                        var keyCode = e.which;
5393                        if ($("this:focus") && (keyCode == 9 && !e.shiftKey)) {
5394                            var dropdown_name = $(this).attr("data-dropdown")
5395                            $(this).closest('.share_links').removeClass("active");
5396                            $(this).closest('.share_links').find('.link button').attr("aria-expanded", "false");
5397                        }
5398                    });
5399                });
5400
5401            }
5402
5403        },
5404
5405        enquiry: {
5406
5407            init: function() {
5408                window.site.enquiry.setup();
5409            },
5410
5411            setup: function() {
5412
5413                $('.form_row_types', '#contact_enquiry_form').each(function() {
5414                    $(this).find('li').click(function() {
5415                        $('#qcw_field_contact_variant').val($(this).attr('data-type'));
5416                        $(this).parent().find('li').removeClass('active');
5417                        $(this).addClass('active');
5418                    });
5419                    $(this).find('li:eq(0)').addClass('active');
5420                });
5421
5422                $('input, textarea', '#contact_enquiry_form')
5423                    .each(function() {
5424                        $(this).attr('default-value', $(this).parent().find('> label').text());
5425                        if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
5426                            $(this).addClass('active');
5427                        } else {
5428                            $(this).val($(this).attr('default-value'));
5429                        }
5430                    })
5431                    .change(function() {
5432                        $(this).closest('.form_row').removeClass('error');
5433                    })
5434                    .focus(function() {
5435                        $(this).closest('.form_row').removeClass('error');
5436                        if ($(this).val() == $(this).attr('default-value')) {
5437                            $(this).addClass('active');
5438                            $(this).val('');
5439                        }
5440                    })
5441                    .blur(function() {
5442                        $(this).attr('default-value', $(this).parent().find('label').text());
5443                        if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
5444                            $(this).val($(this).attr('default-value'));
5445                            $(this).removeClass('active');
5446                        }
5447                    })
5448                ;
5449
5450                $('select', '#contact_enquiry_form')
5451                    .each(function() {
5452                        $(this).attr('default-value', $(this).val());
5453                    })
5454                    .change(function() {
5455                        if ($(this).val() != '') {
5456                            $(this).addClass('active');
5457                        } else {
5458                            $(this).removeClass('active');
5459                        }
5460                    })
5461                ;
5462
5463                $('#contact_enquiry_form .button a').unbind().click(function() {
5464                    window.site.enquiry.submit_form($(this).closest('.enquiry_form').find('form'));
5465                    return false;
5466                });
5467
5468                $('#contact_enquiry_form').each(function() {
5469                    if (!$(this).hasClass('initialized')) {
5470                        if (false) {
5471                            // now done in archimedes frontend
5472                                $.ajax({
5473                                url: "/custom/get_user_data/",
5474                                cache: false,
5475                                method: 'POST',
5476                                success: function(data) {
5477                                    if (data) {
5478                                        var parsed_data = JSON.parse(data);
5479                                        $.each(parsed_data, function(k, v) {
5480                                        	if (v && v != '') {
5481    	                                        $('#contact_enquiry_form').find('input[name="' + k + '"]').val(v).addClass('active');
5482                                        	}
5483                                        });
5484                                    }
5485                                }
5486                            });
5487                        }
5488                    }
5489                    $(this).addClass('initialized');
5490                });
5491
5492            },
5493
5494            clear_form: function() {
5495                $('#ecw_field_item').val('');
5496                $('#ecw_field_message', '#contact_enquiry_form').each(function() {
5497                    $(this).val($(this).attr('default-value')).removeClass('active');
5498                });
5499                $('#ecw_field_subject', '#contact_enquiry_form').each(function() {
5500                    $(this).val('').removeClass('active');
5501                });
5502                $('#contact_enquiry_form .notify_panel_items').html('');
5503            },
5504
5505            submit_form: function(instance) {
5506
5507                if (instance) {
5508                    $('.button', instance).addClass('loading');
5509                    $('.error_row', instance).removeClass('active');
5510                    data = 'submit=1&';
5511                    $('input, select, textarea', instance).each(function() {
5512                        var field_value = $(this).val();
5513                        if ($(this).attr('type') == 'checkbox') {
5514                            if ($(this).attr('name') == 'terms') {
5515                                var field_value = $(this).is(':checked') ? '1' : '';
5516                            } else {
5517                                var field_value = $(this).is(':checked') ? 'Yes' : 'No';
5518                            }
5519                        }
5520                        if ($(this).attr('name') == 'message') {
5521                            data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />').replace('%', 'percent') + '&';
5522                        } else {
5523                            data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
5524                        }
5525                    });
5526
5527                    data = data + 'originating_page=' + encodeURIComponent(window.location.pathname + window.location.search) + '&';
5528
5529                    $.ajax({
5530                        url: "/enquiry/",
5531                        data: data,
5532                        cache: false,
5533                        method: 'POST',
5534                        dataType: 'json',
5535                        success: function(data) {
5536                            $('#contact_enquiry_form .button').removeClass('loading');
5537                            $('#contact_enquiry_form')
5538                                .delay(400)
5539                                .queue(function() {
5540                                    if (data['success'] == 1) {
5541                                        window.archimedes.archimedes_core.analytics.track_campaigns.save_form_data($('#contact_enquiry_form'));
5542
5543                                        $('#contact_enquiry_form').addClass('success');
5544                                        h.alert('<h2>Thank you</h2><div>Your Inquiry has been sent.</div>');
5545                                        if (window.ga) {
5546                                            // Track in Analytics
5547                                            analytics_params = {
5548                                              'hitType': 'event',
5549                                              'eventCategory': 'Enquiry form submit success',
5550                                              'eventAction': window.location.pathname,
5551                                              'eventLabel': $(document).attr('title')
5552                                            };
5553                                            ga('send', analytics_params);
5554                                            ga('tracker2.send', analytics_params);
5555                                        }
5556
5557                                        $('#contact_enquiry_form')
5558                                            .delay(2000)
5559                                            .queue(function() {
5560                                                $(this).dequeue();
5561                                            })
5562                                        ;
5563
5564                                    } else {
5565                                        var error_message = '';
5566                                        if (data['error_message'] && typeof data['error_message'] != 'undefined') {
5567                                            var error_message = data['error_message'];
5568                                        }
5569                                        var field_errors = [];
5570                                        if (data['field_errors'] && typeof data['field_errors'] != 'undefined') {
5571                                            var field_errors = data['field_errors'];
5572                                        }
5573                                        $.each(field_errors, function(i, v) {
5574                                            $('#contact_enquiry_form').find('[name="' + v + '"]').closest('.form_row').addClass('error');
5575                                        });
5576                                        if (error_message) {
5577                                            h.alert(error_message);
5578                                        }
5579
5580                                        if (window.ga) {
5581                                            // Track in Analytics
5582                                            analytics_params = {
5583                                              'hitType': 'event',
5584                                              'eventCategory': 'Enquiry form submit error',
5585                                              'eventAction': window.location.pathname,
5586                                              'eventLabel': $(document).attr('title')
5587                                            };
5588                                            ga('send', analytics_params);
5589                                            ga('tracker2.send', analytics_params);
5590                                        }
5591
5592                                    }
5593                                    $(this).dequeue();
5594                                })
5595                           ;
5596                        }
5597                    });
5598                }
5599
5600            },
5601
5602            after_submit: function() {
5603
5604            }
5605
5606        },
5607
5608        tracking: {
5609
5610            init: function() {
5611
5612
5613            }
5614
5615        },
5616
5617        quick_enquiry: {
5618
5619            // Quick mailing list signup form
5620
5621            init: function() {
5622                window.site.quick_enquiry.setup();
5623            },
5624
5625            setup: function() {
5626
5627
5628                $('input:not(.signup_interests_user_select_input), textarea', '.page_enquiry_widget')
5629                    .each(function() {
5630                        $(this).attr('default-value', $(this).parent().find('> label').text());
5631                        if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
5632                            $(this).addClass('active');
5633                        } else {
5634                            $(this).val($(this).attr('default-value'));
5635                        }
5636                    })
5637                    .change(function() {
5638                        $(this).closest('.form_row').removeClass('error');
5639                    })
5640                    .focus(function() {
5641                        $(this).closest('.form_row').removeClass('error');
5642                        if ($(this).val() == $(this).attr('default-value')) {
5643                            $(this).addClass('active');
5644                            $(this).val('');
5645                        }
5646                    })
5647                    .blur(function() {
5648                        $(this).attr('default-value', $(this).parent().find('label').text());
5649                        if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
5650                            $(this).val($(this).attr('default-value'));
5651                            $(this).removeClass('active');
5652                        }
5653                    })
5654	                .keypress(function(event) {
5655	                    if (event.which == 13) {
5656	                        window.site.quick_enquiry.submit_form($(this).closest('.page_enquiry_widget').find('form'));
5657	                        return false;
5658	                    }
5659	                })
5660                ;
5661                
5662                interests_to_submit = new Array();
5663                
5664                $('input.signup_interests_user_select_input', '.page_enquiry_widget')
5665                    .each(function() {
5666                        var $user_checkbox = $(this);
5667                        var $interests_input =  $user_checkbox.closest('.page_enquiry_widget').find("input[name='interests']");
5668                        var $user_checkbox_val = $user_checkbox.val();
5669                        //console.log('each');
5670                        
5671                        if ($user_checkbox.prop('checked')) {
5672                            interests_to_submit.push($user_checkbox_val);
5673                        } else {
5674                            interests_to_submit.splice( $.inArray($user_checkbox_val,interests_to_submit), 1);
5675                     
5676                        }
5677                        $interests_input.val(interests_to_submit);
5678                        
5679                    })
5680                  .change(function() {
5681                        var $user_checkbox = $(this);
5682                        var $interests_input =  $user_checkbox.closest('.page_enquiry_widget').find("input[name='interests']");
5683                        var $user_checkbox_val = $user_checkbox.val();
5684                        //console.log('change');
5685                        
5686                        if ($user_checkbox.prop('checked')) {
5687                            interests_to_submit.push($user_checkbox_val);
5688                        } else {
5689                            interests_to_submit.splice( $.inArray($user_checkbox_val,interests_to_submit), 1);
5690                        }
5691                        $interests_input.val(interests_to_submit);
5692                    })
5693                ;
5694
5695
5696                $('.page_enquiry_widget .page_enquiry_widget_submit button').unbind().click(function() {
5697                    window.site.quick_enquiry.submit_form($(this).closest('.page_enquiry_widget').find('form'));
5698                    return false;
5699                });
5700
5701                $('.page_enquiry_widget').each(function() {
5702                    if (!$(this).hasClass('initialized')) {
5703                        if (false) {
5704
5705                            $.ajax({
5706                                url: "/custom/get_user_data/",
5707                                cache: false,
5708                                method: 'POST',
5709                                success: function(data) {
5710                                    if (data) {
5711                                        var parsed_data = JSON.parse(data);
5712                                        $.each(parsed_data, function(k, v) {
5713                                        	if (v && v != '') {
5714                                            	$('.page_enquiry_widget').find('input[name="' + k + '"]').val(v).addClass('active');
5715                                            }
5716                                        });
5717                                    }
5718                                }
5719                            });
5720                        }
5721                    }
5722                    $(this).addClass('initialized');
5723                });
5724
5725            },
5726
5727            clear_form: function() {
5728                $('#pew_field_item').val('');
5729                $('#pew_field_email', '.page_enquiry_widget').each(function() {
5730                    $(this).val($(this).attr('default-value')).removeClass('active');
5731                });
5732            },
5733
5734            email_is_valid: function(email) {
5735                flag = false;
5736                if (email.indexOf('@') > -1 && email.split('@')[1].indexOf('.') > -1 && email.indexOf(' ') == -1) {
5737                    flag = true;
5738                }
5739                if (!flag) {
5740                     return false
5741                }
5742                return flag;
5743            },
5744
5745            submit_form: function(instance) {
5746
5747                if (instance) {
5748                    $('.page_enquiry_widget_submit', instance).addClass('loading');
5749                    $('.error_row', instance).removeClass('active');
5750                    data = 'submit=1&';
5751                    email_string = instance.find('input[name="email"]').val();
5752                    verify_email = window.site.quick_enquiry.email_is_valid(email_string);
5753                    
5754                    if (!verify_email) {
5755                        $('.page_enquiry_widget .page_enquiry_widget_submit').removeClass('loading');
5756                        h.alert('Please enter a valid email address.');
5757                        return false;
5758                    }
5759
5760                    $('input, select, textarea', instance).each(function() {
5761                        var field_value = $(this).val();
5762                        if (field_value != $(this).attr('default-value')) {
5763                            if ($(this).attr('type') == 'checkbox') {
5764                                if ($(this).attr('name') == 'terms') {
5765                                    var field_value = $(this).is(':checked') ? '1' : '';
5766                                } else {
5767                                    var field_value = $(this).is(':checked') ? 'Yes' : 'No';
5768                                }
5769                            }
5770                            if ($(this).attr('name') == 'message') {
5771                                data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />').replace('%', 'percent') + '&';
5772                            } else {
5773                                data = data + $(this).attr('name') + '=' + field_value.replace(/\n/g, '<br />') + '&';
5774                            }
5775                        }
5776                    });
5777
5778                    data = data + 'type=send&originating_page=' + encodeURIComponent(window.location.pathname + window.location.search) + '&contact_type=quick';
5779
5780                    $.ajax({
5781                        url: "/mailing-list/artlogicmailings/", // /enquiry/
5782                        data: data,
5783                        cache: false,
5784                        method: 'POST',
5785                        dataType: 'json',
5786                        success: function(data) {
5787                            $('.page_enquiry_widget')
5788                                .delay(400)
5789                                .queue(function() {
5790                            		$('.page_enquiry_widget .page_enquiry_widget_submit').removeClass('loading');
5791                                    if (data['success'] == 1) {
5792                                        window.archimedes.archimedes_core.analytics.track_campaigns.save_form_data($('.page_enquiry_widget'));
5793
5794                                        $('.page_enquiry_widget').addClass('success');
5795                                        h.alert('<h2>Thank you</h2><div>You have been added to our mailing list.</div>');
5796                                        if (window.ga) {
5797                                            // Track in Analytics
5798                                            analytics_params = {
5799                                              'hitType': 'event',
5800                                              'eventCategory': 'Enquiry form submit success',
5801                                              'eventAction': window.location.pathname,
5802                                              'eventLabel': $(document).attr('title')
5803                                            };
5804                                            ga('send', analytics_params);
5805                                            ga('tracker2.send', analytics_params);
5806                                        }
5807
5808                                    } else {
5809                                        var error_message = '';
5810                                        if (data['error_message'] && typeof data['error_message'] != 'undefined') {
5811                                            var error_message = data['error_message'];
5812                                        }
5813                                        var field_errors = [];
5814                                        if (data['field_errors'] && typeof data['field_errors'] != 'undefined') {
5815                                            var field_errors = data['field_errors'];
5816                                        }
5817                                        $.each(field_errors, function(i, v) {
5818                                            $('.page_enquiry_widget').find('[name="' + v + '"]').closest('.form_row').addClass('error');
5819                                        });
5820                                        if (error_message) {
5821                                            h.alert(error_message);
5822                                        }
5823
5824                                        if (window.ga) {
5825                                            // Track in Analytics
5826                                            analytics_params = {
5827                                              'hitType': 'event',
5828                                              'eventCategory': 'Enquiry form submit error',
5829                                              'eventAction': window.location.pathname,
5830                                              'eventLabel': $(document).attr('title')
5831                                            };
5832                                            ga('send', analytics_params);
5833                                            ga('tracker2.send', analytics_params);
5834                                        }
5835
5836                                    }
5837                                    $(this).dequeue();
5838                                })
5839                           ;
5840                        }
5841                    });
5842                }
5843
5844            },
5845
5846            after_submit: function() {
5847
5848            }
5849
5850        },
5851
5852        mailing_list_form: {
5853
5854            _send_url: '/mailing-list/artlogicmailings/send/',
5855            _error_messages: '',
5856
5857            init: function() {
5858                var self = this;
5859                $('.mailing_list_form')
5860                    .each(function() {
5861                        $('.field', this)
5862                            .unbind()
5863                            .each(function() {
5864                                $(this).val($(this).attr('data-default-value'));
5865                            })
5866                            .focus(function() {
5867                                if ($(this).val() == $(this).attr('data-default-value')) {
5868                                    $(this).addClass('active').val('');
5869                                }
5870                            })
5871                            .blur(function() {
5872                                if ($(this).val() == '') {
5873                                    $(this).removeClass('active').val($(this).attr('data-default-value'));
5874                                }
5875                            })
5876                        ;
5877                        $('.submit_button', this).unbind().click(function() {
5878                            $(this).closest('form').submit();
5879                            return false;
5880                        });
5881                        $('input, textarea', this).keypress(function(event) {
5882                            if (event.which == 13) {
5883                                $(this).closest('form').submit();
5884                                return false;
5885                            }
5886                        });
5887                    })
5888                    .submit(function(e){
5889                        e.preventDefault();
5890                        self._send_form($(this).closest('form'));
5891                    })
5892                ;
5893            },
5894
5895            _form_data: function(instance) {
5896
5897                var data = {}
5898                $('input, textarea', instance).each(function() {
5899                    if ($(this).val() != $(this).attr('data-default-value')) {
5900                        data[$(this).attr('name')] = $(this).val();
5901                    } else {
5902                        data[$(this).attr('name')] = '';
5903                    }
5904                });
5905                return data;
5906            },
5907
5908            _clear_form_data: function(instance) {
5909                $('input, textarea', instance).each(function() {
5910                    $(this).val($(this).attr('data-default-value'));
5911                });
5912                $('.error', instance).text('').hide();
5913            },
5914
5915            _mandatory_fields: function() {
5916
5917            },
5918
5919            _email_is_valid: function(instance) {
5920                var self = this,
5921                    flag = false,
5922                    email = self._form_data(instance)['email'];
5923
5924                if (!self._form_data(instance)['email']) {
5925                    flag = false;
5926                } else if (email.indexOf('@') > -1 && email.split('@')[1].indexOf('.') > -1 && email.indexOf(' ') == -1) {
5927                    flag = true;
5928                }
5929
5930                /* Set error message */
5931                if (!flag) {
5932                     self._set_error('Please enter a valid email address.');
5933                     return false
5934                }
5935                return flag;
5936
5937
5938            },
5939
5940            _emails_match: function(instance) {
5941
5942                // We are NOT matching the emails on this form
5943                return true;
5944
5945                var self = window.site.mailing_list_form,
5946                    flag = false;
5947
5948                self._form_data(instance)['email2'] == self._form_data(instance)['email'] ? flag = true : flag = false;
5949
5950                /* Set error message */
5951                if (!flag) {
5952                    self._set_error('Your email addresses do not match.');
5953                }
5954                return flag;
5955            },
5956
5957            _email_not_exists: function(instance) {
5958
5959                var self = window.site.mailing_list_form,
5960                    flag = false;
5961
5962                $.ajax({
5963                    url: '/mailing-list/artlogicmailings/email_exists/',
5964                    type: "POST",
5965                    dataType: 'json',
5966                    data: {'email': self._form_data(instance)['email']},
5967                    success: function(data){
5968                        flag = data['exists'] ? flag = false : flag = true;
5969                    },
5970                    error: function(jqXHR,textStatus,errorThrown){
5971                        console.log(errorThrown);
5972                    },
5973                    async: false
5974                });
5975
5976                /* Set error message */
5977                if (!flag) {
5978                    self._set_error('Your email address already exists on our mailing list.');
5979                }
5980                return flag;
5981            },
5982
5983            _set_error: function(error) {
5984                this._error_messages = error;
5985            },
5986
5987            _display_error: function(instance) {
5988                var self = this;
5989                error_messages_str = '' + self._error_messages + ''
5990                error_element = $('.error', instance);
5991                if (!error_element.length) {
5992                    // Fall back to error container outside the mailing list form
5993                    error_element = $('.error');
5994                }
5995                $(error_element).text(error_messages_str);
5996                $(error_element).fadeOut(1);
5997                $(error_element).fadeIn(200);
5998            },
5999
6000            _send_form: function(instance) {
6001
6002                var self = this;
6003
6004                if (self._email_is_valid(instance) && self._email_not_exists(instance) && self._emails_match(instance)) {
6005                    $.ajax({
6006                        url: self._send_url,
6007                        type: "POST",
6008                        dataType: 'json',
6009                        data: self._form_data(instance),
6010                        success: function(data) {
6011                            if (data.success) {
6012                                h.alert('<h2>Thank you</h2> You have been added to our mailing list.');
6013                                self._clear_form_data(instance);
6014                                // window.site.mailing_list_widget.close();
6015                            } else {
6016                                self._set_error('There was a problem adding you to the mailing list, please check the form and try again.');
6017                                self._display_error(instance);
6018                            }
6019                        }
6020                    });
6021                } else {
6022                    self._display_error(instance);
6023                }
6024            }
6025        },
6026
6027        artists: {
6028        	
6029        	init: function() {
6030                //window.site.horizontal_scroller.setup('#artists_nav_track');
6031        	}
6032
6033        },
6034
6035        exhibitions: {
6036
6037            ///FROM UNIT.. NO LONGER REQUIRED
6038            // init: function() {
6039            //     // Handle the whats-on slide-in preview pages
6040            //     $('#container a[href^="/whats-on/"]').not('a[href="/whats-on/"]').each(function() {
6041            //         if ($(this).attr('href').split('/').length == 4) {
6042            //             //$(this).addClass('pageload-link-type-ajax-enabled-content');
6043            //             $(this).unbind('click').bind('click', function() {
6044            //                 // Make sure the link is to an exhibition landing page only, do not handle other pages within the exhibition as slide-in menus
6045            //                 var element_href = $(this).attr('href') + '?type=inner';
6046            //                 var clicked_element = $(this);
6047            //                 $.pageload.load(element_href, false, function() {
6048            //                     if (new_page_inner_content) {
6049            //                         window.site.overlays.content.open(cl
6049icked_element, new_page_inner_content);
6050            //                         $.pageload.refresh('#content-overlay-content');
6051            //                         window.site.social_media.init();
6052            //                         window.site.overlays.enquire.init();
6053            //                     }
6054            //                 }, null, clicked_element);
6055            //                 return false;
6056            //             });
6057            //         }
6058            //     });
6059            // }          
6060            
6061            
6062            init: function() {
6063           
6064                window.site.layout.grids.set_item_min_height($('.content_image_1_wrapper'));
6065                $(window).resize(function() {
6066                    window.site.layout.grids.set_item_min_height($('.content_image_1_wrapper'));
6067                });
6068            }
6069
6070        },
6071
6072        store: {
6073
6074            init: function() {
6075
6076                if ($('#wishlist_enquiry_submitted_confirmation').length) {
6077                    h.alert($('#wishlist_enquiry_submitted_confirmation').html());
6078                }
6079
6080                $('#shipping_container_loader').addClass('loader');
6081                $('#stripe_loader').addClass('loader');
6082                
6083                $('input, textarea', '#sc_additional_fields, #wishlistEnquiryForm')
6084                    .each(function() {
6085                        $(this).attr('default-value', $(this).parent().find('> label').text());
6086                        if ($(this).val() != '' && $(this).val() != $(this).attr('default-value')) {
6087                            $(this).addClass('active');
6088                        } else {
6089                            $(this).val($(this).attr('default-value'));
6090                        }
6091                    })
6092                    .focus(function() {
6093                        if ($(this).val() == $(this).attr('default-value')) {
6094                            $(this).addClass('active');
6095                            $(this).val('');
6096                        }
6097                    })
6098                    .blur(function() {
6099                        $(this).attr('default-value', $(this).parent().find('label').text());
6100                        if ($(this).val() == '' || $(this).val() == $(this).attr('default-value')) {
6101                            $(this).val($(this).attr('default-value'));
6102                            $(this).removeClass('active');
6103                        }
6104                    })
6105                ;
6106            }
6107
6108        },
6109
6110        misc: {
6111
6112        	init: function(call_type) {
6113
6114                $('#logo').hover(function() {
6115                    if (typeof logo_hover_timeout != 'undefined') {
6116                        clearTimeout(logo_hover_timeout);
6117                    }
6118                    $('#logo').addClass('hover');
6119                    logo_hover_timeout = setTimeout(function () {
6120                        $('#logo').removeClass('hover');
6121                    }, 400);
6122                }, function() {
6123
6124                });
6125
6126                var call_type = (call_type && typeof call_type != 'undefined' ? call_type : 'standard');
6127
6128                $('.loader').each(function() {
6129                    if (!$(this).find('svg').length) {
6130                        $(this).append('<svg viewBox="25 25 50 50"><circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="3" stroke-miterlimit="10"/></svg>');
6131                    }
6132                });
6133
6134        		$('a').each(function() {
6135                    var el = $(this);
6136                    var href = el.attr('href');
6137                    if (href && href.indexOf('http') == 0 && !el.hasClass('noPopup')
6138                        && !el.hasClass('nopopup')
6139                        && !$('body').hasClass('no_pop_ups')
6140                        && !$('body').hasClass('nopopups')
6141                        && href.indexOf(window.location.hostname) == -1) {
6142                            el.attr('target', '_blank').addClass('external');
6143                    }
6144                });
6145
6146                if (call_type != 'popup') {
6147                    $('body').removeClass('content-type-reversed');
6148                    if ($('#container .content-reversed').length) {
6149                        $('body').addClass('content-type-reversed');
6150                    }
6151                }
6152
6153            	//window.site.misc.map();            	
6154            	window.site.misc.mulitple_maps();
6155        	},
6156
6157        	map: function() {
6158        		if ($('#map_area').length){
6159                    var latlng = $('#map_area').attr('data-latlng').split(',');
6160
6161                    if (latlng.length == 2) {
6162                        var lat = $('#map_area').attr('data-latlng').split(',')[0];
6163                        var lng = $('#map_area').attr('data-latlng').split(',')[1];
6164                        var centerlat = $('#map_area').attr('data-centerlatlng').split(',')[0];
6165                        var centerlng = $('#map_area').attr('data-centerlatlng').split(',')[1];
6166                        var map_title = $('#map_area').attr('data-title');
6167                        var map_link = $('#map_area').attr('data-url');
6168                        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"}]}];
6169                        var position = new google.maps.LatLng(lat, lng);
6170                        if (window.site.device.breakpoint() <= 2) {
6171                            var center = new google.maps.LatLng(lat, lng);
6172                            var zoomLevel = 15;
6173                        } else {
6174                            var center = new google.maps.LatLng(centerlat, centerlng);
6175                            var zoomLevel = 16;
6176                        }
6177                        var markerImage = {
6178                            url: '/images/marker_2x.png',
6179                            size: new google.maps.Size(29, 45),
6180                            scaledSize: new google.maps.Size(29, 45),
6181                            origin: new google.maps.Point(0, 0),
6182                            anchor: new google.maps.Point(15, 45)
6183                        };
6184                        var myOptions = {
6185                          zoom: zoomLevel,
6186                          center: center,
6187                          mapTypeId: google.maps.MapTypeId.ROADMAP,
6188                          panControl: false,
6189                          //panControl: true,
6190                          //panControlOptions: {
6191                          //    position: google.maps.ControlPosition.TOP_RIGHT
6192                          //},
6193                          zoomControl: false,
6194                          zoomControlOptions: {
6195                            style: google.maps.ZoomControlStyle.SMALL,
6196                            position: google.maps.ControlPosition.LEFT_TOP
6197                          },
6198                          scaleControl: false,
6199                          streetViewControl: false,
6200                          overviewMapControl: false,
6201                          scrollwheel: false,
6202                          draggable: true,
6203                          styles: new_styles,
6204                          mapTypeControl: false,
6205                          fullscreenControl: false,
6206    					  backgroundColor: '#111'
6207                        }
6208
6209                        //insert the map into the id on page using map options etc
6210                        var map = new google.maps.Map(document.getElementById("map_area"), myOptions);
6211
6212                        //each marker config
6213                        var marker = new google.maps.Marker({
6214                            position: position,
6215                            map: map,
6216                            url: map_link,
6217                            title: map_title,
6218                            icon: markerImage
6219                        });
6220
6221                        if (map_link != '') {
6222                            google.maps.event.addListener(marker, 'click', function() {
6223                                window.open(
6224                                  marker.url,
6225                                  '_blank'
6226                                );
6227                            });
6228                        }
6229                        google.maps.event.trigger(map, 'resize');
6230                    }
6231                    $( window ).load(function() {
6232                        setTimeout(function() {
6233                                $("img[src$='google_white2.png']").css({ opacity: 0.4 });
6234                                $(".gm-style-cc").css({ opacity: 0.4 });
6235                                //$("img[src$='google_white2.png']").css({ background: 'none'});
6236                                $(".gm-style-cc div, .gm-style-cc a").css({background: 'none', color: '#333'});
6237                        }, 400);
6238                    });
6239                }
6240        	},
6241        	
6242        	mulitple_maps: function() {
6243        	    
6244        	    
6245        		if ($('#map_area').length){
6246        		    
6247                    var bounds  = new google.maps.LatLngBounds();
6248                    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"}]}];
6249                    var map = new google.maps.Map(document.getElementById("map_area"), {
6250                        zoom: 18,
6251                        styles: new_styles,
6252                        center: new google.maps.LatLng(40.750681,-74.002781),
6253                        mapTypeId: google.maps.MapTypeId.ROADMAP,
6254                        disableDefaultUI: true,
6255                        backgroundColor: '#f8f8f8',
6256                        panControl: false,
6257                          //panControl: true,
6258                          //panControlOptions: {
6259                          //    position: google.maps.ControlPosition.TOP_RIGHT
6260                          //},
6261                        zoomControl: false,
6262                        zoomControlOptions: {
6263                        style: google.maps.ZoomControlStyle.SMALL,
6264                        position: google.maps.ControlPosition.LEFT_TOP
6265                        },
6266                        scaleControl: false,
6267                        streetViewControl: false,
6268                        overviewMapControl: false,
6269                        scrollwheel: false,
6270                        draggable: true,
6271                        mapTypeControl: false,
6272                        fullscreenControl: false
6273                    });
6274                    
6275                    var infoBubble = new InfoBubble({
6276                        map: map,
6277                        ShadowStyle: 0,
6278                        padding: 20, //padding in css
6279                        backgroundColor: '#fff',
6280                        borderRadius: 0,
6281                        arrowSize: 10,
6282                        borderWidth: 0,
6283                        arrowPosition: 50,
6284                        borderColor: 'transparent',
6285                        disableAutoPan: true,
6286                        disab
6286leAnimation: false,
6287                        hideCloseButton: true,
6288                        backgroundClassName: 'map-popup clearwithin',
6289                        //closeSrc: '/images/map-box-close.png'
6290                    });
6291                    
6292                    var icon_inactive = {
6293                        url: '/images/ht_square.svg',
6294                        size: new google.maps.Size(64, 64),
6295                        scaledSize: new google.maps.Size(64, 64),
6296                        origin: new google.maps.Point(0, 0),
6297                        anchor: new google.maps.Point(32, 32)
6298                    };            
6299                    
6300                    function placeMarker(icon,lat,long,html) {
6301
6302                        var latLng = new google.maps.LatLng(lat, long);
6303
6304                        var icon_active = icon_active;
6305                        var arrow_options = {
6306                            position: latLng,
6307                            icon: icon,
6308                            map:map
6309                            //title: 'I am a Draggable-Rotatable Marker!' 
6310                        };
6311                        
6312                        var marker = new google.maps.Marker(arrow_options);
6313
6314                        google.maps.event.addListener(marker, 'click', function() {
6315                            infoBubble.close();
6316                            infoBubble.setContent(html);
6317                            infoBubble.open(map, this);
6318                            currentMark = this;
6319                            // this.setIcon(icon_active);  
6320                        });
6321                        
6322                        // google.maps.event.addListener(infoBubble,'closeclick',function(){
6323                        //   currentMark.setIcon(icon);  
6324                        // });
6325
6326                        // Increase the bounds to this marker
6327                        var bounds_loc = new google.maps.LatLng(marker.position.lat(), marker.position.lng());
6328                        bounds.extend(bounds_loc);
6329                    }
6330                    
6331                    
6332                    $('.map-marker').each(function() {
6333                        var lat = $(this).attr('data-lat');
6334                        var long = $(this).attr('data-long');
6335                        var html = $(this).find('.infowindow').html();
6336                        var icon = icon_inactive;
6337                        placeMarker(icon, lat,long,html);
6338                    });
6339                
6340                    //Set mimimum zoom as the bounds function tends to zoom in as tightly as possible - zooms too much
6341                    google.maps.event.addListenerOnce(map, 'bounds_changed', function(event) {
6342                        this.setZoom(map.getZoom()-1);
6343                        if (this.getZoom() > 18) {
6344                            this.setZoom(18);
6345                        }
6346                    });
6347                    map.fitBounds(bounds);
6348                    map.panToBounds(bounds); 
6349                    
6350                    
6351                }
6352        	},
6353        	
6354        	extended_click_area: function() {
6355        	    $(".extended_click_area:not(.click_event_added)").addClass('click_event_added').click(function(){
6356                    var link_element = $(this).closest('.item, .slide, .sc_cell_item').find('a');
6357                    if (link_element.length) {
6358                        link_element[0].click();
6359                    } else {
6360                        $(this).removeClass('extended_click_area');
6361                    }
6362                });
6363        	}
6364
6365        },
6366
6367
6368        device: {
6369
6370            init: function() {
6371
6372                // Find out the current browser
6373                if ($.browser.name) {
6374                    var browserVersion = parseInt($.browser.version);
6375                    var browserName = $.browser.name;
6376                    if (browserVersion) {
6377                        $('body').addClass('browser-' + browserName);
6378                        $('body').addClass('browser-' + browserName + '-' + browserVersion);
6379                    }
6380                    if ($.browser.platform) {
6381                        $('body').addClass('platform-' + $.browser.platform);
6382                    }
6383                }
6384
6385                // Find out if this is the Android default browser and add a class to the body
6386                // 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
6387                var nua = navigator.userAgent;
6388                var is_android_default_browser = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
6389                if (is_android_default_browser) {
6390                    $('body').addClass('browser-android-internet');
6391                }
6392
6393                // Find outo if this is a high res device and add a class to the body
6394                // This allows us to change graphics to high-res versions on compatible devices
6395                if (window.devicePixelRatio > 1) {
6396                    $('body').addClass('device-highres');
6397                }
6398
6399                if (window.site.device.handheld()) {
6400                    $('body').addClass('device-handheld');
6401                } else {
6402                    $('body').addClass('device-desktop');
6403                }
6404
6405            },
6406
6407            breakpoint: function() {
6408                if ($(window).width() <= 459) {
6409                    return 1;
6410                } else if ($(window).width() <= 767) {
6411                    return 2;
6412                } else if ($(window).width() <= 900) {
6413                    return 2.5;
6414                } else if ($(window).width() <= 1023) {
6415                    return 3;
6416                } else {
6417                    return 4;
6418                }
6419            },
6420
6421            canvas_enabled: function() {
6422                // Check if canvas should be enabled
6423                if (window.location.search.indexOf("canvasdisabled=1") != -1 || !window.site.home.canvas_effect_enabled) {
6424                    return false;
6425                }
6426                return window.site.device.video_mode() && window.site.device.video_inline() && window.site.device.breakpoint() > 2;
6427            },
6428
6429            video_fallback: function() {
6430                // Does this device run in video fallback mode, e.g. usually non desktop devices
6431                return window.site.device.handheld() || !window.site.device.video_inline();
6432            },
6433
6434            video_mode: function() {
6435                // Do we want to show video on this device
6436                return !window.site.device.handheld() && window.site.device.video_inline();
6437            },
6438
6439            video_inline: function() {
6440                // Check if video content can be displayed inline (e.g. as a background physically on the page)
6441                if (window.location.search.indexOf("disablevideoinline=1") != -1) {
6442                	return false;
6443                }
6444                return navigator.userAgent.match(/(iPhone|iPod)/g) ? ('playsInline' in document.createElement('video')) : true;
6445            },
6446
6447            handheld: function() {
6448
6449                /* Detect mobile device */
6450                return (
6451                    //Uncomment to force for testing
6452                    //true ||
6453
6454                    //Dev mode
6455                    (window.location.search.indexOf("handheld=1") != -1) ||
6456                    //Detect iPhone
6457                    (navigator.platform.indexOf("iPhone") != -1) ||
6458                    //Detect iPod
6459                    (navigator.platform.indexOf("iPod") != -1) ||
6460                    //Detect iPad
6461                    (navigator.platform.indexOf("iPad") != -1) ||
6462                    //Detect Android
6463                    (navigator.userAgent.toLowerCase().indexOf("android") != -1) ||
6464                    //Detect Surface (ARM chip version e.g. low powered tablets) will also detect other windows tablets with the same chip
6465                    (navigator.userAgent.toLowerCase().indexOf("arm;") != -1 && navigator.userAgent.toLowerCase().indexOf("windows nt") != -1) ||
6466                    //Detect Opera Mini
6467                    (navigator.userAgent.toLowerCase().indexOf("opera mini") != -1) ||
6468                    //Detect Blackberry
6469                    (navigator.userAgent.toLowerCase().indexOf("blackberry") != -1) ||
6470                    //Detect webos
6471                    (navigator.userAgent.toLowerCase().indexOf("webos") != -1) ||
6472                    //Detect iemobile (old version of windows phone)
6473                    (navigator.userAgent.toLowerCase().indexOf("iemobile") != -1)
6474                );
6475
6476            },
6477
6478            handheld_not_ios: function() {
6479
6480                /* Detect mobile device */
6481                ios_devices = (
6482                    (navigator.platform.indexOf("iPhone") != -1) ||
6483                    //Detect iPod
6484                    (navigator.platform.indexOf("iPod") != -1) ||
6485                    //Detect iPad
6486                    (navigator.platform.indexOf("iPad") != -1)
6487                );
6488
6489                if (window.site.device.handheld() && !ios_devices) {
6490                	return true;
6491                } else {
6492                	return false;
6493                }
6494
6495            }
6496
6497        },
6498
6499        throttle: function(delay, callback) {
6500            var previousCall = new Date().getTime();
6501            return function() {
6502                var time = new Date().getTime();
6503                if ((time - previousCall) >= delay) {
6504                    previousCall = time;
6505                    callback.apply(null, arguments);
6506                }
6507            };
6508        },
6509
6510        debounce: function(wait, func, immediate) {
6511            var timeout;
6512            return function() {
6513                var context = this, args = arguments;
6514                var later = function() {
6515                    timeout = null;
6516                    if (!immediate) func.apply(context, args);
6517                };
6518                var callNow = immediate && !timeout;
6519                clearTimeout(timeout);
6520                timeout = setTimeout(later, wait);
6521                if (callNow) func.apply(context, args);
6522            };
6523        },
6524        
6525        objectfit_polyfill: {
6526            /*
6527                Simple polyfill for image grids that use object-fit css for 'soft' cropping.
6528                Mostly required for all versions of Internet Explorer and older versions of Edge.
6529            */
6530            init: function() {
6531                
6532                var polyfill_images = '.hero_inner .media_wrapper .image img, .artwork-nav-hero img';
6533                
6534                if ($(polyfill_images).length){
6535                    
6536                    var supportsObjectfit;
6537                    
6538                    // Detect whether '@supports' CSS is supported, preventing errors in IE
6539                    var supports_supportsCSS = !!((window.CSS && window.CSS.supports) || window.supportsCSS || false);
6540
6541                    if (supports_supportsCSS){
6542                        // Older Edge supports '@supports' but not object-fit
6543                        supportsObjectfit = CSS.supports('object-fit','cover');
6544                    } else {
6545                        //IE doesn't support '@supports' or 'object-fit', so we can consider them the same
6546                        supportsObjectfit = false;
6547                    }
6548
6549                    if (!supportsObjectfit || typeof supportsObjectfit == 'undefined') {
6550    
6551                        $(polyfill_images).each(function() {
6552                            var $img = $(this);
6553                            var imageURL = false;
6554                            if ($img.attr('src') && typeof $img.attr('src') != 'undefined') {
6555                                var imageURL = $img.attr('src');
6556                            } else if ($img.attr('data-src') && typeof $img.attr('data-src') != 'undefined') {
6557                                var imageURL = $img.attr('data-src');
6558                            }
6559                            if (imageURL) {
6560                                var bg_positioning = '50% 50%';
6561                                if ($img.css('object-position')) {
6562                                    var positioning = $img.css('object-position');
6563                                }
6564                                $img.parent().addClass('objectfit-fallback-bg').css({'background-image':'url('+imageURL+')','background-position':bg_positioning});
6565                                $img.css('visibility','hidden');
6566                                
6567                                if (!$('body').hasClass('objectfit-polyfill-active')){
6568                                    $('body').addClass('objectfit-polyfill-active')
6569                                }
6570                            }
6571                        });
6572                    }
6573                }
6574            },
6575        },
6576
6577
6578        submit_art: {
6579
6580            init: function() {
6581                ///console.log('submit_art --------------------');
6582
6583                $('#art_submission_form button').click(function() {
6584                    $(this).closest('form').submit();
6585                    return false;
6586                });
6587
6588                $('#art_submission_form').each(function() {
6589
6590                       
6591                        $(this).find('.image-label input').each(function() {
6592                            var $this_input = $(this);
6593                            var $thislabel = $this_input.closest('.image-label');
6594                            
6595                            $thislabel.off().keydown(function(e){
6596                                if (e.keyCode === 13 || e.keyCode === 32) {
6597                                    e.preventDefault();
6598                                    $(this).trigger("click");
6599                                }
6600                            });
6601                            
6602                            $this_input.change(function() {
6603                                
6604                                var input_name = $this_input.attr("name")
6605                                //console.log('change');
6606                                var $preview = $('.' + input_name + ' img');
6607                                //console.log($preview);
6608                                var file    = $this_input[0].files[0];
6609                                //console.log(file);
6610                                var reader  = new FileReader();
6611                                
6612                                reader.onloadend = function () {
6613                                    $preview.attr('src', reader.result);
6614                                    //console.log(reader.result);
6615                                }
6616                                
6617                                if (file) {
6618                                    reader.readAsDataURL(file);
6619                                } else {
6620                                    $preview.src = "";
6621                                }
6622                                
6623                                $thislabel.addClass('active');
6624                                $thislabel.find('.label-text').html('- Remove');
6625                                $thislabel.parent().next('.upload-image-container').find('label.hidden').removeClass('hidden');
6626                                
6627                                $thislabel.one( "click", function(e) {
6628                                    e.preventDefault();
6629                                    $thislabel.removeClass('active');
6630                                    $thislabel.find('.label-text').html('+ Upload an image');
6631                                    $this_input.val('');
6632                                    $preview.attr('src', $preview.attr('data-placeholder-src'));
6633                                });
6634
6635
6636                            });
6637                            
6638                        });
6639                        
6640                    // if ($(this).hasClass('form_error')) {
6641                    //     if ($(this).attr('data-error-type') == 'captcha-response-not-found') {
6642                    //         h.alert('<h2>Sorry</h2>The form could not be verified correctly. Please try refreshing the page and starting again. If you continue to have problems please contact us at <a href="mailto:[email protected]">[email protected]</a>');
6643                    //     } else {
6644                    //         h.alert('<h2>Sorry</h2>Please ensure you have filled in all the required fields and completed the verification field.');
6645                    //     }
6646                    // }
6647
6648                    $(this).submit(function() {
6649                        if ($('#f_first_name').val() == '') {
6650                           h.alert('<h2>Sorry</h2>Please enter your first name.');
6651                           return false;
6652                        } else if ($('#f_last_name').val() == '') {
6653                           h.alert('<h2>Sorry</h2>Please enter your last name.');
6654                           return false;
6655                        } else if ($('#f_email').val() == '') {
6656                           h.alert('<h2>Sorry</h2>Please enter your email address.');
6657                           return false;
6658                        } else if (!window.site.submit_art.checkEmail('#f_email')) {
6659                           h.alert('<h2>Sorry</h2>Please enter a valid email address.');
6660                           return false;
6661                        // } else if ($('#f_phone').val() == '') {
6662                        //   h.alert('<h2>Sorry</h2>Please enter your phone number.');
6663                        //   return false;
6664                        } else if ($('#f_artist').val() == '') {
6665                           h.alert('<h2>Sorry</h2>Please enter an artist.');
6666                           return false;
6667                        } else if ($('#f_title').val() == '') {
6668                           h.alert('<h2>Sorry</h2>Please enter a title.');
6669                           return false;                        
6670                        } else if ($('#g-recaptcha-response').val() == '') {
6671                           h.alert("<h2>Sorry</h2>Please select the checkbox marked 'I'm not a robot'.");
6672                           return false;
6673                           
6674                           
6675                        } else if ($('#f_image1').val() == '' && $('#f_image2').val() == '' && $('#f_image3').val() == '') {
6676                           h.alert('<h2>Sorry</h2>Please upload an image.');
6677                           return false;
6678                           
6679                           
6680                        } else {
6681                            $('#art_submission_form button').addClass('loading');
6682                            return true;
6683                        }
6684                    });
6685
6686                });
6687
6688            },
6689
6690            checkEmail: function(email_address) {
6691
6692    
6693                if ($(email_address).val() != "") {
6694                    var str=$(email_address).val();
6695                    var at="@";
6696                    var dot=".";
6697                    var lat=str.indexOf(at);
6698                    var lstr=str.length;
6699                    var ldot=str.indexOf(dot);
6700
6701                    if (str.indexOf(at)==-1){
6702                       return false;
6703                    }
6704
6705                    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
6706                       return false;
6707                    }
6708
6709                    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
6710                        return false;
6711                    }
6712
6713                    if (str.indexOf(at,(lat+1))!=-1){
6714                        return false;
6715                    }
6716
6717                    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
6718                        return false;
6719                    }
6720
6721                    if (str.indexOf(dot,(lat+2))==-1){
6722                        return false;
6723                    }
6724
6725                    if (str.indexOf(" ")!=-1){
6726                        return false;
6727                    }
6728
6729                    return true;
6730                }
6731
6732                else {
6733                    return false;
6734                }
6735
6736            },
6737
6738            image_upload_begin: function(element) {
6739                //console.log('image_upload_callback');
6740                if (element) {
6741                    $(element).each(function() {
6742                        $('.image_field', this).val('');
6743                        $('.image_preview', this).removeClass('active').addClass('loading').find('div').html('');
6744                    });
6745                }
6746            },
6747
6748            image_upload_callback: function(filepath, element) {
6749                //console.log('image_upload_callback');
6750                if (element && filepath) {
6751                    $(element).each(function() {
6752                        $('.form_row_image', this).addClass('image_uploaded');
6753                        $('.image_preview', this).removeClass('loading').addClass('active').find('div').html('<img src="/custom_images/600x400' + filepath + '" />');
6754                        $('.image_field', this).val(filepath);
6755                    });
6756                }
6757            },
6758
6759            entry_form_template: function() {
6760                return $.parseHTML('<div class="item">\
6761                    <input type="hidden" name="order" value="" />\
6762                    <div class="delete">Delete</div>\
6763                    <h4>Entry <span></span></h4>\
6764                    <div class="form_row form_row_image">\
6765                        <label>Image</label>\
6766                        <div class="image_preview"><div></div></div>\
6767                        <input type="hidden" name="image" class="image_field" />\
6768                        <div class="iframe_container"><div class="inputField"><iframe src="/ajax/user_upload_image/#ce_item"></iframe></div></div>\
6769                    </div>\
6770                    <div class="form_row form_row_caption form_row_title">\
6771                        <label>Title</label>\
6772                        <input name="title" type="text" class="inputField" />\
6773                    </div>\
6774                    <div class="form_row form_row_caption">\
6775                        <label>Medium</label>\
6776                        <input name="medium" type="text" class="inputField" />\
6777                    </div>\
6778                    <div class="form_row form_row_caption">\
6779                        <label>Size (cm)</label>\
6780                        <input name="dimensions" type="text" class="inputField" />\
6781                    </div>\
6782                    <div class="form_row form_row_caption">\
6783                        <label>Price (&pound;) - minimum &pound;250</label>\
6784                        <input name="price" type="text" class="inputField" />\
6785                    </div>\
6786                </div>');
6787            }
6788
6789        },
6790
6791        filters: {
6792
6793            init: function() {
6794
6795                $('.filter_toolbar')
6796                    .each(function() {
6797                        var filter_panel_id = $(this).attr('data-filter-panel-id');
6798                        var filter_panel_context = $(this).attr('data-filter-results-context');
6799                        var filters_results_url = $(this).attr('data-filter-results-url');
6800                        if (filter_panel_id && typeof filter_panel_id != 'undefined') {
6801                            var filter_panel = $('#' + filter_panel_id);
6802                            if (filter_panel.length) {
6803                                filter_panel.attr('data-filter-results-context', filter_panel_context);
6804                                filter_panel.attr('data-filter-results-url', filters_results_url);
6805                            }
6806                        }
6807                        // Button to show the filters popup
6808                        $(this).find('.filters_button')
6809                            .click(function() {
6810                                var filter_panel_id = $(this).closest('.filter_toolbar').attr('data-filter-panel-id');
6811                                if (filter_panel_id && typeof filter_panel_id != 'undefined') {
6812                                    if ($('#' + filter_panel_id).hasClass('active')) {
6813                                        window.site.filters.close(filter_panel_id);
6814                                    } else {
6815                                        window.site.filters.filters_panel_init(filter_panel_id);
6816                                    }
6817                                }
6818                            })
6819                        ;
6820                        // Free text search
6821                        $(this).find('.filters_search input')
6822                            .each(function() {
6823                                $(this).attr('data-default-value', $(this).val());
6824                                $(this).keypress(function(event) {
6825                                    var filter_panel_id = $(this).closest('.filter_toolbar').attr('data-filter-panel-id');
6826                                    var this_value = $(this).val();
6827                                    if (event.which == 13 && this_value != $(this).attr('data-default-value')) {
6828                                        // Clear filters panel, text and filters should be exclusive
6829                                        var filter_panel = $('#' + filter_panel_id);
6830                                        filter_panel.find('li').removeClass('active');
6831                                        // Submit search
6832                                        window.site.filters.filters_panel_init(filter_panel_id, false, true, true, true);
6833                                        return false;
6834                                    }
6835                                    $(this).addClass('typed');
6836                                });
6837                                $(this).closest('.filters_search').find('.filters_search_submit').unbind('click').bind('click', function() {
6838                                    var filter_panel_id = $(this).closest('.filter_toolbar').attr('data-filter-panel-id');
6839                                    var this_value = $(this).val();
6840                                    if (this_value != $(this).attr('data-default-value')) {
6841                                        // Clear filters panel, text and filters should be exclusive
6842                                        var filter_panel = $('#' + filter_panel_id);
6843                                        filter_panel.find('li').removeClass('active');
6844                                        // Submit search
6845                                        window.site.filters.filters_panel_init(filter_panel_id, false, true, true, true);
6846                                    }
6847                                    return false;
6848                                });
6849                            })
6850                            .focus(function() {
6851                                if ($(this).val() == $(this).attr('data-default-value')) {
6852                                    $(this).addClass('active').val('');
6853                                }
6854                            })
6855                            .blur(function() {
6856                                if ($(this).val() == '') {
6857                                    $(this).removeClass('active').val($(this).attr('data-default-value'));
6858                                }
6859                            })
6860                        ;
6861                    })
6862                ;
6863                window.site.filters.setup();
6864            },
6865
6866            close: function(filter_panel_id) {
6867                $('#' + filter_panel_id).removeClass('active');
6868            },
6869
6870            setup: function()  {
6871
6872                $('.filter_toolbar')
6873                    .each(function() {
6874                        var filter_panel_id = $(this).attr('data-filter-panel-id');
6875                        if (filter_panel_id && typeof filter_panel_id != 'undefined') {
6876                            var filter_panel = $('#' + filter_panel_id);
6877                            var filter_panel_context = $(this).attr('data-filter-results-context');
6878                            var filter_type = filter_panel.attr('data-filter-type');
6879
6880                            var load_filters = $('input[name="filter_data"]').length > 0 || window.location.search.indexOf('?filter=1') > '-1';
6881                            user_selected = false;
6882
6883                            if (filter_panel) {
6884                                // Get current user filters data for this panel if it exists in localstorage
6885                                var filter_data = {'filters_count': 0, 'record_ids': [], 'filters_active': false, 'filters': {}};
6886                                var filter_data_defaults = filter_data;
6887                                if (localStorage) {
6888                                    // If filter data exists on the page, set it in storage
6889                                    var filter_data_new = $('.filter_results').find('[name="filter_data"]').val();
6890                                    if ($('.filter_results').find('[name="filter_data"]').length) {
6891                                        localStorage.setItem('filters', filter_data_new);
6892                                    }
6893                                    // If there is no filter data, clear out any old data so it is not 'remembered'
6894                                    if (!filter_data_new || typeof filter_data_new == 'undefined') {
6895                                        localStorage.setItem('filters', JSON.stringify(filter_data_defaults));
6896                                    }
6897                                    // Get filter data from storage if it exists
6898                                    var filters_user_data_storage = localStorage.getItem('filters');
6899                                    if (filters_user_data_storage && typeof filters_user_data_storage != 'undefined') {
6900                                        var data = JSON.parse(filters_user_data_storage);
6901                                        if (data[filter_type]) {
6902                                            var filter_data = data[filter_type];
6903
6904                                            // Load filters only if the filter data is user selected - e.g. if the user intentionally filtered the data originally
6905                                            var user_selected = filter_data.user_selected;
6906                                            if (user_selected) {
6907                                                var load_filters = true;
6908                                            }
6909                                        }
6910                                    }
6911                                }
6912
6913                                // Setup filters panel
6914                                if (load_filters) {
6915                                    var filter_panel_filters_enabled = filter_data.filters_active;
6916                                    if (filter_panel_filters_enabled) {
6917                                        var filter_panel_filters_count = filter_data.filters_count && typeof filter_data.filters_count != 'undefined' ? filter_data.filters_count : 0;
6918
6919                                        // Mark active filters
6920                                        $.each(filter_data.filters, function(k, v) {
6921                                            var filter_items_container = filter_panel.find('ul[data-value="' + k + '"]');
6922                                            if (filter_items_container.length) {
6923                                                filter_items_container.find('li').removeClass('active');
6924                                                $.each(v, function(index, selected_item_value) {
6925                                                    filter_items_container.find('li[data-value="' + selected_item_value + '"]').addClass('active');
6926                                                });
6927                                            }
6928                                            if (k == 's' && v != '') {
6929                                                $(filter_panel_context).find('.filters_search input').each(function() {
6930                                                    $(this).val(v).addClass('active');
6931                                                });
6932                                            }
6933                                        });
6934                                        if (!filter_panel.hasClass('initialized') && window.location.search == '') {
6935                                            window.site.filters.filters_panel_init(filter_panel_id, false, true, user_selected);
6936                                        }
6937                                    }
6938                                }
6939
6940                                // Clear filters button setup
6941
6942                                $(this).find('.filters_clear_button').unbind('click').bind('click', function() {
6943                                    var filter_panel_id = $(this).parent().attr('data-filter-panel-id');
6944                                    var filter_panel = $('#' + filter_panel_id);
6945                                    filter_panel.find('li').removeClass('active');
6946                                    $(filter_panel_context).find('.filters_search input').each(function() {
6947                                        $(this).val($(this).attr('data-default-value')).removeClass('active');
6948                                    });
6949                                    window.site.filters.filters_panel_init(filter_panel_id, true);
6950                                });
6951
6952                                if (!$(this).attr('data-default-label') || typeof $(this).attr('data-default-label') == 'undefined') {
6953                                    $(this).attr('data-default-label', $('span', this).html().trim());
6954                                }
6955                                $('.filter_heading', filter_panel_context).each(function() {
6956                                    var heading_context = ($('a', this).length ? $('a', this) : $(this));
6957                                    if (!$(this).attr('data-default-heading') || typeof $(this).attr('data-default-heading') == 'undefined') {
6958                                        $(this).attr('data-default-heading', heading_context.html().trim());
6959                                    }
6960                                });
6961
6962                                if (filter_panel_filters_enabled == '1') {
6963                                    $(filter_panel_context).addClass('filters_active');
6964                                    // Change heading label
6965                                    if (window.location.search == '') {
6966                                        $('.filter_heading', filter_panel_context).each(function() {
6967                                            var heading_context = ($('a', this).length ? $('a', this) : $(this));
6968                                            $(this).text('Results');
6969                                        });
6970                                    }
6971
6972                                    // Change button label
6973                                    if (filter_panel_filters_count > 0) {
6974                                        $('span', this).html('Filters selected <em class="qty">' + filter_panel_filters_count + '</em>');
6975                                    }
6976                                } else {
6977                                    $(filter_panel_context).removeClass('filters_active');
6978                                    $('.filter_heading', filter_panel_context).each(function() {
6979                                        var heading_context = ($('a', this).length ? $('a', this) : $(this));
6980                                        $(this).html($(this).attr('data-default-heading'));
6981                                    });
6982                                    $('span', this).html($(this).attr('data-default-label'));
6983                                }
6984
6985                                filter_panel.addClass('initialized');
6986                            }
6987                        }
6988                        $(this).addClass('initialized');
6989                    })
6990                ;
6991
6992            },
6993
6994            filters_panel_init: function(filter_panel_id, clear_filters, instant_load_results, user_selected, text_field_submitted) {
6995
6996                clear_filters = (clear_filters && typeof clear_filters != 'undefined' ? true : false);
6997                instant_load_results = (instant_load_results && typeof instant_load_results != 'undefined' ? true : false);
6998
6999                filter_panel_original = $('#' + filter_panel_id);
7000
7001                filter_panel_original.removeClass('filters-user-select');
7002
7003                filter_panel_original.each(function() {
7004                    $(this).addClass('active');
7005                    $('.filters_list', this)
7006                        .each(function() {
7007                            $('li a', this).each(function() {
7008                                $(this).addClass('link-no-ajax');
7009                                $(this).unbind('click').bind('click', function() {
7010                                    var fieldtype = $(this).closest('ul').attr('data-fieldtype') == 'unique' ? 'unique' : 'multi';
7011                                    if ($(this).closest('li').hasClass('active')) {
7012                                        $(this).closest('li').removeClass('active');
7013                                        filter_panel_original.find('ul[data-value="' + $(this).closest('ul').attr('data-value') + '"]').find('li[data-value="' + $(this).attr('data-value') + '"]').removeClass('active');
7014                                    } else {
7015                                        if (fieldtype == 'unique') {
7016                                            $(this).closest('ul').find('li').removeClass('active');
7017                                        }
7018                                        $(this).closest('li').addClass('active');
7019                                        filter_panel_original.find('ul[data-value="' + $(this).closest('ul').attr('data-value') + '"]').find('li[data-value="' + $(this).attr('data-value') + '"]').addClass('active');
7020                                    }
7021
7022                                    // Instantly submit the search
7023                                    $(this).closest('.filters_panel').find('.filters_submit').trigger('click');
7024
7025                                    return false;
7026                                });
7027                            });
7028                        });
7029                        $(this).closest('.filters_panel').find('.filters_submit').unbind('click').bind('click', function() {
7030                            window.site.filters.submit_filters(filter_panel_id);
7031                        });
7032                    })
7033                    .promise()
7034                    .done(function() {
7035                        if (clear_filters || instant_load_results) {
7036                            if (instant_load_results && !text_field_submitted) {
7037                                var filter_panel_context = $(this).attr('data-results-context');
7038                                $('.filter_results', filter_panel_context).html('');
7039                            }
7040                            if (user_selected) {
7041                                filter_panel_original.addClass('filters-user-select');
7042                            }
7043                            $('.filters_submit', filter_panel_original).trigger('click');
7044                        } else {
7045                            // Clear the text search - text and filter searches should be exclusive
7046                            $('.filter_toolbar .filters_search input').each(function() {
7047                                $(this).val($(this).attr('data-default-value')).removeClass('active');
7048                            });
7049                            $('body').addClass('navigation-filters-open');
7050                            filter_panel_original.addClass('filters-user-select');
7051                        }
7052                    })
7053                ;
7054            },
7055
7056            submit_filters: function(filter_panel_id) {
7057
7058                filter_panel_original = $('#' + filter_panel_id);
7059                filters_user_selected = filter_panel_original.hasClass('filters-user-select');
7060                filter_type = filter_panel_original.attr('data-filter-type');
7061                filter_text_active = $('.filter_toolbar .filters_search input').hasClass('typed');
7062                $('#' + filter_panel_id)
7063                    .each(function() {
7064                        filter_panel_context = $(this).attr('data-results-context');
7065                        filters_results_url = $(this).attr('data-filter-results-url');
7066                        filter_text_search_field = $(filter_panel_context).find('.filters_search input');
7067                        url_params = '';
7068                        href = '';
7069                        params_dict = {};
7070                        filter_count = 0;
7071                        filters_active = false;
7072                        $('.filters_list', this)
7073                            .each(function() {
7074                                var this_context = $(this).attr('data-value');
7075                                params_dict[this_context] = Array();
7076                                $('li.active', this).each(function() {
7077                                    params_dict[this_context].push($(this).attr('data-value'));
7078                                    filter_count = filter_count + 1;
7079                                    filters_active = true;
7080                                });
7081                            })
7082                        ;
7083                        $.each(params_dict, function(k, v) {
7084                            if (v.length) {
7085                                url_params = url_params + '&f_' + k + '=' + v.join();
7086                            }
7087                        });
7088
7089                        var text_search_value = (filter_text_search_field && typeof filter_text_search_field != 'undefined' && filter_text_search_field.val() != filter_text_search_field.attr('data-default-value') ? '&s=' + filter_text_search_field.val() : '');
7090                        var user_select_param = (filters_user_selected ? '&user_selected=1' : '');
7091                        var clear_filters_param = (url_params == '' && text_search_value == '' ? '&clear_filters=1' : '');
7092
7093                        href = filters_results_url + '?filter=1' + user_select_param + clear_filters_param + text_search_value + url_params;
7094                        filter_panel_original.attr('data-filters-count', filter_count);
7095                        filter_panel_original.attr('data-filters-enabled', (filters_active ? '1' : '0'));
7096                        
7097
7098                        // Scroll to results
7099                        var offset_top = $('.filter_results', filter_panel_context).offset().top - 150;
7100                        $('html,body').animate(
7101                            {scrollTop: offset_top},
7102                            1200,
7103                            'easeInOutExpo'
7104                        );
7105                    })
7106                    .promise()
7107                    .done(function() {
7108                        var incoming_content_type = 'inner';
7109                        $.pageload.load(href, false, function(new_page_inner_content, element_href, new_page_main_content) {
7110                            if (new_page_inner_content) {
7111                                $('.filter_results', filter_panel_context)
7112                                    .addClass('filter_transition')
7113                                    .delay(400)
7114                                    .queue(function() {
7115                                        var updated_url = element_href.replace('&user_selected=1', '');
7116                                        var clear_filters = false;
7117                                        if (element_href.split('?')[1] == 'filter=1&clear_filters=1') {
7118                                            var updated_url = element_href.split('?')[0];
7119                                            var clear_filters = true;
7120                                        }
7121                                        if ($('body').hasClass('navigation-filters-open') || clear_filters || filter_text_active) {
7122                                            history.replaceState({'ajaxPageLoad': true}, null, updated_url);
7123                                        }
7124
7125                                        $('.filter_results', filter_panel_context).html(new_page_inner_content);
7126                                        $('.filter_results', filter_panel_context).removeClass('filter_transition');
7127
7128                                        window.cart.init();
7129                                        window.site.enquiry.init();
7130                                        window.site.overlays.enquire.init();
7131                                        $.pageload.refresh();
7132                                        $(window).trigger('resize');
7133
7134                                        window.site.filters.setup();
7135
7136                                        var full_html = $(new_page_main_content);
7137                                        var filter_heading_text = full_html.find('.filter_heading').html();
7138                                        if (filter_heading_text && typeof filter_heading_text != 'undefined') {
7139                                            if (filter_heading_text != $('.filter_heading', filter_panel_context).attr('data-default-heading')) {
7140                                                $('.filter_heading', filter_panel_context).html(filter_heading_text);
7141                                            }
7142                                        }
7143
7144                                        window.site.artlogic_inview.init();
7145                                        window.site.lazy_load.setup();
7146                                        window.site.lazy_load.fire($('.image_lazy_load', filter_panel_context));
7147
7148                                        $(this).dequeue();
7149                                    })
7150                                ;
7151                            }
7152                        }, null, null, null, incoming_content_type);
7153                    })
7154                ;
7155            },
7156
7157            get_filter_data: function() {
7158                // This ajax option is not currently used, but mnight be useful in future.
7159                $.ajax({
7160                    url: "/custom/filters_get_data/",
7161                    cache: false,
7162                    method: 'POST',
7163                    success: function(data) {
7164                        if (data) {
7165                            return data;
7166                        }
7167                    }
7168                });
7169            }
7170
7171        }
7172
7173    };
7174
7175    $(document).ready(function() {
7176
7177        window.site.init();
7178        
7179        window.onload = function() {
7180            var onloadCallback = function() {
7181                grecaptcha.render('g_recap', {
7182                    'sitekey' : '6Ld8dqQUAAAAAINqesYkIEZJLUPqhMl9Vmi46D7Y'
7183                });
7184            };
7185            if ($('#g_recap').length) {
7186                onloadCallback();
7187            }
7188        };
7189    });
7190
7191
7192})(jQuery);
7193
7194
7195
7196       
7197
7198
7199(function( $ ){
7200
7201  'use strict';
7202
7203  $.fn.fitVids = function( options ) {
7204    var settings = {
7205      customSelector: null,
7206      ignore: null
7207    };
7208
7209    if(!document.getElementById('fit-vids-style')) {
7210      // appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js
7211      var head = document.head || document.getElementsByTagName('head')[0];
7212      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%;}';
7213      var div = document.createElement("div");
7214      div.innerHTML = '<p>x</p><style id="fit-vids-style">' + css + '</style>';
7215      head.appendChild(div.childNodes[1]);
7216    }
7217
7218    if ( options ) {
7219      $.extend( settings, options );
7220    }
7221
7222    return this.each(function(){
7223      var selectors = [
7224        'iframe[src*="player.vimeo.com"]',
7225        'iframe[src*="player.vimeo.com"]',
7226        'iframe[src*="youtube.com"]',
7227        'iframe[src*="youtube-nocookie.com"]',
7228        'iframe[src*="kickstarter.com"][src*="video.html"]',
7229        'iframe[src*="player.youku.com"]',
7230        'iframe[src*="mpembed.com"]',
7231        
7232        'object',
7233        'embed'
7234      ];
7235
7236      if (settings.customSelector) {
7237        selectors.push(settings.customSelector);
7238      }
7239
7240      var ignoreList = '.fitvidsignore';
7241
7242      if(settings.ignore) {
7243        ignoreList = ignoreList + ', ' + settings.ignore;
7244      }
7245
7246      var $allVideos = $(this).find(selectors.join(','));
7247      $allVideos = $allVideos.not('object object'); // SwfObj conflict patch
7248      $allVideos = $allVideos.not(ignoreList); // Disable FitVids on this video.
7249
7250      $allVideos.each(function(){
7251        var $this = $(this);
7252        if($this.parents(ignoreList).length > 0) {
7253          return; // Disable FitVids on this video.
7254        }
7255        if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; }
7256        if ((!$this.css('height') && !$this.css('width')) && (isNaN($this.attr('height')) || isNaN($this.attr('width'))))
7257        {
7258          $this.attr('height', 9);
7259          $this.attr('width', 16);
7260        }
7261        var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(),
7262            width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(),
7263            aspectRatio = height / width;
7264        if(!$this.attr('id')){
7265          var videoID = 'fitvid' + Math.floor(Math.random()*999999);
7266          $this.attr('id', videoID);
7267        }
7268        $this.wrap('<div class="fluid-width-video-wrapper"></div>').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+'%');
7269        $this.removeAttr('height').removeAttr('width');
7270      });
7271    });
7272  };
7273// Works with either jQuery or Zepto
7274})( window.jQuery || window.Zepto );
7275
7276
7277(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+'">
7277<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);
7278// set up defaults for artlogic
7279jQuery.prompt.setDefaults({
7280      prefix: 'arprompt',
7281      useiframe: true
7282});
7283
7284
7285

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.