$(document).ready(function(){
$('.link-gallery').click(function(){
var galleryId = $(this).attr('data-target');
var currentLinkIndex = $(this).index('a[data-target="'+ galleryId +'"]');
createGallery(galleryId, currentLinkIndex);
createPagination(galleryId, currentLinkIndex);
$(galleryId).on('hidden.bs.modal', function (){
destroyGallry(galleryId);
destroyPagination(galleryId);
});
$(galleryId +' .carousel').on('slid.bs.carousel', function (){
var currentSlide = $(galleryId +' .carousel .item.active');
var currentSlideIndex = currentSlide.index(galleryId +' .carousel .item');
setTitle(galleryId, currentSlideIndex);
setPagination(++currentSlideIndex, true);
})
});
function createGallery(galleryId, currentSlideIndex){
var galleryBox = $(galleryId + ' .carousel-inner');
$('a[data-target="'+ galleryId +'"]').each(function(){
var img = $(this).html();
var galleryItem = $('<div class="item">'+ img +'</div>');
galleryItem.appendTo(galleryBox);
});
galleryBox.children('.item').eq(currentSlideIndex).addClass('active');
setTitle(galleryId, currentSlideIndex);
}
function destroyGallry(galleryId){