
var baseURL;
var __device; // 1=XS; 2=SM, 3=MD, 4=LG
var _bxSliders = [];
var _language;
var _codeCheckForm = 1;

function adjustIframe() {
    $(parent.document.getElementById("responsive-iframe")).css("height", $("html").css("height"));
}


$(window).load(function() {

    var hashValue = location.hash;
    hashValue = hashValue.replace(/^#/, '');
    if($('#'+hashValue).length) {
        var screenTop = $(document).scrollTop();
        var newScreenTop =  screenTop - 100;
        $('html,body').animate({scrollTop: newScreenTop}, 500);
    }

    if(typeof($.cookie('cookie-note')) == "undefined") {

        if (document.location.hostname == "france.fairtrade.he-hosting.de" || document.location.hostname == "www.maxhavelaarfrance.org") {
            var cookieItem = $('#cookie-note');
            $(cookieItem).fadeIn('fast');

            $(cookieItem).find('a.accept').click(function() {
                $.cookie('cookie-note','1', { expires: 365, path: '/' });
                $(cookieItem).slideUp('slow');
            });

        }
    }
});


$( document ).ready(function() {



    var wi = $(window).width();

    initResponisve();
    if (wi >= 768){ initTablitV(); }
    if (wi >= 980){ initTablitH(); }
    if (wi >= 1170){ initTablitDesktop(); }

    setTeaserHeight();
    baseURL = $('head base').attr('href');
    _language = $('html').attr('lang');
    $('body').addClass($("meta[name='color:scheme']").attr('content'));

    $(window).on('load resize', adjustIframe);
    
    
    if($('.logoutform').length && $('aside').length ) {
    	$('.logoutform').appendTo($('aside'));
    	$('.logoutform .fieldwrap label, .logoutform .fieldwrap span').css('display', 'none');
    }

    $('div.csc-default').addClass('clearfix');

    initOverlayAction();
    
    if($('.eventmap').length > 0) initEventMap();

    if($('#mainslider').length) {

        infinitySlider(
            infinitySliderId = 'mainslider',
            infinitySliderCommandsClass = 'iS-Commands',
            infinitySliderPreviousButtonClass = 'iS-Previous',
            infinitySliderNextButtonClass = 'iS-Next',
            infinitySliderDotsClass = 'iS-Dots',
            infinitySliderDotClass = 'iS-Dot',
            infinitySliderDotActiveClass = 'iS-Dotactive',
            infinitySliderPlayButtonClass ='iS-Play',
            infinitySliderPlayButtonActiveClass ='iS-Playactive',
            infinitySliderStopButtonClass ='iS-Stop',
            infinitySliderStopButtonActiveClass ='iS-Stopactive',
            infinitySliderLoopIndicator ='iS-Loopline',
            infinitySliderContentClass ='iS-Content',
            infinitySliderItemsClass = 'iS-Items',
            infinitySliderItemClass = 'iS-Item',
            infinitySliderAutoStartLoop = true,
            infinitySliderKeyboardNavigation = false
        );

        var mobileSlider = $('.mainslider-mobil');
        $(mobileSlider).find('.item-wrap[data-index="1"]').addClass('aktiv');
        $(mobileSlider).find('.dots > div[data-index="1"]').addClass('aktiv');

        $(mobileSlider).find('.dots > div').click(function() {
            var item_index = $(this).attr('data-index');
            clearInterval(_mobileInterval);
            switchMobilSlider(mobileSlider, item_index);
        })

        _momileIndexMax = $(mobileSlider).find('.item-wrap').length;
        _mobileInterval = setInterval(function(){ switchMobileControll(mobileSlider,0) }, 8000);

        $(mobileSlider).find('.content, .dots').swipe( {
            //Generic swipe handler for all directions
            swipe:function(event, direction, distance, duration, fingerCount, fingerData) {
                if(direction == 'left') {
                    clearInterval(_mobileInterval);
                    switchMobileControll(mobileSlider,0);
                }
                if(direction == 'right') {
                    clearInterval(_mobileInterval);
                    switchMobileControll(mobileSlider,1);
                }
            },
            //Default is 75px, set to 0 for demo so any distance triggers swipe
            threshold:0
        });

        if($('.fr-quotes-wrapper').length > 0) initQuotes();
    }




    if($('.fairtrade-finder').length) {
        var items = $('.fairtrade-finder .item');
        $(items).click(function() {
            if(!$(this).hasClass('open')) {
                $(items).removeClass('open');
                $(this).addClass('open');
            }
        });
    }

    var contentTrenner = $('.content-trenner');
    if($(contentTrenner).length) {
        if($('.startseite-banner').length) {
            var bgImage = $(contentTrenner).find('.startseite-banner').attr('data-bg');
            if(bgImage != "") {
                $('section.content-trenner').css('background-image', 'url(/'+bgImage+')');
            }
        }

        if($('.zitate-inner').length) {
            $('section.content-trenner').css('background', 'none');
        }


    }



    var nowTemp = new Date();
    var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
    $('.fieldwrap.datewrap').each(function() {
        var wrap = $(this);
        var input = $(wrap).find('input.standard');

        $(input).keypress(function(event) {
            event.preventDefault();
        });
        $(input).datepicker({
            appendToElement: $(wrap),
            format: 'dd.mm.yyyy',
            onRender: function(date) {
                return date.valueOf() < now.valueOf() ? 'disabled' : '';
            }
        }).on('changeDate', function(ev) {

        }).data('datepicker');

    });





    $('.bxSlider').each(function() {
        var elem = $(this);
        var slider = $(elem).bxSlider({
            easing: 'ease-out',
            pager: false,
            'prevText': '<span class="fairtrade-icon_pfeil_1_links"></span>',
            'nextText': '<span class="fairtrade-icon_pfeil_1_rechts"></span>',
            minSlides: $(elem).attr('data-minSlides') ? parseInt($(elem).attr('data-minSlides')) : 1,
            maxSlides: $(elem).attr('data-maxSlides') ? parseInt($(elem).attr('data-maxSlides')) : 1,
            slideWidth: $(elem).attr('data-slideWidth') ? parseInt($(elem).attr('data-slideWidth')) : 0,
            moveSlides: $(elem).attr('data-moveSlides') ? parseInt($(elem).attr('data-moveSlides')) : 1,
            slideMargin: $(elem).attr('data-slideMargin') ? parseInt($(elem).attr('data-slideMargin')) : 0,
            infiniteLoop: $(elem).attr('data-infiniteLoopFalse') ? false : true,
            hideControlOnEnd: $(elem).attr('data-hideControlOnEnd') ? true : false,
            onSlideNext: function(slideElement, oldIndex, newIndex) {
                // News Veranstaltungen Verteilerseite
                if($(slideElement).parents('.slider-veranstaltungen').length) {
                    slideOnVeranstaltung(slideElement, oldIndex, newIndex);
                }
            },
            onSlidePrev: function(slideElement, oldIndex, newIndex) {
                // News Veranstaltungen Verteilerseite
                if($(slideElement).parents('.slider-veranstaltungen').length) {
                    slideOnVeranstaltung(slideElement, oldIndex, newIndex);
                }
            },
            onSliderLoad: function() {

            }
        });
        _bxSliders.push(slider);
    });


    $('a.menu-opener').click(function() {
        var myNav = $(this).parent('nav');

        if($(myNav).hasClass('mobile-menu-open')) {
            $(myNav).removeClass('mobile-menu-open');
            $('body').removeClass('mobile-menu-open');
            $('.mobile-meta-nav').hide();
            $('div.blacked').remove();
        } else {
            $(myNav).addClass('mobile-menu-open');
            $('body').addClass('mobile-menu-open');
            $('<div/>', { class:'blacked' }).appendTo('body');
            $('.mobile-meta-nav').fadeIn('slow');
        }
    });


    //$('select').chosen({ width: '100%', disable_search_threshold: 15, no_results_text: "Kein Ergebnis" })
    //$('select.chosen-container-single-search, select.powermail_select').chosen({ width: '100%', disable_search_threshold: 10, no_results_text: "Kein Ergebnis" })

    $('input.checkbox').iCheck({
        checkboxClass: 'icheckbox_flat-blue',
        radioClass: 'iradio_flat-blue'
    });


    $('a.lightbox').magnificPopup({
        type: 'image',
        mainClass: 'mfp-zoom-in',
        tLoading: '<div class="spinner"><div class="ball"></div></div>',
        overflowY: 'scroll',
        removalDelay: 500,
        callbacks: {
            imageLoadComplete: function() {
                var self = this;
                setTimeout(function() {
                    self.wrap.addClass('mfp-image-loaded');
                }, 16);
            },
            close: function() {
                this.wrap.removeClass('mfp-image-loaded');
            },
            buildControls: function() {
                if($(this.ev).hasClass('gallery')) {
                    this.contentContainer.append(this.arrowLeft.add(this.arrowRight));
                }
            }
        },
        image: {
            titleSrc: function(item) {
                var description = item.el.attr('data-description');
                if(typeof description !== "undefined") {
                    if(description == "") return '';
                    return '<p>' + item.el.attr('data-description') + '</p>';
                }else {
                    return '';
                }

            }
        },
        gallery: {
            enabled: true,
            preload: [0,2],
            navigateByImgClick: true,
            arrowMarkup: '<button title="%title%" type="button" class="mfp-arrow mfp-arrow-%dir%"></button>', // markup of an arrow button
            tPrev: 'Previous (Left arrow key)', // title for left button
            tNext: 'Next (Right arrow key)', // title for right button
            tCounter: '<span class="mfp-counter">%curr% of %total%</span>' // markup of counter
        },
        closeBtnInside: false,
        closeOnContentClick: true,
        midClick: true
    });

    $(document).on("click","nav.mobile-menu-open ul li a",function(event) {
        var cur_li = $(event.currentTarget).parent('li');
        if(!$(cur_li).hasClass('sub')) return true;

        if(!$(cur_li).hasClass('mobile-open')) {
            // Check others
            event.preventDefault();
            var parentLi = $(cur_li).parents('li.ebene-1');
            $('nav.mobile-menu-open ul.first > li.mobile-open').not(parentLi).each(function(){
                $(this).removeClass('mobile-open');
                $(this).children('ul').slideUp();
            });

            $(cur_li).addClass('mobile-open');
            $(cur_li).children('ul').slideDown();
        }

    });



    
    $('iframe').each(function(){
        if($(this).parent('.embed-container').length == 0 && $(this).parent('.grwf2-wrapper').length == 0) {
            $(this).wrap('<div class="embed-container"></div>');
        }
    });
    
    
    var navMenu = $('ul.nav-language');
    if($(navMenu).length) {
        $.each(navMenu, function( index, value ) {
            var navMenuCurrent = $(value).find('li.current');
            $(value).prepend(navMenuCurrent);

            $(value).fadeTo(400,1);

            $(navMenuCurrent).click(function(event) {
                event.preventDefault();
                if($(value).hasClass('open')) {
                    $('ul.nav-language').removeClass('open');
                    $('ul.nav-language li').not('.current').css('display','none');
                }else {
                    $('ul.nav-language').addClass('open');
                    $('ul.nav-language li').css('display','block');
                }
            });

        });


    }

    bootbox.setLocale('fr');
    $(document).on("click","a.download-file",function(event) {
        event.preventDefault();
        var link = $(event.currentTarget);
        bootbox.confirm({
            message: "Les photographies sont libres de droit dans le cadre d'articles de presse uniquement. Pour les HD, veuillez contacter le service presse. Nous vous remercions de nous indiquer leur utilisation.",
            buttons: {
                confirm: {
                    label: 'Accepter',
                },
                cancel: {
                    label: 'Abandonner',
                }
            },
            callback: function(result) {
                if (result === true) {
                    window.location = $(link).attr('href');
                }
            }
        });
    });


    initNews();
    checkInitAccordeonTabs();




    $("form.code-check-form").submit(function(e) {
        if(_codeCheckForm) {
            e.preventDefault();
            var form = $(e.currentTarget);
            var finput = $(form).find('input.search-sword');
            if($(finput).val() == "") {
                $(finput).val($(finput).attr('data-default'));
            }
            _codeCheckForm = 0;
            $(form).trigger('submit');
        }
    });








});


$(window).resize(function() {

    var wi = $(window).width();

    initResponisve();
    if (wi >= 768){ initTablitV(); }
    if (wi >= 980){ initTablitH(); }
    if (wi >= 1170){ initTablitDesktop(); }

    setTeaserHeight();

    // DCE Produzenten
    position_top_content($('.element-top-active'));

    if($('.newsletter-goto').length) initNewsletteranmeldung();
    if($('#NewsletterForm').length) initNewsletterForm();
    if($('.tooltip').length) initToolTips();
});


function  initToolTips() {
	
	$('.tooltip span.fairtrade-icon_info').mouseenter(function(){
		$(this).parent().find('.tooltip-text').fadeIn();
	});
	$('.tooltip span.fairtrade-icon_info').mouseleave(function(){
		$(this).parent().find('.tooltip-text').fadeOut();
	});
}





function initResponisve() {
    __device = 1;
    //$('.fairtrade-teaser').css('height', 'auto');
}


function initTablitV() {

    __device = 2;
    calcMainMenuHeight();



}

function initTablitH() {

    __device = 3;
    calcMainMenuHeight();


}

function initTablitDesktop() {

    __device = 4;


    $(window).scroll(function() {
        var x = $(this).scrollTop();

        // Sticky Menu
        if(x >= 100) {
            if(__device > 1) $('body,header').addClass('transform-to-sticky');
        }else {
            $('body,header').removeClass('transform-to-sticky');
        }

    });



    calcMainMenuHeight();

   //$('select').chosen({ width: '100%', disable_search_threshold: 15, no_results_text: "Kein Ergebnis" })
}








function calcMainMenuHeight() {
    var menus = $('div.main-nav nav ul.first > li.sub');
    $.each(menus, function( index, value ) {
        var firstMenuHeight = $(value).find('ul.second').outerHeight();
        var secondMenu = $(value).find('ul.second');
        var secondMenus = $(value).find('ul.second > li.sub');
        showMenuForHeight(secondMenu);
        $.each(secondMenus, function( index2, value2 ) {
            var thirdMenu = $(value2).find('ul.third');
            showMenuForHeight(thirdMenu);
            var secondMenuHeight = $(thirdMenu).outerHeight();
            $(thirdMenu).removeAttr('style');

            // Check and set new height
            if(secondMenuHeight >= firstMenuHeight) {
                $(secondMenu).css('height', secondMenuHeight);
            }else {
                $(thirdMenu).css('height', firstMenuHeight);
            }
        });
        $(secondMenu).removeAttr('style');
    });

}

function showMenuForHeight(elm) { $(elm).css({'opacity':'0','display':'block'}); }


var row_height = [];
var row_cheight = [];
function setTeaserHeight() {


    $('.row').each(function(i,e) {

        $(this).find('.fairtrade-teaser').removeAttr( 'style' );
        $(this).find('.fairtrade-teaser').find('.content').removeAttr( 'style' );

        if($(this).find('.row').length == 0 && $(this).find('.fairtrade-teaser').length) {
            row_height[i] = 0;
            row_cheight[i] = 0;

            $(this).find('.fairtrade-teaser').each(function(){
                if($(this).find('.content-mobile') && __device == 1) {
                    $(this).find('.content-mobile').css('height', 'auto');
                    $(this).find('.content-background').css('height', '50%');
                    $(this).find('.content-ovelay').css('height', '50%');
                    newheight = $(this).find('.content-ovelay').height() + $(this).height();
                    if(newheight > row_height[i]) {
                        row_height[i] = newheight;
                    }
                } else if($(this).height() >= row_height[i] && $(this).find('.image-wrap').hasClass('normal')) {
                    row_height[i] = $(this).height();
                    if($(this).find('.image-wrap').hasClass('normal')) {
                        if((row_height[i] - $(this).find('.image-wrap').height() + 4) > 50) {
                            if(row_height[i] - $(this).find('.image-wrap').height() + 4 > row_cheight[i]) {
                                row_cheight[i] = row_height[i] - $(this).find('.image-wrap').height() + 4;
                            }
                        }
                    }
                }
                if($(this).find('.content-mobile') && __device > 1)  {
                    $(this).find('.content-background').css('height', '100%');
                    $(this).find('.content-ovelay').css('height', '100%');
                }

                if($(this).find('.image-wrap').height() == 0) {
                    if(row_height[i] - row_cheight[i] < 50 ) {
                        $(this).find('.image-wrap').css('height', 2);
                        row_height[i] += 2;
                    }else $(this).find('.image-wrap').css('height', row_height[i] - row_cheight[i]);
                    $(this).find('.image-wrap').css('background', '#f0f0f0');
                }

            });

            if( __device > 1) {
                if( $(this).find('.fairtrade-teaser').find('.image-wrap').css('height') < 20) {
                    $(this).find('.fairtrade-teaser').css('height', row_height[i]);
                }
                $(this).find('.fairtrade-teaser').find('.content').css('height', row_cheight[i]);

                if( $(this).find('.fairtrade-teaser').find('.content-background').length) {
                    $(this).find('.fairtrade-teaser').find('.content-background').css('height', row_height[i]);
                    $(this).find('.fairtrade-teaser').find('.content-ovelay').css('height', row_height[i]);
                }

            }else {
                if(row_cheight[i] == 0) row_cheight[i] = 'auto';
                $(this).find('.fairtrade-teaser').css('height', row_height[i]+22);
                $(this).find('.fairtrade-teaser').find('.content').css('height', row_cheight[i]);
            }

        }
    });
}






function initNews() {

    if($('.newsroom-veranstaltungen').length) {
        var mySlider = '';
        $.each(_bxSliders, function(){
            var item = $(this)[0];
            if($(item).hasClass('slider-veranstaltungen')) {
                mySlider = this;
            }
        });


        $('.month-top a').click(function() {
            if($(this).hasClass('aktiv') && !$(this).hasClass('current')) {
                var newMonth = $(this).attr('data-month');
                var firstSlide = $('.newsroom-veranstaltungen .items-wrap .item[data-month="'+newMonth+'"]').first();
                var slideIndex = $('.newsroom-veranstaltungen .items-wrap .item').index(firstSlide);
                $('.newsroom-veranstaltungen .month-top a.month').removeClass('current');
                $(this).addClass('current');
                mySlider.goToSlide(slideIndex);
            }
        });

        $('.month-top a.aktiv').first().trigger('click');

    }

}

function slideOnVeranstaltung(slideElement, oldIndex, newIndex) {
    var dataMonth = $(slideElement).attr('data-month');
    $('.newsroom-veranstaltungen .month-top a.month').removeClass('current');
    $('.newsroom-veranstaltungen .month-top a.month[data-month="'+dataMonth+'"]').addClass('current');
}


function checkInitAccordeonTabs() {


    $('.t3ddy-tabContainer').each(function(){
        var $tabContainer = $(this);
        var $tabs = $tabContainer.find('>ul > li');

        var maxTabs = 12;
        var cols = Math.floor(maxTabs/$tabs.length);
        var colClass= 'col-sm-'+cols;



        $tabContainer.find('.t3ddy-tabContainer-tabList').addClass('row').addClass('clearfix');
        $tabContainer.find('.t3ddy-tabContainer-tabList').wrap('<div class="tabList-outer"></div>');

        $tabs.each(function(){
            var $tab = $(this);
            $tab.addClass(colClass);
            $tab.find('> .t3ddy-item').appendTo($tabContainer);
        });

        /*$tabs.find('a').each(function(){
            var $link = $(this);
            var section = $link.attr('href').replace(/.*(#.*)/gi, '$1');
            var newLink = location.pathname + location.search + section;
            $link.attr('href', newLink);
        });*/

        $tabContainer.tabs();
    });

    $('.t3ddy-accordion').each(function(){
        var $accordionContainer = $(this);
        $(this).find('h5.t3ddy-accordion-header').next('a').remove();
        $(this).find('h5.t3ddy-accordion-header').first().addClass('first');
        $(this).find('h5.t3ddy-accordion-header').last().addClass('last');
        $accordionContainer.accordion({
            heightStyle: 'content',
            navigation: true,
            collapsible: true,
            active: false
        });

        $(this).find('h5.t3ddy-accordion-header .ui-accordion-header-icon').addClass('fairtrade-icon_plus');
    });



}

function initNewsletteranmeldung() {
	
	if($('.newsletter-email').length) $('.newsletter-email').css('color','#666');
	
	$('.newsletter-goto button').click(function(event){
		event.preventDefault();
		var pregmatch = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		var anmeldung = new Array();
		anmeldung['mail'] = $('.newsletter-email').val();
		anmeldung['source'] = escape(location.href);
		
		if(pregmatch.test(anmeldung['mail'])) {
			
			$('.newsletter-email').css('background-color','#474747');
			$('.newsletter-email').css('color','#ccc');
			
		/*
			$.ajax({
	            url: '/?eID=cleverreach&mail='+anmeldung['mail']+'&source='+anmeldung['source'],
	            type: "POST",
	            data: anmeldung,
	            cache: false,
	            //dataType: "json",
	            //processData: false, // Dont process the files
	            contentType: false, // Set content type to false as jQuery will tell the server its a query string request
	            success: function(data, textStatus, jqXHR) {
	                if(typeof data.error === "undefined") {
	                	$('.newsletter-email').attr('placeholder','Anmeldung erfolgreich');
	                	$('.newsletter-email').val('');
	                }else{
	                	$('.newsletter-email').attr('placeholder','Anmeldung fehlgeschlagen');
	                	$('.newsletter-email').val('');
	                }
	            }, error: function(jqXHR, textStatus, errorThrown) {
	            	$('.newsletter-email').attr('placeholder','Anmeldung fehlgeschlagen');
	            	$('.newsletter-email').val('');
	            }
	        });   
	       
	       */
            top.location.href="http://"+location.host+"/liens-courts/recevoir-les-news/?newmail="+anmeldung['mail'];

		
		}else{
			$('.newsletter-email').css('background-color','#FFC2C2');
			$('.newsletter-email').css('color','#DE0033');
			$('.newsletter-email').css('border-radius','5px');
		}
	});
}

function initNewsletterForm() {
	$('.nlButtonForm').click(function(event){
		//event.preventDefault();
	});
}




var _mobileIndex = 0;
function switchMobileControll(mobileSlider, reverse) {
    if(reverse==1) {
        _mobileIndex -= 1;
        if(_mobileIndex < 1) _mobileIndex = _momileIndexMax;
    }else {
        _mobileIndex += 1;
        if(_mobileIndex > _momileIndexMax) _mobileIndex = 1;
    }


    switchMobilSlider(mobileSlider, _mobileIndex)
}

function switchMobilSlider(mobileSlider, item) {
	//console.log(item);
    $(mobileSlider).find('.item-wrap.aktiv').hide().removeClass('aktiv');
    $(mobileSlider).find('.dots > div.aktiv').removeClass('aktiv');
    $(mobileSlider).find('.item-wrap[data-index="'+item+'"]').show().addClass('aktiv');
    $(mobileSlider).find('.dots > div[data-index="'+item+'"]').addClass('aktiv');
}



var mapEvent;

function initEventMap() {
	$('#mapEvents').css('height','300px');
	$('#mapP').css('padding','10px');
	$('#mapP').css('background','#fff');
	$('#mapP').css('margin','0px 0px 20px 0px');
	//console.log('initmap');
    var image = {
        url: '/typo3conf/ext/igx_products/Resources/Public/Icons/pin_ft.png',
        // This marker is 20 pixels wide by 32 pixels high.
        size: new google.maps.Size(37, 59),
        // The origin for this image is (0, 0).
        origin: new google.maps.Point(0, 0),
        // The anchor for this image is the base of the flagpole at (0, 32).
        anchor: new google.maps.Point(18, 59)
    };

    var infowindow = null;
    infowindow = new google.maps.InfoWindow({
        content: "."
    });
    
    mapEvent = new google.maps.Map(document.getElementById('mapEvents'), {
        scrollwheel: false,
        center: {lat: parseFloat($('#mapP').attr('data-geolat')), lng: parseFloat($('#mapP').attr('data-geolan'))},
        zoom: 8
    });

    var markerHtml = "<div class='map-marker'><p>"+$('.location .row .col-sm-7 > p > b').html()+" <br /><a target='_blank' href='https://www.google.de/maps/dir//"+$('#mapP').attr('data-georaw')+"'>Routenplaung</a></p></div>";

    marker = new google.maps.Marker({
        position: new google.maps.LatLng(parseFloat($('#mapP').attr('data-geolat')), parseFloat($('#mapP').attr('data-geolan'))),
        map: mapEvent,
        icon: image,
        html:markerHtml
    });
    
    google.maps.event.addListener(marker, 'click', function () {
        infowindow.setContent(this.html);
        infowindow.open(mapEvent, this);
    });
}

function initOverlayAction() {
    var ovContainer = $('#overlayContainer');

    if($(ovContainer).length) {
        var pageUid = $(ovContainer).attr('data-uid');
        var currentHost = window.location.origin;
        var pageType = 89657337;

        $.ajax({
            url: currentHost,
            dataType:'html',
            data: {
                type: pageType,
                pageUid: pageUid
            },
            beforeSend: function() {

            },
            success: function(d) {
                // [T25094]
                d = d.replace(/<!--((?!-->).+)-->/gmi, '').trim();
                if(d != '') {
                    $(ovContainer).html(d);
                    var newOverlay = $('#fairtrade-overlay');

                    var magnificObject = {
                        items: {
                            src: $(ovContainer).html(),
                            type: 'inline'
                        },

                        mainClass: 'mfp-zoom-in mfp-overlay',
                        tLoading: '<div class="spinner"><div class="ball"></div></div>',
                        overflowY: 'scroll',
                        closeOnBgClick: true,
                        removalDelay: 500,
                        closeBtnInside:true,
                        closeMarkup: '<button title="%title%" type="button" class="mfp-close"><span class="fairtrade-icon_x"></span></button>',
                        callbacks: {
                            beforeOpen: function() {

                            },
                            open: function() {
                                // set cookie
                                $.ajax({ url:currentHost, type: 'POST', dataType:'text', data: { type: pageType, fairtrade_overlay_c: $(newOverlay).attr('data-uid') }});
                                if($('.store_voting').length) initStorevoting();
                            },
                            close: function() {

                            }
                        }
                    };

                    var timeout = parseInt($(newOverlay).attr('data-timout'));
                    if(isNaN(timeout)) {
                        $.magnificPopup.open(magnificObject);
                        tarteaucitron.services.youtube.fallback();
                        lazyload();
                    }else {
                        setTimeout(function(){ $.magnificPopup.open(magnificObject); tarteaucitron.services.youtube.fallback(); lazyload(); }, timeout*1000);
                        
                    }

                    $(document).on("click",".mfp-overlay button.mfp-close",function(event) {
                        $.magnificPopup.close(magnificObject);
                    });





                }
            },
            error: function(d) {

            }
        });

    }
}


function initQuotes() {
    const quoteWrapper = $('.fr-quotes-wrapper');
    const active_class = 'active';
    if($(quoteWrapper).length) {

        // Active First Item und set Wrapper Height
        $(quoteWrapper).find('[data-item="0"]').addClass(active_class);
        const first_height = $(quoteWrapper).find('.quote-item[data-item="0"]').outerHeight(true);
        $(quoteWrapper).find('.quotes').height(first_height);

        function changeActiveQuoteHeight() {
            const newActiveHeight = $(quoteWrapper).find('.quote-item.'+active_class).outerHeight(true);
            $(quoteWrapper).find('.quotes').height(newActiveHeight);
        }

        // Click Event
        $(quoteWrapper).find('.nav-item').click(function () {
            if(!$(this).hasClass('active')) {
                // remove active
                $(quoteWrapper).find('.c-item').removeClass(active_class);

                // add new active
                const newActiveIndex = $(this).attr('data-item');
                $(quoteWrapper).find('.c-item[data-item="'+newActiveIndex+'"]').addClass(active_class);
                // new height
                changeActiveQuoteHeight();
            }
        });


        $(window).resize(function() {
            changeActiveQuoteHeight();
        });

    }
}