function map() {
  var $carte = $('#carte');
  if ( $carte.length ) {

    var mymap = L.map('carte').setView([44.7365818, 4.9776488], 13);

    var greenIcon = L.icon({
        iconUrl: '/user/themes/lecampus/images/mappoint.svg',

        iconSize:     [38, 95], // size of the icon
        iconAnchor:   [22, 94], // point of the icon which will correspond to marker's location
        popupAnchor:  [-3, -76] // point from which the popup should open relative to the iconAnchor
    });

  	L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
  		maxZoom: 18,
  		id: 'mapbox.streets'
  	}).addTo(mymap);

  	L.marker([44.7365818, 4.9776488], {icon: greenIcon}).addTo(mymap)
  		.bindPopup("<b>Hello world!</b><br />I am le campus.").openPopup();

  	function onMapClick(e) {
  		popup
  			.setLatLng(e.latlng)
  			.setContent("You clicked the map at " + e.latlng.toString())
  			.openOn(mymap);
  	}

  	mymap.on('click', onMapClick);

  }
}

function filteritem() {
  var $card = $('#item > .card');
  var $cat = $('.cat a');
  var $img = $('#item .img');

  $(".filters .btn").click(function(e) {
    e.preventDefault();

    var filter = $(this).attr("data-filter");
    var self = $('.container #item');

    self.masonryFilter({
        filter: function () {
            if (!filter) return true;
            return $(this).attr("data-filter") == filter;
        }
    });
});

  var $grid = $('#archive #item, #calendrier #item').masonry({
    // columnWidth: 200,
    itemSelector: '.card',
    gutter: 10,
    transitionDuration: '0.2s'
  });

// $( "a[hreflang|='en']" ).css( "border", "3px dotted green" );
  $grid.imagesLoaded().progress(function() {
      $grid.masonry();
  });

}

function slide() {
  $(".gal").slidesjs({
    width: 940,
    height: 528,
    pagination: {
      active: false
    }
  });
}

function links() {
  var $a = $('li a[href="/organisez-vos-evenements"],li a[href="/qui-sommes-nous"] ');
  var $map = $('a#carte');

  $a.on('click', function(e) {
    e.preventDefault();
  })

  $map.on('click', function(e) {
    e.preventDefault();
  })

}

jQuery(document).ready(function(){
  links();
  slide();
  filteritem();
  map();
});
