
/* OMS WallPaper Settings
-------------------------------------*/
var contentContainerWidth = 1088;
var omsv_centered = true;
var OMSres_screen_width = typeof document.documentElement != 'undefined' ? document.documentElement.clientWidth : window.innerWidth;
var adlWallPaperLeft = (OMSres_screen_width/2)+(contentContainerWidth/2);


console.log('document is loading...');

$(document).ready(function() {
    console.log('document.ready event is fired...');

    /* Template-Helper */
    $('[data-toggle="tmplHelperTooltip"]').tooltip({
        title: function() {
            return $(this).attr('class');
        }
    });



    /* Option Panel Dropdown Handling
    -------------------------------------*/
    var optionPanel = '#optionPanel';
    var optionPanelDd = optionPanel + ' .dropDown';

    $(optionPanel + ' > ul a').click(function(e){
        e.preventDefault(); //prevent default action
        e.stopPropagation(); //prevent other events
        target = $(this).attr('class');
        if( $(optionPanelDd + '.' + target).hasClass('open') ) {
            $(optionPanelDd).hide().removeClass('open');
        } else {
            $(optionPanelDd).hide().removeClass('open');
            $(optionPanelDd + '.' + target).fadeIn(100).addClass('open');
            if(target == 'search') $(optionPanelDd + '.' + target + ' input').focus();
        }
    });

    $(optionPanelDd).click(function(e) {
        e.stopPropagation(); //prevent other events
    });

    $(document).click(function(e) {
        $(optionPanelDd + '.open').hide().removeClass('open');
    });



    /* Bootstrap Popover Init
    ----------------------------*/
    $('[data-toggle="popover"]').popover();



    /* Bootstrap SelectPicker
    ----------------------------*/
    $('.selectpicker').selectpicker({
        style: 'btn-default',
        showTick: true,
        iconBase: 'fa',
        tickIcon: 'fa-check',
        liveSearch: false,
        liveSearchPlaceholder: 'Suche...'
    });



    /* File-Input-Styler "FileStyle" for Bootstrap
    ----------------------------------------------*/
    $(':file').filestyle({
        buttonText: '',
        buttonName: 'btn-primary',
        buttonBefore: true,
        placeholder: 'Datei wählen...'
    });



    /* Newsticker
    ----------------------------*/
    var mq = $('#newsTickerArea .content').marquee({
        duration: 15000,
        pauseOnHover: true,
        gap: 50,
        delayBeforeStart: 0,
        direction: 'left',
        duplicated: false,
        startVisible: false,
        allowCss3Support: true
    });



    /* Region-Filter
    ----------------------------*/
    /*
    $('.regionFilter form').submit(function(event) {
        event.preventDefault();
        alert( "Submit-Event is fired..." );
    });

    $('.regionFilter form select').on('changed.bs.select', function (e) {
        alert( "Change-Event is fired..." );
    });
    */



    /* Search-Stage Filter-Options
    --------------------------------*/
    $('.searchStage .filterOptionsToggle').click(function() {
        var collapseIcon = $(this).find('span.icon');
        $('.searchStage .filterOptions').slideToggle();
        if(collapseIcon.hasClass('glyphicon-menu-down')) collapseIcon.removeClass('glyphicon-menu-down').addClass('glyphicon-menu-up');
        else collapseIcon.removeClass('glyphicon-menu-up').addClass('glyphicon-menu-down');
    });


    /* Content Slider (owl-carousel)
    -----------------------------------------*/
    var owlCarousel = $('.owl-carousel');

    owlCarousel.each(function(index) {

        //if (!$(this).is('#iconyCarousel')){
        //Variable Defaults
        var items = 1;
        var responsive = {};
        var margin = 0;
        var dots = true;
        var autoplay = false;
        var autoplayTimeout = 5000;

        //Type: Rubric Bar
        if( $(this).hasClass('carouselTypeRubricBar') && !$(this).hasClass('carouselTypeFlirtRubricBar') ) {
            margin = 20;
            responsive = {
                0:{
                    items:1
                },
                400:{
                    items:2
                },
                768:{
                    items:3
                },
                993:{
                    items:3
                },
                1264:{
                    items:4
                }
            };
        }
        //Type: Anzeigen/Prospekte
        else if( $(this).hasClass('carouselTypeLeaflet') ) {
            margin = 60;
            responsive = {
                0:{
                    items:2
                },
                768:{
                    items:2
                },
                993:{
                    items:2
                },
                1264:{
                    items:2
                }
            };
            autoplay = true;
            autoplayTimeout = 3000;
        }
        //Type: Shop
        else if( $(this).hasClass('carouselTypeShop') ) {
            margin = 60;
            responsive = {
                0:{
                    items:1
                },
                400:{
                    items:2,
                    margin:10
                },
                600:{
                    items:3,
                    margin:30
                },
                993:{
                    items:3
                },
                1264:{
                    items:4
                }
            };
        }
        //Type: Media
        else if( $(this).hasClass('carouselTypeMedia') ) {
            margin = 26;
            dots = false;
            responsive = {
                0:{
                    items:1
                },
                480:{
                    items:2
                },
                710:{
                    items:3
                },
                993:{
                    items:3
                },
                1264:{
                    items:4
                }
            };
        }


        if(!$(this).hasClass('carouselTypeFlirtRubricBar')){
            // Carousel Initialisierung
            $(this).owlCarousel({
                items: items,
                responsive: responsive,
                margin: margin,
                rewind: true,
                nav: true,
                dots: dots,
                navText: ['<span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span>', '<span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span>'],
                autoplay: autoplay,
                autoplayTimeout: autoplayTimeout,
                loop:true,
                autoplayHoverPause: true,
            });

            // Wrap around nav & dots
            $(this).find('.owl-nav, .owl-dots').wrapAll("<div class='owl-controls'></div>");
        }
        //}
    });


    /* Image Slider (bootstrap-carousel)
    -----------------------------------------*/
    /* Initial beim Pageload */
    $('.imageSlider').each(function(index) {
        var target = $(this).attr('id');

        // Custom Caption
        var caption = $('#'+target+' .item.active .carousel-caption').html();
        if(caption == undefined || caption == '') $('.'+target+'.imageSliderCaption').hide();
        else $('.'+target+'.imageSliderCaption')
            .html(caption)
            .show();

        // Counter
        var totalItems = $(this).find('.item').length;
        var currentItem = $(this).find('.item.active').index() + 1;
        $(this).find('.counter .numbers').html(currentItem+' / '+totalItems);
    });

    /* Updates beim Sliden */
    $('.imageSlider').on('slide.bs.carousel', function (evt) {
        var target = $(this).attr('id');
        var indexNextItem = $(evt.relatedTarget).index() + 1;

        // Custom Caption
        var caption = $('#'+target+' .item:nth-child(' + indexNextItem + ') .carousel-caption').html();
        if(caption == undefined || caption == '') $('.'+target+'.imageSliderCaption').hide();
        else $('.'+target+'.imageSliderCaption')
            .html(caption)
            .show();

        // Counter
        var totalItems = $(this).find('.item').length;
        var currentItem = indexNextItem;
        $(this).find('.counter .numbers').html(currentItem+' / '+totalItems);
    });

    /* Swipe Support (bcSwipe) */
    $('.imageSlider').bcSwipe({
        threshold: 50
    });


});