$(document).ready(function () {
    
    $('.flexslider').flexslider({
        controlNav: false,
        prevText: '',
        nextText: '',
        slideshow: true,
        pauseOnAction: true,
        pauseOnHover: false
    });
    
    if (forceReference) {
        $('ul.nav.navbar-nav').find('li').removeClass('current-menu-item');
        $('li#menu-item-20').addClass('current-menu-item');
    }
    
    $(window).on('scroll', function (event) {
        var scrollValue = $(window).scrollTop();
        var scrollTop = 0;
        if (scrollValue > 230) {
            scrollTop = (scrollValue - 230);
        }
        $('.sidebar.sticky').css({
            top: scrollTop + 'px'
        });
    });
    
    var appContainer = $('body');
    
    console.log('hello world');
    console.log('appContainer', appContainer);
    
    $(appContainer).off('click', '*[data-gallery-key]');
    $(appContainer).on('click', '*[data-gallery-key]', function () {
        console.log('key');
        var key = $(this).attr('data-gallery-key');
        renderImage(key);
    });
    
    function renderImage(key)
    {
        // If the window is small ...
        if ($(window).width() < 767) {
            // Block the modal
           // return false;
        }
        
        // Open the modal
        $('#image-gallery').modal();
        
        var imageData = imageArray[key];
        
        var galleryWidthh = $('#image-gallery-container').width();
        var maxRatio = galleryWidthh / maxGalleryWidth;
        
        // Check if url is defined
        if (typeof imageData !== 'undefined' && imageData.largeUrl.length > 0) {
            var imageRatio = galleryWidthh / imageData.width;
            $('#image-gallery-container').css('height', (imageData.height * imageRatio) + 'px');
        }
        
        $('#image-gallery-container').css('height', (maxGalleryHeight * maxRatio) + 'px');
        $('#image-gallery-wrapper').css('height', (maxGalleryHeight * maxRatio) + 'px');
        $('#image-gallery-container').css('background-image', 'url(' + imageData.largeUrl + ')');
        
        $('#image-gallery-title').html('<span>' + imageData.title + '</span>');
        
        var prevImg = imageArray[parseInt(key) - 1];
        var nextImg = imageArray[parseInt(key) + 1];
        
        if (typeof prevImg !== 'undefined') {
            $('#prev-gallery-image').removeClass('hidden').attr('data-gallery-key', parseInt(key) - 1);
        } else {
            $('#prev-gallery-image').addClass('hidden');
        }
        if (typeof nextImg !== 'undefined') {
            $('#next-gallery-image').removeClass('hidden').attr('data-gallery-key', parseInt(key) + 1);
        } else {
            $('#next-gallery-image').addClass('hidden');
        }
    }
});