/*!
 * jQuery UI Touch Punch 0.2.3
 *
 * Copyright 2011–2014, Dave Furfero
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *
 * Depends:
 *  jquery.ui.widget.js
 *  jquery.ui.mouse.js
 */
!function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.bind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery);


var mixer;
function websiteHandling() {
    'use strict';
    var self = this;
    var isMobile = false; //initiate as false

    var activeElements = 0;
    var addActiveElements = 3;
    var filter;

    this.init = function () {
        // device detection
        if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
            || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0, 4))) {
            self.isMobile = true;
        }

        if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
            $('body').addClass('is-safari');
        }

        self.initToolbox();
        self.initDatePicker();
        self.initAutocomplete();
        self.initStationSearch();
        self.initGeoLocation();
        self.initixitUp();
        self.initFixxes();
        self.initMilestones();

        self.initEventfilter();

        self.initWorkloadArea();

    };


    this.initMilestones = function () {

        console.log("init milestones");

        // Slick Selector.
        var slickSlider = $('.milestone-slider');

        if(slickSlider.length == 0) {
            return;
        }

        var maxDots = 5;
        var currentDotCount = 0;
        var pointWidth = $('.milestone-slider').width()/5;

        if (window.matchMedia('(max-width: 767px)').matches) {
            var transformXIntervalNext = -pointWidth;
            var transformXIntervalPrev = pointWidth;
        } else {
            var transformXIntervalNext = -170;
            var transformXIntervalPrev = 170;
        }


        slickSlider.on('init', function (event, slick) {
            $(this).append('<div class="arrow-down" />');

            var dotsWrap = $(this).find('ul.slick-dots');
            dotsWrap.wrap("<div class='slick-dots-container'></div>");
            var dots = $(this).find('ul.slick-dots li');

            currentDotCount = dots.length;
            pointWidth = $('.milestone-slider').width() / currentDotCount;

            dots.each(function (index) {
                $(this).addClass('dot-index-' + index);
                $(this).append('<span>'+slick.$slides.eq(index).data('title')+'</span>');
            });


            // Breite der Dots berechnen (immer aufteilen auf gesamte Slider-Breite)
            calculateDotWidth();

            // Position des Arrows bestimmen
            setArrowPosition(0);
        });

        // Hilfsfunktion zur Bestimmung der Dot-Breite
        var calculateDotWidth = function() {
            $("ul.slick-dots").width($('.milestone-slider').width());
            currentDotCount = slickSlider.find('ul.slick-dots li').length;

            pointWidth = parseInt($('.slick-dots-container').width() / currentDotCount);

            $('.milestone-slider ul.slick-dots li').each(function (index) {
                $(this).width(pointWidth);
            });
        }

        // Hilfsfunktion zur Bestimmung der Arrow-Position
        var setArrowPosition = function(nextSlide) {
            var arrow = slickSlider.find('.arrow-down');
            var transformLeft = $("ul.slick-dots li").eq(nextSlide).position().left;
            var offsetDotContainer = parseInt($(".slick-dots-container").css("margin-left"));
            var dotWidth = $("ul.slick-dots li").width();
            var arrowWith = $(".arrow-down").outerWidth();
            var sliderHeight = $(".milestone-slider").height();

            if( $(window).outerWidth() < 768) {
                offsetDotContainer = 0;
            }

            arrow.css('transform', 'translateX(' + (offsetDotContainer + transformLeft + dotWidth/2 - arrowWith/2) + 'px)');
            arrow.css('top', sliderHeight + "px");
        }

        // Resize Event / Orientation Change
        $(window).resize(function() {
            calculateDotWidth();

            var currentSlide = $('ul.slick-dots li.slick-active').index();
            setArrowPosition(currentSlide);
        });

        var transformCount = 0;

        slickSlider.on('beforeChange', function (event, slick, currentSlide, nextSlide) {

            var totalCount = $(this).find('.slick-dots li').length;

            setArrowPosition(nextSlide);

            if (totalCount > maxDots) {
                if (nextSlide > currentSlide) {
                    if ($(this).find('ul.slick-dots li.dot-index-' + nextSlide).hasClass('n-small-1')) {
                        if (!$(this).find('ul.slick-dots li:last-child').hasClass('n-small-1')) {
                            transformCount = transformCount + transformXIntervalNext;
                            $(this).find('ul.slick-dots li.dot-index-' + nextSlide).removeClass('n-small-1');
                            var nextSlidePlusOne = nextSlide + 1;
                            $(this).find('ul.slick-dots li.dot-index-' + nextSlidePlusOne).addClass('n-small-1');
                            $(this).find('ul.slick-dots').css('transform', 'translateX(' + transformCount + 'px)');
                            var pPointer = nextSlide - 3;
                            var pPointerMinusOne = pPointer - 1;
                            $(this).find('ul.slick-dots li').eq(pPointerMinusOne).removeClass('p-small-1');
                            $(this).find('ul.slick-dots li').eq(pPointer).addClass('p-small-1');
                        }
                    }
                }
                else {
                    if ($(this).find('ul.slick-dots li.dot-index-' + nextSlide).hasClass('p-small-1')) {
                        if (!$(this).find('ul.slick-dots li:first-child').hasClass('p-small-1')) {
                            transformCount = transformCount + transformXIntervalPrev;
                            $(this).find('ul.slick-dots li.dot-index-' + nextSlide).removeClass('p-small-1');
                            var nextSlidePlusOne = nextSlide - 1;
                            $(this).find('ul.slick-dots li.dot-index-' + nextSlidePlusOne).addClass('p-small-1');
                            $(this).find('ul.slick-dots').css('transform', 'translateX(' + transformCount + 'px)');
                            var nPointer = currentSlide + 3;
                            var nPointerMinusOne = nPointer - 1;
                            $(this).find('ul.slick-dots li').eq(nPointer).removeClass('n-small-1');
                            $(this).find('ul.slick-dots li').eq(nPointerMinusOne).addClass('n-small-1');
                        }
                    }
                }
            }
        });

        slickSlider.slick({
            dots: true,
            infinite: false,
            slidesToShow: 1,
            slidesToScroll: 1,
            rows: 0,
            arrows: true,
            speed: 300,
            responsive: [
                {
                    breakpoint: 768,
                    settings: {
                        arrows: false,
                        dots: true,
                        adaptiveHeight: false
                    }
                },
            ]
        });



    };

    this.initFixxes = function () {
        if (isMobile){
            $('div.stat').on('touchstart click', function(e){
                e.stopPropagation(); e.preventDefault();
                $('.simulate-hover').removeClass('simulate-hover');
                $(this).addClass('simulate-hover');
            });
        }
    };

    this.initixitUp = function () {

        if ($('#station-result.mixer').length){
            try {
                mixer.destroy();
            }catch(x) {}

            mixer = mixitup('#station-result.mixer', {
                controls: {
                    scope: 'local'
                },
                selectors: {
                    target: '.station-list > li'
                },
                animation: {
                    effects: 'fade translateZ(-100px)'
                }/*,
                callbacks: {
                    onMixEnd: function(state){
                    }
                }*/
            });
        }
    };


    this.initToolbox = function () {
        $('#pills-home .list-holder input,' +
            '.root-layout-288 #pills-profile .list-holder input,' +
            '.root-layout-289 #pills-profile .list-holder .dropdown-toggle,' +
            '.root-layout-290 #pills-profile .list-holder .dropdown-toggle'
        ).focusin(function() {
            $('#top-toolbox').slideDown();
            $('body').addClass('toolbox-open');
        });

        if (!$('.root-layout-289').length && !$('.root-layout-290').length){
            $('#pills-contact-tab').on('click', function (e) {
                $('body').toggleClass('toolbox-open');
            });
        }


        $('#add-input').on('click', function (e) {
            e.preventDefault();
            $(this).hide();
            $('#extra-route').fadeIn();
        });

        $('#change-orient').on('click', function (e) {
            e.preventDefault();

            var rfrom = $('#routefrom').val();
            var rto = $('#routeto').val();
            var from =  $('#from').val();
            var to = $('#to').val();


            $('#routefrom').val(rto);
            $('#routeto').val(rfrom);
            $('#from').val(to);
            $('#to').val(from);

        });

        $('.nav-item.last:not(.no-special) > a').on('click', function (e) {
            e.preventDefault();
            if ($(this).hasClass('active')){
                if (!$('#pills-contact').hasClass('hide-panel')){
                    $('#pills-contact, #pills-contact-tab').addClass('hide-panel');
                }else{
                    $('#pills-contact, #pills-contact-tab').removeClass('hide-panel');
                }
            }else{
                $('#pills-contact, #pills-contact-tab').removeClass('hide-panel');
            }
        });

        if($("#error-messages").length !== 0 && $("#message-count").length !== 0) {
            var messages = $('#error-messages').data('count');
            var notPlanned = $('#error-messages').data('notplanned');
            $('#message-count,#message-count-mobile').html(messages);

            if(notPlanned > 0 || messages >= 5){
                $('#pills-contact-tab, #pills-contact, .mobile-toolbox').addClass('error');
            } else if (messages > 0) {
                $('#pills-contact-tab, #pills-contact, .mobile-toolbox').addClass('warning');
            } else {
                $('#pills-contact-tab, #pills-contact, .mobile-toolbox').addClass('success');
            }
        }

        $(document).on('click', '.line', function (e) {
            self.initFilter($(this).data('filter'));
            self.addStopEvents();

        });

        $(document).scroll(function() {
            var y = $(this).scrollTop();
            if (isMobile && y > 300 || y > 500) {
                $('.back-top').fadeIn();
            } else {
                $('.back-top').fadeOut();
            }
        });

        $(document).on('submit', '#from-to-timetable', function (e) {
            $('#from-to-timetable button').attr('disabled', true);
            $('#from-to-timetable .spinner').removeClass('d-none');
            $('#from-to-timetable .bt-text').addClass('sr-only');
        });

        // Klick auf Betriebsmeldung
        $('#accordion').on('show.bs.collapse', function (e) {
            $(e.target).parents('.route').addClass('open-route');
            $(e.target).parents(".route").find(".dot.disabled").removeClass("disabled").attr("data-disabled", 1);
            $(e.target).parents('.route').find(".dot.lmore").addClass('disabled');
        });

        // Klick auf Betriebsmeldung
        $('#accordion').on('hide.bs.collapse', function (e) {
            $(e.target).parents('.route').removeClass('open-route');
            $(e.target).parents(".route").find(".dot[data-disabled='1']").addClass("disabled").attr("data-disabled", 0);
            $(e.target).parents('.route').find(".dot.lmore").removeClass('disabled');
        });

        if (self.isMobile){
            var height = $('#pills-tabContent').height()+50;

            if ($('.mobile-toolbox').length){
                height = height+50;
            }
            $('.info-holder .slider-info').css('bottom', height);
            $('a[data-toggle="pill"]').on('shown.bs.tab', function (e) {
                var height = $('#pills-tabContent').height()+50;
                if ($('.mobile-toolbox').length){
                    height = height+50;
                }
                $('.info-holder .slider-info').css('bottom', height);
            });
        }
    };

    this.initFilter = function (f) {
        $('.stop-event').removeClass('active');
        filter = f;
        activeElements = 0;
    };

    /**
     * add stop events
     */
    this.addStopEvents = function(){
        if(filter) {
            $(filter).slice(activeElements, activeElements + addActiveElements).addClass('active');
        } else {
            $('.stop-event').slice(activeElements, activeElements + addActiveElements).addClass('active');
        }
        activeElements = activeElements + addActiveElements;
    };


    this.initDatePicker = function(){
        flatpickr.localize(flatpickr.l10ns.de);
        $(".dayselect").flatpickr({
            locale: 'de',
            dateFormat: "Y-m-d",
            minDate: "today",
            defaultDate: "today",
            altInput: true,
            wrap: true,
            altFormat: "j. F Y",
            onReady: function(selectedDates, dateStr, instance) {
            },
            onChange: function(selectedDates, dateStr, instance) {
            },
        });

        $(".dayselect-placeholder").flatpickr({
            locale: 'de',
            dateFormat: "Y-m-d",
            minDate: "today",
            altInput: true,
            wrap: true,
            altFormat: "d.m.",
            onReady: function(selectedDates, dateStr, instance) {
            },
            onChange: function(selectedDates, dateStr, instance) {
            },
        });

        $(".dayselect-nodefault").flatpickr({
            locale: 'de',
            dateFormat: "Y-m-d",
            minDate: "today",
            altInput: true,
            wrap: true,
            altFormat: "j. F Y",
            onReady: function(selectedDates, dateStr, instance) {
            },
            onChange: function(selectedDates, dateStr, instance) {
            },
        });

        var coeff = 1000 * 60 * 5;
        var rounded = new Date(Math.round(new Date().getTime() / coeff) * coeff);

        $(".timeselect").flatpickr({
            locale: 'de',
            enableTime: true,
            noCalendar: true,
            wrap: true,
            dateFormat: "H:i",
            time_24hr: true,
            defaultDate: rounded
        });

        $(".timeselect-nodefault").flatpickr({
            locale: 'de',
            enableTime: true,
            noCalendar: true,
            wrap: true,
            dateFormat: "H:i",
            time_24hr: true
        });
    };


    this.initAutocomplete = function () {
        $( 'input.autocomplete' ).autocomplete({
            autoFocus: true,
            delay: 50,
            source: function( request, response ) {

                var term = request.term;
                term = term.replace(/[^a-zA-Z 0-9äöüÄÜÖ-]+/g, '');

                var url = $('#attributes').attr('data-service-url') + '?tx_twwctimetable_pi5%5Bquery%5D=' + term;
                $.ajax({
                    dataType: "json",
                    type : 'Get',
                    url: url,
                    success: function(data) {
                        response(data);
                    },
                    error: function(data) {
                    }
                });
            },
            select: function( event, ui ) {
                $(this).parent().addClass('selected');
                var input = ($(this).attr('data-input'));
                $("#" + input).val(ui.item.didok);

                if($("#from").val() && $("#to").val()){
                    $('#attributes button').attr('disabled', false);
                } else {
                    $('#attributes button').attr('disabled', true);
                }

            },
            classes: {
                "ui-autocomplete": "highlight"
            },
            position: {  collision: "flip"  }
        });

        if($("#station-search").length !== 0) {
            var stations;
            var resources = $('#station-search').data('source');
            var redirect = $('#station-search').data('redirect');

            $.getJSON(resources, function (data) {
                stations = data;
                $( 'input.autocomplete-file' ).autocomplete({
                    source: stations,
                    autoFocus: true,
                    delay: 50,
                    select: function( event, ui ) {
                        $(this).parent().addClass('selected');
                        var input = ($(this).attr('data-input'));
                        $("#" + input).val(ui.item.didok);

                        if(redirect){
                            redirect = redirect+'ab-'+ui.item.didok;
                            $(location).attr('href',redirect);
                        }else{
                            $('#station-search button').attr('disabled', true);

                            $('#station-search').submit();
                            $("document").focus();
                        }

                    },
                    minLength: 2,
                    classes: {
                        "ui-autocomplete": "highlight"
                    },
                    position: {  collision: "flip"  }
                });
            });
        }
    }

    this.initStationSearch = function () {

        if ($('#station-search').length){
            $(document).on('submit', '#station-search', function (e) {

                e.preventDefault();

                var url = $(this).attr("action");

                $('#station-search .spinner').removeClass('d-none');
                $('#station-search .bt-text').addClass('sr-only');


                $.ajax({
                    type: 'POST',
                    url: url,
                    context: this,
                    data: $.param($(this).serializeArray()),
                    success: function (data) {
                        var content = jQuery('<div>' + data + '</div>');
                        $("#station-result").html(content.find('#station-result').html());
                        $("#station-title").html(content.find('#station-title').html());

                        websiteHandle.initixitUp();

                        $('#station-search .spinner').addClass('d-none');
                        $('#station-search .bt-text').removeClass('sr-only');
                        $('#station-search button').attr('disabled', false);
                        $("document").focus();
                    },error: function(request, status, erro){
                        //$('#price-spinner').hide();
                        //$('#submit-offer').prop('disabled', false);
                    }
                });

            });
        }

        if ($('#ship-stations').length){
            $('#ship-stations').on('change', function (e) {
                if($(this).find(":selected").val() > 0){
                    $("#station-search").submit();
                } else {
                    $("#ship-station-bt").attr('disabled', true);
                }
            });
        }



    }

    this.initGeoLocation = function () {
        $('.didok-gps').on('click', function (e) {

            var url = $(this).data('source');
            var name = $(this).data('name');
            var didok = $(this).data('didok');

            var currentPlaceHolder = $(name).attr('placeholder');
            $(name).attr('placeholder','suchen');


            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(
                    function (position) {
                        var latitude = position.coords.latitude;
                        var longitude = position.coords.longitude;

                        $.ajax({
                            dataType: "json",
                            type : 'Get',
                            url: url,
                            data: { latitude: latitude, longitude: longitude},
                            success: function(data) {

                                $(name).attr('placeholder',currentPlaceHolder);

                                if(data){
                                    $(name).val(data['name']);
                                    $(didok).val(data['didok']);

                                }

                                if($("#from").val() && $("#to").val()){
                                    $('#attributes button').attr('disabled', false);
                                } else {
                                    $('#attributes button').attr('disabled', true);
                                }

                                if($("#fromStation").val()) {
                                    $('#station-search button').attr('disabled', false);
                                }

                            },
                            error: function(request, status, error) {
                                $(name).attr('placeholder',currentPlaceHolder);

                            }

                        });
                    });
            }
        });
    }


    this.initEventfilter = function () {

        if($(".booking-offers").length > 0) {
            console.log("init eventfilter");

            var offers = $(".booking-offers > a");
            var totalOffers = 0;
            var currentOfferoffset = 0;
            var visibleOffers = 0;

            var loadMore = $(".load-more");
            var filterButton = $(".offer-filter-btn");
            var filterResetButton = $(".offer-reset-filter-btn");

            if(offers.length > 0) {
                totalOffers = offers.length;
                visibleOffers = $(".booking-offers > a.offer-visible").length;

                if(visibleOffers < totalOffers) {
                    loadMore.show();
                }
                else {
                    loadMore.hide();
                }
            }

            loadMore.find("a").click(function() {
                var tmpCnt = 0;
                $(".booking-offers > a:not(.offer-visible)").each(function() {
                    if(tmpCnt < 5) {
                        $(this).addClass("offer-visible");
                        visibleOffers = $(".booking-offers > a.offer-visible").length;
                        tmpCnt++;
                    }
                })

                if(visibleOffers < totalOffers) {
                    loadMore.show();
                }
                else {
                    loadMore.hide();
                }
            })

            /**
             * Klick-Handler für "Filterung".
             */
            filterButton.click(function () {
                var filterFrom = ($("#filter_offer_date_from").val() != "")?new Date($("#filter_offer_date_from").val()):null;
                var filterTo = ($("#filter_offer_date_to").val() != "")?new Date($("#filter_offer_date_to").val()):null;

                if(filterFrom != null || filterTo != null) {
                    $("h3.offer-table-heading-upcoming").addClass("d-none");
                    $("h3.offer-table-heading-results").removeClass("d-none");

                    offers.each(function () {
                        var offerDate = new Date($(this).attr("data-offer-date"));
                        $(this).removeClass("offer-visible");

                        if (filterFrom != null && filterTo == null && filterFrom <= offerDate) {
                            $(this).addClass("offer-visible");
                        }

                        if (filterFrom == null && filterTo != null && filterTo >= offerDate) {
                            $(this).addClass("offer-visible");
                        }

                        if (filterFrom != null && filterTo != null && filterFrom <= offerDate && filterTo >= offerDate) {
                            $(this).addClass("offer-visible");
                        }
                    })

                    visibleOffers = $(".booking-offers > a.offer-visible").length;
                    if(visibleOffers === 0) {
                        $(".message-no-results").removeClass("d-none");
                    } else {
                        $(".message-no-results").addClass("d-none");
                    }

                    loadMore.hide();
                }
            });

            filterResetButton.click(function() {
                $("#filter_offer_date_from").val("");
                $("#filter_offer_date_from").next("input").val("");
                $("#filter_offer_date_to").val("");
                $("#filter_offer_date_to").next("input").val("");

                offers.each(function(index) {
                    if(index < 5) {
                        $(this).addClass("offer-visible");
                    } else {
                        $(this).removeClass("offer-visible");
                    }
                });

                visibleOffers = $(".booking-offers > a.offer-visible").length;

                $("h3.offer-table-heading-upcoming").removeClass("d-none");
                $("h3.offer-table-heading-results").addClass("d-none");
                $(".message-no-results").addClass("d-none");

                if(visibleOffers < totalOffers) {
                    loadMore.show();
                }
                else {
                    loadMore.hide();
                }
            })

        }

    }

    self.initWorkloadArea = function() {
        if($(".workload-area").length) {

            $(".workload-navigation .route-button.lmore").click(function() {
                $(".workload-navigation .route-button").removeClass("disabled").removeClass("disabled-mobile");
                $(this).addClass("disabled");
            })

            /*$(".workload-area").draggable({
                axis: "x",
                cursor: "move",
                drag: function(event, ui) {
                    var leftPosition = ui.position.left;
                    console.log(ui.position.left);

                    var containerWidth = $(".workload-area-container").width();
                    var draggableWidth = $(".workload-area").width();

                    if (leftPosition > 0) {
                        ui.position.left = 0;
                    }

                    if (containerWidth - draggableWidth > ui.position.left) {
                        ui.position.left = containerWidth - draggableWidth;
                    }


                }
            });*/


        }

    }
}
var websiteHandle;
(function ($) {
    'use strict';
    $(document).ready(function () {
        websiteHandle = new websiteHandling();
        websiteHandle.init();
    });
})(jQuery);

