jQuery(function() {
    fitMobileNav();
    responsiveTables();
    initLightbox();
    calMonthViewMarkSelected();
    languageMenu();
    displaySubMenuOfCurrent();
});
function displaySubMenuOfCurrent() {
    if($('.nav-opener').css('display') == 'none') {
        var current = $('.side-nav-area').find('.current');
        current.children('ul').css('display','block').removeClass('js-acc-hidden');
    }
}
function languageMenu() {
    $('.language-holder select').on('change',function(){
        var link = $(this).val();
        window.location.href = link;
    })
}
function calMonthViewMarkSelected() {
    var currentDayOfMonth = jQuery('.tx-cal-controller #selectedDay').data('day');
    jQuery('.tx-cal-controller .month-small .eventDay').not('.monthToday').each(function() {
        var item = jQuery(this);
        if(parseInt(item.children('a').html()) == parseInt(currentDayOfMonth)) {
            item.addClass('selectedDay');
        }
    });
}

function fitMobileNav() {
    jQuery('li.active').each( function () {
        var item = jQuery(this);
        var drop = item.find('ul').eq(0);
        if (drop.length) {
            drop.css('display','block');
        }
    });
}


// cycle scroll gallery init
window.initCycleCarousel = function() {
    jQuery('.cycle-gallery').scrollAbsoluteGallery({
        mask: '.mask',
        slider: '.slideset',
        slides: '.slide',
        btnPrev: 'a.btn-prev',
        btnNext: 'a.btn-next',
        generatePagination: '.pagination',
        stretchSlideToMask: true,
        pauseOnHover: true,
        maskAutoSize: true,
        autoRotation: true,
        switchTime: 5000,
        animSpeed: 500
    });
};


/** js for responsive tables **/
function responsiveTables () {
    $('table tr').each(function () {
        $(this).find('td').each(function (index) {
            $(this).attr('data-header', $(this).parents('table').find('thead tr').children().eq(index).text()
        )});
    });
}

function initLightbox() {

    $('.tx-genericgallery-pi1').lightGallery({
        selector: '*[data-toggle="lightbox"]'
    });

    $("#main").lightGallery({selector: 'a.lightbox'});

}