(function (document, window, $) {
    if ($("*").is('#dayitime')) {
        function addZero(i) {
            if (i < 10) {
                i = "0" + i;
            }
            return i;
        };
        function getCurrentTime1() {
            var today_time, h, m;
            today_time = new Date(Date.now());
            h = today_time.getUTCHours();
            m = addZero(today_time.getUTCMinutes());
            return (h + 3) + '<span class=timeseparator>:</span>' + m;
        }

        function setTimer1() {
            today_time.innerHTML = getCurrentTime1();
        }

        setInterval(setTimer1, 1000);
    }

    function clock() {
        var d = new Date();
        var month_num = d.getMonth()
        var day = d.getDate();
        var hours = d.getHours();
        var minutes = d.getMinutes();
        var seconds = d.getSeconds();
        var weekday_num = d.getDay();

        var month = new Array("января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря");
        var weekday = new Array("воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота");

        if (day <= 9) day = "0" + day;
        if (hours <= 9) hours = "0" + hours;
        if (minutes <= 9) minutes = "0" + minutes;
        if (seconds <= 9) seconds = "0" + seconds;

        var date_time = day + " " + month[month_num] + ", " + weekday[weekday_num] + ", ";
        if (document.layers) {
            document.layers.today_day.document.write(date_time);
            document.layers.today_day.document.close();
        }
        else document.getElementById("today_day").innerHTML = date_time;
        setTimeout(clock, 1000);
    }

    if ($("*").is('#filterservice')) {
        function checktoggle() {
            if ($("#switch_old").is(':checked')) {
                $('#switch_old2').addClass("filterservice__labelbig--active");
                $('#switch_old1').removeClass("filterservice__labelbig--active");
            } else {
                $('#switch_old1').addClass("filterservice__labelbig--active");
                $('#switch_old2').removeClass("filterservice__labelbig--active");
            }

            if ($("#switch_male").is(':checked')) {
                $('#switch_male2').addClass("filterservice__labelbig--active");
                $('#switch_male1').removeClass("filterservice__labelbig--active");
            } else {
                $('#switch_male1').addClass("filterservice__labelbig--active");
                $('#switch_male2').removeClass("filterservice__labelbig--active");
            }
        }
    }

    $(document).ready(function () {

        $(".region__link").click(function (e) {
            e.preventDefault();
        });

        setTimeout(function () {
            $(".shortnews__description").dotdotdot();
        }, 10);

        if ($("*").is('#filterservice')) {
            checktoggle();
        }


        $(".filterservice__toggle").click(function () {
            checktoggle();
        });

        if ($("*").is('#datefilter')) {
            $('#datefilter').dateRangePicker({
                autoClose: true,
                language: 'ru',
                duration: 500,
                startOfWeek: "monday",
                getValue: function () {
                    return document.getElementById('datefiltertext').innerHTML;
                }, setValue: function (s) {
                    document.getElementById('datefiltertext').innerHTML = s;
                }
            });
        }
        if ($("*").is('.calendinfo__calendcase')) {
            $('.calendinfo__calendcase').dateRangePicker({
                inline: true,
                language: 'ru',
                container: '#calendinfo_range',
                alwaysOpen: true,
                singleMonth: true,
                showTopbar: false,
                singleDate: true,
                startOfWeek: "monday",
            });
        }

        if ($("*").is('#calendinfo')) {
            clock();
        }

        $('input, textarea').focus(function () {
            $(this).data('placeholder', $(this).attr('placeholder'))
            $(this).attr('placeholder', '');
        });
        $('input, textarea').blur(function () {
            $(this).attr('placeholder', $(this).data('placeholder'));
        });

        $('#organization__title, #specialization__title').click(function (e) {
            $(this).next().toggleClass('active');
            $(this).find('.leftbar__arrow').toggleClass('active');
            e.preventDefault();
        });

        if ($("*").is('#full_news__sliderlist')) {
            $('#full_news__sliderlist').lightSlider({
                selector: '.full-news__slirderitem',
                item: 1,
                loop: true,
                auto: true,
                pause: 8000,
                speed: 1000,
                gallery: true,
                thumbItem: 4
                // controls: false,
                // onSliderLoad: function(el) {
                //     el.lightGallery({
                //         selector: '#fullnews__gallerylist .lslide'
                //     });
                // },
            });
        }

        if ($("*").is('#mainsliderId')) {
            $('#mainsliderId').lightSlider({
                selector: '.mainslider__item',
                item: 1,
                loop: true,
                auto: true,
                pause: 8000,
                speed: 1000,
                // mode: 'fade',
                controls: false
            });
        }

        /*$('.centerbar input, .centerbar select').styler();*/

        if ($("*").is('#newsfilter')) {
            $("#newsfiltericon").click(function () {
                $(".newsfilter__open").toggleClass('newsfilter__open--show');
            });
        }

    });

    $(window).scroll(function () {
        if ($(this).scrollTop() > 750 && $('.header, .content').hasClass('loading')) {
            $('.header, .content').removeClass('loading').addClass('scrolling');
        } else if ($(this).scrollTop() <= 750 && $('.header, .content').hasClass('scrolling')) {
            $('.header, .content').removeClass('scrolling').addClass('loading');
        }
    });

    new SpecFilter.SpecFilter($('.newsfilter__specializations .newsfilter__text'));
    new RegionFilter.RegionFilter($('.newsfilter__regions .newsfilter__text'), {
        itemsContainerClass: 'regionsfilter__container',
        itemContainerClass: 'regionsfilter__region',
        itemCheckboxClass: 'regionsfilter__checkbox',
        itemLabelClass: 'regionsfilter__label'
    });

    window.showFotorama = function(jQuery, fotoramaObjectClass, fotoramaPrevClass, fotoramaNextClass) {
        var $selector = jQuery(fotoramaObjectClass);
        $selector.data('navwidth', ($selector.outerWidth() - 80) + 'px');
        var $fotoramaDiv = $selector.fotorama();
        var fotorama = $fotoramaDiv.data('fotorama');
        jQuery(fotoramaPrevClass).click((function (e) {
            fotorama.show('<');
        }).bind(this));
        jQuery(fotoramaNextClass).click((function (e) {
            fotorama.show('>');
        }).bind(this));
    };

})(window.document, window, window.jQuery);