$(document).ready(function() {
  if ($('a.imageGalleryItem').length > 0) {
    $('a.imageGalleryItem').overlay({
      target: '#redGallery',
      expose: '#111',
      closeOnClick: true
    });
    $('a.imageGalleryItem').alternativegallery({
      disabledClass: 'inactive',
      speed: 'fast',
      altInfoDestID: '#altGalleryInfo',
      altInfoIDPrefix: '#ref-',
      template: '<div id="altGalleryInfo"></div><span style="float:right;">${index} / ${total}</span>',
      preload: false,
      autohide: false
    });
  }
  if ($('a.videoGalleryItem').length > 0) {
    $('a.videoGalleryItem').overlay({
      target: '#redVideoGallery',
      expose: '#111',
      closeOnClick: true
    });
    $('a.videoGalleryItem').alternativegallery({
      disabledClass: 'inactive',
      speed: 'fast',
      altInfoDestID: '#altVideoGalleryInfo',
      altInfoIDPrefix: '#ref-',
      template: '<div id="altVideoGalleryInfo"></div><span style="float:right;">${index} / ${total}</span>',
      preload: false,
      autohide: false,
      beforeChange: function(el) {
        $('#redVideoContent').html('');
      },
      afterChange: function(el) {
        $('#redVideoContent').html('');
        $('#redVideoContent').css('width', $('#redVideoGallery #img').css('width')).css('height', ($('#redVideoGallery #img').innerHeight())+'px');
        $('#redVideoGallery #img').css('display', 'none');
        startFlowPlayer('redVideoContent', el.attr('rel'));
      }
    });
  }
  $('#Map area').tooltip({
    showURL: false,
    delay: 100,
    extraClass: 'finalistTooltip',
    bodyHandler: function() {
      return $($(this).next()).html();
    }
  });
});