ips.templates.set("eventLoading"," <li class='legoEvent legoEvent--withImage legoEvent--loading'>  <div class='legoPlaceholder legoPlaceholder--eventImage'></div>  <div class='legoPlaceholder legoPlaceholder--eventDate'></div>  <div class='legoPlaceholder legoPlaceholder--eventTitle'></div>  <div class='legoPlaceholder legoPlaceholder--eventBlurb'></div> </li>");ips.templates.set("nearMe"," <ul class='ipsClearfix ipsList_reset legoEventList legoNearMe__events'>  <li class='legoNearMe__map legoPlaceholder legoPlaceholder--map' id='legoMap'></li>  {{{events}}} </ul>");;
var PER_PAGE=16;;(function($,_,undefined){"use strict";ips.controller.register('events.front.overview.eventList',{initialize:function(){this.on('click','[data-action="loadMore"]',this.loadMore);this.on('click','[data-action="changeMonth"]',this.changeMonth);this.setup();},setup:function(){this._eventList=this.scope.find('[data-role="eventList"]');this._loadMore=this.scope.find('[data-action="loadMore"]');this._monthNav=this.scope.find('[data-role="monthNav"]');},loadMore:function(e){e.preventDefault();var placeholders=this.getPlaceholders();this._eventList.append(placeholders);this._loadMore.prop('disabled',true);var self=this;var current=this.getCurrentDate();var total=this.scope.find('[data-eventID]').length;var url=ips.getSetting('baseURL')+'?app=events&module=events&controller=overview&get=byMonth&m='+current.month+'&y='+current.year+'&offset='+total;ips.getAjax()(url).done(function(response){self._eventList.append(response.html);self.removePlaceholders();self.checkMoreButton(response.count);self._loadMore.prop('disabled',false);$(document).trigger('contentChange',[self.scope]);});},changeMonth:function(e){e.preventDefault();var placeholders=this.getPlaceholders(4);this._eventList.html(placeholders);this._loadMore.prop('disabled',true);this._monthNav.find('[data-action="changeMonth"]').removeClass('legoMonthNav__monthItem--active');$(e.currentTarget).addClass('legoMonthNav__monthItem--active');var self=this;var current=this.getCurrentDate();var url=ips.getSetting('baseURL')+'?app=events&module=events&controller=overview&get=byMonth&m='+current.month+'&y='+current.year+'&offset=0';ips.getAjax()(url).done(function(response){self._eventList.html(response.html);self.checkMoreButton(response.count);self._loadMore.prop('disabled',false);$(document).trigger('contentChange',[self.scope]);});},getPlaceholders:function(count){var events=[];if(_.isUndefined(count)){count=4;}
for(var i=0;i<count;i++){events.push(ips.templates.render('eventLoading'));}
return events.join('');},removePlaceholders:function(){this.scope.find('.legoEvent--loading').remove();},checkMoreButton:function(count){if(_.isNumber(count)&&count<PER_PAGE){this.scope.find('[data-action="loadMore"]').hide();this.scope.find('[data-role="noMoreResults"]').show();}else{this.scope.find('[data-action="loadMore"]').show();this.scope.find('[data-role="noMoreResults"]').hide();}},getCurrentDate:function(){var current=this.scope.find('[data-role="monthNav"] .legoMonthNav__monthItem--active');return{month:current.attr('data-month'),year:current.attr('data-year')};}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('events.front.overview.nearMe',{initialize:function(){this.setup();},setup:function(){var self=this;$('head').append("<link rel='stylesheet' type='text/css' media='all' href='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css'><link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v1.0.0/MarkerCluster.css' rel='stylesheet' /><link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v1.0.0/MarkerCluster.Default.css' rel='stylesheet' /><link rel='stylesheet' type='text/css' media='all' href='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css' />");ips.loader.get(['https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js']).then(function(){ips.loader.get(['https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v1.0.0/leaflet.markercluster.js','https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js']).then(function(){if("geolocation"in navigator){self.getEventsByLocation();}else{self.fetchEvents();}
self._mapReady=true;});});},getEventsByLocation:function(){this.showPlaceholders();var self=this;navigator.geolocation.getCurrentPosition(function(position){var lat=position.coords.latitude;var long=position.coords.longitude;self.scope.find('[data-role="nearMeLink"]').attr('href',ips.getSetting('baseURL')+'?app=events&do=search&form_submitted=1&lat='+lat+'&lon='+long).attr('data-lat',lat).attr('data-long',long);self.fetchEvents(lat,long);},function(){self.fetchEvents();});},fetchEvents:function(lat,long){var self=this;ips.getAjax()(ips.getSetting('baseURL')+'?app=events&module=events&controller=overview&get=nearMe'+(lat&&long?'&lat='+lat+'&lon='+long:'')).done(function(response){self.scope.find('[data-role="locationEvents"]').html(response.content);self.setUpMap(response.lat,response.long);$(document).trigger('contentChange',[self.scope]);});},setUpMap:function(lat,long){var self=this;var mapDiv=this.scope.find('#legoMap');L.mapbox.accessToken=ips.getSetting('mapApiKey');this._map=L.mapbox.map(mapDiv.get(0),'mapbox.streets',{zoomControl:false,minZoom:2,dragging:false,zoomControl:false});var markersGroup=new L.featureGroup([]);var markers=$.parseJSON(mapDiv.attr('data-markers'));for(var id in markers){var marker=L.marker([markers[id].lat,markers[id].long],{title:markers[id].title,draggable:false,eventId:parseInt(id)});markersGroup.addLayer(marker);marker.on('mouseover',_.bind(this._markerMouseOver,this));marker.on('mouseout',_.bind(this._markerMouseOut,this));}
markersGroup.addTo(this._map);this._map.fitBounds(markersGroup.getBounds(),{maxZoom:5});},_markerMouseOver:function(e){var eventId=e.target.options.eventId;this.scope.find('[data-eventid]').stop(false,true);this.scope.find('[data-eventid]:not([data-eventid="'+eventId+'"])').animate({opacity:0.4},'fast');},_markerMouseOut:function(e){this.scope.find('[data-eventid]').stop(false,true);this.scope.find('[data-eventid]').animate({opacity:1},'fast');},showPlaceholders:function(count){var events=[];for(var i=0;i<6;i++){events.push(ips.templates.render('eventLoading'));}
this.scope.find('[data-role="locationEvents"]').removeClass('ipsJS_hide').html(ips.templates.render('nearMe',{events:events.join('')}));}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('events.front.overview.search',{initialize:function(){this.on('click','[data-action="useMyLocation"]',this.useMyLocation);this.on('click','[data-action="cancelLocation"]',this.cancelLocation);this.on('submit',this.doSearch);this.on(document,'click','[data-action="backToOverview"]',this.backToOverview);this.on(document,'click','[data-action="loadMoreSearch"]',this.loadMore);this.on(document,'menuItemSelected','#elSortMenu',this.changeSort);this.on(document,'click','[data-action="moreNearMe"]',this.moreNearMe);this.on(document,'click','[data-action="moreExhibitions"]',this.moreExhibitions);History.Adapter.bind(window,'statechange',_.bind(this.stateChange,this));this.setup();},setup:function(){var self=this;this._gotCoords=false;this._offset=0;this._limit=20;this._currentSort=$('body').find('#elSortMenu_menu .ipsMenu_itemChecked').attr('data-ipsMenuValue');this._baseURL=this.scope.attr('action');this._initialURL=window.location.href;this._cancelledLookup=false;this._searchBox=this.scope.find('input[name="term"]');this._previousValue=this._searchBox.val();this._originalPlaceholder=this.scope.attr('data-placeholder');this._locationLink=this.scope.find('[data-action="useMyLocation"]');this._cancelLocationLink=this.scope.find('[data-action="cancelLocation"]');this._page=this.scope.closest('[data-role="eventsPage"]');this._resultsContainer=$('body').find('[data-role="searchResults"]');this._noResults=$('body').find('[data-role="noSearchResults"]');this._loadMore=$('body').find('[data-action="loadMoreSearch"]');this._noMore=$('body').find('[data-role="noMoreSearchResults"]');this._map=null;this._mapContainer=$('body').find('[data-role="searchResultsMap"]');this._markers={};if("geolocation"in navigator){this.getInitialLocation();}
$('head').append("<link rel='stylesheet' type='text/css' media='all' href='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css'><link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v1.0.0/MarkerCluster.css' rel='stylesheet' /><link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v1.0.0/MarkerCluster.Default.css' rel='stylesheet' /><link rel='stylesheet' type='text/css' media='all' href='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css' />");ips.loader.get(['https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js']).then(function(){ips.loader.get(['https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v1.0.0/leaflet.markercluster.js','https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js']).then(function(){self._mapReady=true;Debug.log(self._resultsContainer.find('[data-eventid]'));Debug.log(self._mapContainer.attr('data-markers'));if(self._resultsContainer.find('[data-eventid]').length&&self._mapContainer.attr('data-markers')){Debug.log('here');try{var markers=JSON.parse(self._mapContainer.attr('data-markers'));Debug.log(markers);self._updateMap(markers);}catch(err){Debug.log("Invalid marker JSON");Debug.log(err);}}});});},getInitialLocation:function(){var self=this;navigator.geolocation.getCurrentPosition(function(position){self.setCoords(position.coords.latitude,position.coords.longitude);},function(){self.setCoords(0,0);});},setCoords:function(lat,long){this.scope.prepend("<input type='hidden' name='lat' value='"+lat+"'>");this.scope.prepend("<input type='hidden' name='lon' value='"+long+"'>");this._gotCoords=true;},moreNearMe:function(e){e.preventDefault();var lat=$(e.currentTarget).attr('data-lat');var long=$(e.currentTarget).attr('data-long');var self=this;this.setSearchToLocation();this.scope.find('[name="date[start]"]').val('');this.scope.find('[name="date[end]"]').val('');this.scope.find('[name="show"]').val('regular');$("html, body").animate({scrollTop:"300px"},function(){self.doSearch();});},moreExhibitions:function(e){e.preventDefault();var self=this;this.cancelLocation();this.scope.find('[name="date[start]"]').val('');this.scope.find('[name="date[end]"]').val('');this.scope.find('[name="show"]').val('exhibitions');$("html, body").animate({scrollTop:"300px"},function(){self.doSearch();});},doSearch:function(e){if(e){e.preventDefault();}
var url=this._getUrlFromData();History.replaceState({controller:'events.front.overview.search',url:url},document.title,url);},getPlaceholders:function(count){var events=[];if(_.isUndefined(count)){count=10;}
for(var i=0;i<count;i++){events.push(ips.templates.render('eventLoading'));}
return events.join('');},stateChange:function(){var state=History.getState();if((!state.data.controller||state.data.controller!='events.front.overview.search')&&this._initialURL!==state.url){return;}
if(this._initialURL==state.url){this.hideResults();}else if(this._initialURL==state.url&&_.isUndefined(state.data.url)){this._loadResults(this._getUrlFromData(this._initialData));}else{this._loadResults(state.data.url);}},changeSort:function(e,data){e.preventDefault();this._currentSort=data.selectedItemID;var title=data.menuElem.find('[data-ipsMenuValue="'+this._currentSort+'"]').text();$('body').find('[data-role="searchOrder"]').text(title);this.doSearch();},_getUrlFromData:function(){var formData=this.scope.serializeArray();var params=[];_.each(formData,function(item){if($.trim(item.value)!==''){params.push(item.name+"="+encodeURIComponent(item.value));}});params.push("sortBy="+this._currentSort);return this._baseURL+'&'+params.join('&');},_loadResults:function(url){var self=this;if(this._page.length){this._page.find('[data-role="eventsOverview"]').hide();this._page.find('[data-role="searchResultsWrapper"]').show();}
this._resultsContainer.removeClass('ipsHide').html(this.getPlaceholders(6));this._mapContainer.addClass('legoEventSearchMap--loading').show();this._currentUrl=url;ips.getAjax()(url).done(function(response){if(response.count){self._resultsContainer.html(response.content);self._noResults.addClass('ipsHide');self._updateMap(_.extend({},self._markers,response.markers));if(response.totalCount>(response.count+self._offset)){self._loadMore.show();self._noMore.hide();}else{self._loadMore.hide();self._noMore.hide();}}else{self._resultsContainer.html('').addClass('ipsHide');self._noResults.removeClass('ipsHide');self._loadMore.hide();self._noMore.hide();self._mapContainer.hide();}
$(document).trigger('contentChange',[self._resultsContainer]);});},_updateMap:function(markers){if(!this._map){L.mapbox.accessToken=ips.getSetting('mapApiKey');this._map=L.mapbox.map(this._mapContainer.get(0),'mapbox.streets',{zoomControl:false,minZoom:2,dragging:false,zoomControl:false});this._markersGroup=new L.featureGroup([]);this._markersGroup.addTo(this._map);}
this._mapContainer.removeClass('legoEventSearchMap--loading');this._markersGroup.clearLayers();for(var id in markers){var marker=L.marker([markers[id].lat,markers[id].long],{title:markers[id].title,draggable:false,eventId:parseInt(id)});this._markersGroup.addLayer(marker);marker.on('click',_.bind(this._markerClick,this));}
this._mapContainer.show();this._map.fitBounds(this._markersGroup.getBounds(),{maxZoom:5});},_markerClick:function(e,data){var targetEvent=e.target.options.eventId;var eventBlock=this._resultsContainer.find('[data-eventId="'+targetEvent+'"]');var topPos=eventBlock.offset().top;$('html, body').animate({scrollTop:topPos},function(){eventBlock.css({transform:'scale(1.1)'});setTimeout(function(){eventBlock.css({transform:'scale(1)'});},2000);});},loadMore:function(e){e.preventDefault();var placeholders=this.getPlaceholders(2);this._resultsContainer.append(placeholders);this._loadMore.prop('disabled',true);var self=this;var currentCount=this._resultsContainer.find('[data-eventid]').length;ips.getAjax()(this._currentUrl+"&offset="+currentCount+"&limit="+this._limit).done(function(response){self._resultsContainer.find('.legoEvent--loading').remove();self._resultsContainer.append(response.content);self._updateMap(response.markers);self._loadMore.prop('disabled',false);if(self._resultsContainer.find('[data-eventid]').length>=response.totalCount){self._loadMore.hide();self._noMore.show();}else{self._loadMore.show();self._noMore.hide();}
$(document).trigger('contentChange',[self._resultsContainer]);});},cancelLocation:function(e){if(e){e.preventDefault();}
this._cancelledLookup=true;this._searchBox.val(this._previousValue).attr('placeholder',this._originalPlaceholder).prop('disabled',false).removeClass('ipsField_loading');this._locationLink.show();this._cancelLocationLink.hide();this.scope.find('[name="searchNearLocation"]').remove();},useMyLocation:function(e){e.preventDefault();var self=this;self._cancelledLookup=false;self._searchBox.val('').attr('placeholder','Finding your location...').prop('disabled',true).addClass('ipsField_loading');self._locationLink.hide();self._cancelLocationLink.show();var afterCoords=function(){if(self._cancelledLookup){self._cancelledLookup=false;return;}
self.setSearchToLocation();self._cancelledLookup=false;};if(self._gotCoords){afterCoords()}else{navigator.geolocation.getCurrentPosition(function(position){self.setCoords(position.coords.latitude,position.coords.longitude);},function(){self.setCoords(0,0);});}},setSearchToLocation:function(){this._searchBox.val('').attr('placeholder','Your Current Location').prop('disabled',true).removeClass('ipsField_loading');this.scope.prepend("<input type='hidden' name='searchNearLocation' value='1'>");},backToOverview:function(e){if(!this._page.length){return;}
e.preventDefault();History.replaceState({controller:'events.front.overview.search',url:this._initialURL},document.title,this._initialURL);},hideResults:function(e){this._page.find('[data-role="eventsOverview"]').show();this._page.find('[data-role="searchResultsWrapper"]').hide();}});}(jQuery,_));;