/* Minification failed. Returning unminified contents.
(1265,58-59): run-time error JS1195: Expected expression: >
(1276,14-15): run-time error JS1195: Expected expression: )
(1277,9-10): run-time error JS1002: Syntax error: }
(1283,47-48): run-time error JS1195: Expected expression: >
(1283,73-74): run-time error JS1004: Expected ';': )
(1285,39-40): run-time error JS1004: Expected ';': {
(1318,47-48): run-time error JS1195: Expected expression: )
(1318,50-51): run-time error JS1195: Expected expression: >
(1325,14-15): run-time error JS1195: Expected expression: )
(1339,45-46): run-time error JS1195: Expected expression: >
(1340,38-39): run-time error JS1195: Expected expression: >
(1344,14-15): run-time error JS1195: Expected expression: )
(1356,44-45): run-time error JS1195: Expected expression: >
(1358,10-11): run-time error JS1195: Expected expression: )
(1363,1-2): run-time error JS1002: Syntax error: }
(1363,25-34): run-time error JS1197: Too many errors. The file might not be a JavaScript file: undefined
 */
/// <reference path="_references.js" />


; (function ($, window, document, undefined) {
    'use strict';

    var lang = navigator.languages ? navigator.languages : navigator.language;
    moment.locale(lang);

    if (!Modernizr.inputtypes.date) {
        var $dateInputs = $("input[type=date]");

        $dateInputs.each(function () {
            var $this = $(this);

            $this.attr("type", "text");
            var picker = new Pikaday({ field: $this[0], format: moment().locale(lang).localeData()._longDateFormat['L'] });
        });
    }

    $(document).on("click", "[data-play-youtube-video]", function (e) {
        e.preventDefault();

        var videoId = $(this).data("play-youtube-video");

        $.magnificPopup.open({
            items: {
                src: '<div class="c-video-player"><div class="c-video-player__content"><a href="#" class="c-video-player__close">Close</a><div id="c-video-player-frame"></div></div></div>',
                type: 'inline'
            }
        });

        $(".c-video-player__close").on("click", function (e) {
            e.preventDefault();
            $.magnificPopup.close();
        });

        var videoPlayer = new YT.Player('c-video-player-frame', {
            height: '576',
            width: '1024',
            videoId: videoId,
            playerVars: {
                fs: 0,
                controls: 0,
                autoplay: 1,
                enablejsapi: 1,
                modestbranding: 1,
                origin: 'www.gwp.org',
                rel: 0,
                showinfo: 0
            }
        });
    });
    
    if ($('.c-slideshow .swiper-slide').length > 1) {
        var autoplay = $('.c-slideshow .swiper-container').data('swiper-autoplay');
        
        if (autoplay === undefined || autoplay <= 0)
            autoplay = 2000;
        
        var heroSwiper = new Swiper('.c-slideshow > .swiper-container', {
            direction: 'horizontal',
            loop: true,
            speed: 500,
            autoplay: autoplay,
            spaceBetween: 20,
            paginationClickable: true,
            pagination: '.c-slideshow .swiper-pagination'
        })
    }

    var textBlockSwiper = new Swiper('.text-block-slideshow > .swiper-container', {
        direction: 'horizontal',
        loop: false,
        speed: 500,
        spaceBetween: 20,
        pagination: '.text-block-slideshow .swiper-pagination',
        paginationClickable: true,
        paginationBulletRender: function (swiper, index, className) {

            var numberOfBullets = swiper.params.loop ? Math.ceil((swiper.slides.length - swiper.loopedSlides * 2) / swiper.params.slidesPerGroup) : swiper.snapGrid.length;

            if (numberOfBullets < 2)
                return '';

            return '<span class="' + className + '"></span>';
        },
        slidesPerView: 3,
        breakpoints: {
            480: {
                slidesPerView: 1
            },
            939: {
                slidesPerView: 2,
                spaceBetween: 30
            }
        }
    })

    $(document).on('click', '.c-link-list--expandable + a', function (e) {
        e.preventDefault();

        var $this = $(this);
        var $linkList = $this.prev();

        $linkList.toggleClass('is-expanded');
        $this.hide();
    })

    $('#actions-filter-form select')
        .on("change", function () {
            $('#actions-filter-form').submit();
        });

    if (window.history.length == 0)
        $('[history-button]').hide()

})(jQuery, window, document);;
/// <reference path="_references.js" />

; (function ($, window, document, undefined) {
    'use strict';

    $(function () {
        var $nav = $('nav');
        var $menuButtons = $('[data-toggle=menu]')
        var $linkItems = $nav.find('.c-navigation__link');
        var $linkWrappers = $nav.find('.c-navigation__item');

        $nav.on('click', '.c-navigation__link:not([data-disable-menu-toggle])', function (e) {
            e.preventDefault();

            var $linkItem = $(this);
            var $linkWrapper = $linkItem.parent('.c-navigation__item');

            var isActive = $linkItem.hasClass("is-active");

            $linkItems.removeClass('is-active');
            $linkWrappers.removeClass('is-active');

            if (!isActive) {
                $linkItem.addClass('is-active');
                $linkWrapper.addClass('is-active');
            }
        });

        $(document).on('click', '[data-toggle=menu]', function (e) {
            e.preventDefault();

            var $this = $(this);
            var isActive = $nav.hasClass("is-active");

            $menuButtons.removeClass("is-active");

            if (isActive) {
                $nav.removeClass("is-active");
            }
            else {
                $nav.addClass("is-active");
                $this.addClass("is-active");
            }


        })
        

        $(document).on("mouseup", function (event) {
            if (!$nav.is(event.target) && $nav.has(event.target).length === 0) {
                $linkItems.removeClass("is-active");
                $linkWrappers.removeClass("is-active");
            }
        });



        //side navigation mobile
        var nav = '[data-side-navigation]'
        var navToggler = '[data-side-navigation-toggler]';

        $(document).on('click', navToggler, function () {
            $(this).toggleClass('open')
            $(this).next(nav).toggleClass('active');
        })

        $(document).on("mouseup", function (event) {
            var $nav = $(nav);
            var $navToggler = $(navToggler);

            // if the target of the click isn't the container nor a descendant of the container
            if (!$nav.is(event.target) && $nav.has(event.target).length === 0 && !$navToggler.is(event.target) && $navToggler.has(event.target).length === 0) {
                $nav.removeClass('active');
                $navToggler.removeClass('open');
            }
        }); 
    })

})(jQuery, window, document);;
/// <reference path="_references.js" />

; (function ($, window, document, undefined) {
    'use strict';

    $(function () {
        
    })

})(jQuery, window, document);;
var GWP = new function () { };
var countryItemList = [];

$(window).on('load', function () {
    if ($('#mapplic').length > 0) {
        GWP.mapplic.Init();
    }
});

GWP.mapplic = new function () {
    var instance = {
        Init: function () {
            if ($('#c-interactivemap-holder').length > 0) {
                GWP.mapplic.Interactive();
            }
            else if ($('#c-sdg-interactivemap-holder').length > 0) {
                GWP.mapplic.Sdg();
            }
            else if ($('#c-unicefmap-holder').length > 0) {
                GWP.mapplic.Unicef();
            }
            else if ($('#c-regionmap-holder').length > 0) {
                GWP.mapplic.RegionMap();
            }
            GWP.mapplic.Events();
            GWP.lightbox.Init();
            GWP.menu.Init();
        },
        Interactive: function () {
            var windowHeight = (typeof window.outerHeight != 'undefined') ? Math.min(window.outerHeight, $(window).height()) : $(window).height();
            var map;
            var self;
            var filterForm = {};
            var developer = false;
            $('form[name="filterNavigationForm"]').serializeArray().map(function (x) { filterForm[x.name] = x.value; });
            $.ajax({
                url: "/en/interactivemap/GetData",
                cache: false,
                dataType: "json",
                data: filterForm,
                success: function (result) {

                    developer = result.developer;
                    if (developer) {
                        console.log(result);
                    }
                    var countryString = "[";

                    $.each(result.countries, function (key, obj) {
                        if (obj.CountryCode == null) {
                            return true;
                        }

                        var shortCode = JSON.stringify(obj.CountryCode).toLowerCase();
                        var xyOrLangLat = "\"lat\": \"" + obj.Latitude + "\",\"lng\": \"" + obj.Longitude + "\"";
                        if (obj.Ycord && obj.Xcord) {
                            xyOrLangLat = "\"y\": \"" + obj.Ycord + "\",\"x\": \"" + obj.Xcord + "\"";
                        }

                        if (obj.MapItems.length > 0) {
                            countryItemList[obj.Name] = [];
                            var description = "<ul>";

                            $.each(obj.MapItems, function (k, item) {
                                var mapItemType = $.grep(result.types, function (e) { return e.Name === GWP.mapplic.NameOfFilterID(result.types, item.IWRM); });
                                var iconClass = "";
                                var themeNames = "";
                                var IWRMNames = "";
                                var longtext = item.LongText;
                                var imageUrl = item.ImageUrl.length > 0 ? (item.ImageUrl + "?width=588&height=285&mode=crop&scale=both&anchor=topcenter") : "";

                              
                                if (mapItemType.length > 0) {
                                    iconClass = mapItemType[0].IconClass;
                                }

                                if (item.InteractiveMapItemTheme) {
                                    themeNames = GWP.mapplic.NameOfFilterID(result.themes, item.InteractiveMapItemTheme, true);
                                }
                                if (item.IWRM) {
                                    IWRMNames = GWP.mapplic.NameOfFilterID(result.types, item.IWRM, true);
                                }

                                var CountryList = {
                                    "guid": item.Guid,
                                    "name": item.ShortText,
                                    "year": item.Year,
                                    "ingress": obj.Name + (item.Year > 0 ? " - " + item.Year : null),
                                    "longtext": longtext,
                                    "image": imageUrl,
                                    "CaseStudy": item.CaseStudy,
                                    "ImpactStory": item.ImpactStory,
                                    "theme": item.InteractiveMapItemTheme,
                                    "themeNames": themeNames,
                                    "IWRM": item.IWRM,
                                    "IWRMNames": IWRMNames
                                };
                                countryItemList[obj.Name].push(CountryList);
                                description += "<li>" +
                                    "<a href='#' onClick='GWP.lightbox.Browse($(this));' data-country='" + obj.Name + "' data-guid=" + item.Guid + ">" +
                                    "<span class='mapplic-type-icon'><i class='" + iconClass + "' aria-hidden='true'></i></span><span class='mapplic-type-icon-text'>" + (item.Year != 0 ? item.Year + " - " : "") + item.Name + "</span></a></li>";
                            });
                            description += "</ul>";
                            countryString += "{ \"id\": \"" + obj.Name + "\", \"title\": \"" + obj.Name + "\", \"label\": \"" + obj.MapItems.length + "\", \"description\" : \"" + description + "\", \"pin\": \"pin-label " + obj.PinColor + "\"," + xyOrLangLat + "},";
                        }
                        countryString += "{\"id\": " + shortCode + ", \"action\":\"none\", \"title\": \"" + obj.Name + "\", \"pin\": \"hidden\",\"fill\": \"" + obj.Color + "\"," + xyOrLangLat + "}";


                        if (result.countries.length != key + 1) {
                            countryString += ",";
                        }
                        else {
                            countryString += "]";
                        }


                    });
                    var data = {
                        "mapwidth": "1200",
                        "mapheight": "760",
                        "bottomLat": "-59",
                        "leftLng": "-190",
                        "topLat": "59",
                        "rightLng": "190",
                        "categories": [
                        ],
                        "levels": [
                            {
                                "id": "World",
                                "title": "World",
                                "map": "/Scripts/mapplic/maps/world.svg",
                                "locations": JSON.parse(countryString)
                            }
                        ]
                    };

                    /** COUNTRIES FILTER **/
                    $("#countryActive").html(result.activeFilter.country != "" ? result.activeFilter.country : "country");

                    $("#countriesFilter").html("");
                    if (result.activeFilter.region != "") {
                        $("#countriesFilter").append("<li data-filter='country'>country</li>")
                        $.each(result.countries, function (key, value) {
                            if (value.CountryCode.indexOf("riverbasin") == -1) {
                                var activeClass = result.activeFilter.country == value.Name ? "c-interactivemap-navigation__submenu--active" : "";
                                $("#countriesFilter").append("<li class='" + activeClass + "' data-filter='country'>" + value.Name + "</li>")
                            }
                        });
                    }
                    else {
                        $("#countriesFilter").append("<li>Select a region</li>")
                    }


                    /** THEMES FILTER **/
                    var themes = result.activeFilter.theme.split(";");
                    if (themes.length == 1 && themes == "") {
                        $("#themeActive").html("Theme");
                    }
                    else {
                        $("#themeActive").html("Theme (" + themes.length + ")");
                    }


                    $("#themesFilter").html("");
                    $("#themesFilter").append("<li data-filter='theme'>theme</li>")
                    $.each(result.themes, function (key, value) {
                        var activeClass = false;

                        for (i = 0; i < themes.length; i++) {
                            if (themes[i] == value.Name) {
                                activeClass = true;
                            }
                        }
                        var icon = value.IconClass;
                        var file = icon.substr(icon.indexOf('.'), icon.length);
                        switch (file) {
                            case '.svg':
                                icon = GWP.mapplic.GetSvg('/Images/' + icon, 14, 14, '#fff');
                                break;
                            default:
                                icon = "";
                                break;
                        }


                        $("#themesFilter").append("<li class='" + (activeClass ? "c-interactivemap-navigation__submenu--active" : "") + "' data-filter='theme'><input type='checkbox' class='themebox' id='themebox" + value.Name + "' value='" + value.Name + "' " + (activeClass ? "checked" : "") + "><label for='themebox" + value.Name + "'>" + icon + value.Name + "</label></li>")
                        //" + (activeClass ? "c-interactivemap-navigation__submenu--active" : "") + "
                    });

                    /** YEARS FILTER **/
                    $("#yearActive").html(result.activeFilter.year != "" ? result.activeFilter.year : "year");

                    $("#yearsFilter").html("");
                    $("#yearsFilter").append("<li data-filter='year'>year</li>")
                    $.each(result.years, function (key, value) {
                        var activeClass = result.activeFilter.year == value ? "c-interactivemap-navigation__submenu--active" : "";
                        $("#yearsFilter").append("<li class='" + activeClass + "' data-filter='year'>" + value + "</li>")
                    });

                    /** REGION FILTER **/
                    $("#regionActive").html(result.activeFilter.region != "" ? result.activeFilter.region : "region");

                    $("#regionsFilter").html("");
                    $("#regionsFilter").append("<li data-filter='region'>region</li>")
                    $.each(result.regions, function (key, value) {
                        var activeClass = result.activeFilter.region == value ? "c-interactivemap-navigation__submenu--active" : "";
                        $("#regionsFilter").append("<li class='" + activeClass + "' data-filter='region'>" + value + "</li>")
                    });

                    /** IWRM FILTER **/
                    $("#IWRMActive").html(result.activeFilter.iwrm != "" ? result.activeFilter.iwrm : "IWRM");

                    $("#IWRMFilter").html("");
                    $("#IWRMFilter").append("<li data-filter='IWRM'>IWRM Components</li>")

                    $.each(result.types, function (key, value) {
                        var activeClass = result.activeFilter.iwrm == value.Name ? "c-interactivemap-navigation__submenu--active" : "";
                        $("#IWRMFilter").append("<li class='" + activeClass + "' data-filter='IWRM'><i class='" + value.IconClass + "' aria-hidden='true' style='margin-right: 4px;'></i>" + value.Name + "</li>")
                    });

                    /** STORY FILTER **/
                    $("#storyActive").html(result.activeFilter.story != "" ? result.activeFilter.story : "Story");

                    $("#storiesFilter").html("");
                    $("#storiesFilter").append("<li data-filter='story'>Story</li>")

                    $.each(result.stories, function (key, value) {
                        var activeClass = result.activeFilter.story == value.Name ? "c-interactivemap-navigation__submenu--active" : "";
                        $("#storiesFilter").append("<li class='" + activeClass + "' data-filter='story'><i class='" + value.IconClass + "' aria-hidden='true' style='margin-right: 4px;'></i>" + value.Name + "</li>")
                    });


                    map = $('#mapplic').mapplic({
                        source: data,
                        height: Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
                        markers: true,
                        sidebar: false,
                        minimap: false,
                        fullscreen: false,
                        developer: developer,
                        lightbox: true,
                        zoombuttons: false,
                        clearbutton: false,
                        maxscale: 4
                    });

                    self = map.data('mapplic');
                    // Location opened
                    map.on('locationopened', function (e, location) {
                        $("#locationFilterValue").val(location.title);
                    });


                    if (result.activeFilter.country != "") {
                        self.showLocation(result.activeFilter.country, 1);
                    }
                    else if (result.activeFilter.location != "") {
                        self.showLocation(result.activeFilter.location, 1);
                    }

                }
            });


        },
        Sdg: function () {
            var windowHeight = (typeof window.outerHeight != 'undefined') ? Math.min(window.outerHeight, $(window).height()) : $(window).height();
            var map;
            var self;
            var filterForm = {};
            var developer = false;
            var url = $('#c-sdg-interactivemap-holder').data("url");

            $('form[name="filterNavigationForm"]').serializeArray().map(function (x) { filterForm[x.name] = x.value; });

            $.ajax({
                url: url + "GetData",
                cache: false,
                dataType: "json",
                data: filterForm,
                success: function (result) {

                    developer = result.developer;
                    if (developer) {
                        console.log(result);
                    }
                    var countryString = "[";

                    $.each(result.countries, function (key, obj) {
                        if (obj.CountryCode == null) {
                            return true;
                        }

                        var shortCode = JSON.stringify(obj.CountryCode).toLowerCase();
                        var xyOrLangLat = "\"lat\": \"" + obj.Latitude + "\",\"lng\": \"" + obj.Longitude + "\"";
                        if (obj.Ycord && obj.Xcord) {
                            xyOrLangLat = "\"y\": \"" + obj.Ycord + "\",\"x\": \"" + obj.Xcord + "\"";
                        }

                        if (obj.MapItemGroups.length > 0) {
                            countryItemList[obj.Name] = [];
                            var description = "";

                            $.each(obj.MapItemGroups, function (g, itemGroup) {

                                var groupName = itemGroup.GroupName;
                                var groupItems = itemGroup.Items;

                                description += "<h2>" + groupName + "</h2><ul>";

                                $.each(groupItems, function (k, item) {
                                    var longtext = "";

                                    if (item.LongText != null) {
                                        longtext = item.LongText.Fragments[0].InternalFormat
                                    }

                                    var aggregatedName = item.StageText + " in " + obj.Name + " in " + item.Year + " [" + item.ProgressText + "]";
                                    var imageUrl = item.ImageUrl.length > 0 ? (item.ImageUrl + "?width=588&height=285&mode=crop&scale=both&anchor=topcenter") : "";

                                    var mapItem = {
                                        "guid": item.Guid,
                                        "name": aggregatedName,
                                        "year": item.Year,
                                        "ingress": "",
                                        "longtext": longtext,
                                        "documenturl": item.DocumentUrl,
                                        "documenttext": item.DocumentText,
                                        "image": imageUrl
                                    };

                                    countryItemList[obj.Name].push(mapItem);
                                    description += "<li>" +
                                        "<a href='#' onClick='GWP.lightbox.Browse($(this));' data-country='" + obj.Name + "' data-guid=" + item.Guid + ">" +
                                        "<span class='mapplic-type-icon-text'>" + (item.Year != 0 ? item.Year + " [" + item.ProgressText + "] - " : "") + item.Name + "</span></a></li>";
                                });
                                description += "</ul>";
                            });

                            countryString += "{ \"id\": \"" + obj.Name + "\", \"title\": \"" + obj.Name + "\", \"description\" : \"" + description + "\", \"pin\": \"pin-label sdg\"," + xyOrLangLat + "},";
                        }

                        countryString += "{\"id\": " + shortCode + ", \"action\":\"none\", \"title\": \"" + obj.Name + "\", \"pin\": \"hidden\",\"fill\": \"" + obj.Color + "\"," + xyOrLangLat + "}";

                        if (result.countries.length != key + 1) {
                            countryString += ",";
                        }
                        else {
                            countryString += "]";
                        }


                    });
                    var data = {
                        "mapwidth": "1200",
                        "mapheight": "760",
                        "bottomLat": "-59",
                        "leftLng": "-190",
                        "topLat": "59",
                        "rightLng": "190",
                        "categories": [
                        ],
                        "levels": [
                            {
                                "id": "World",
                                "title": "World",
                                "map": "/Scripts/mapplic/maps/world.svg",
                                "locations": JSON.parse(countryString)
                            }
                        ]
                    };

                    /** COUNTRIES FILTER **/
                    $("#countryActive").html(result.activeFilter.country != "" ? result.activeFilter.country : "country");

                    $("#countriesFilter").html("");
                    if (result.activeFilter.region != "") {
                        $("#countriesFilter").append("<li data-filter='country'>country</li>")
                        $.each(result.countries, function (key, value) {
                            if (value.CountryCode.indexOf("riverbasin") == -1) {
                                var activeClass = result.activeFilter.country == value.Name ? "c-interactivemap-navigation__submenu--active" : "";
                                $("#countriesFilter").append("<li class='" + activeClass + "' data-filter='country'>" + value.Name + "</li>")
                            }
                        });
                    }
                    else {
                        $("#countriesFilter").append("<li>Select a region</li>")
                    }

                    /** REGION FILTER **/
                    $("#regionActive").html(result.activeFilter.region != "" ? result.activeFilter.region : "region");

                    $("#regionsFilter").html("");
                    $("#regionsFilter").append("<li data-filter='region'>region</li>")
                    $.each(result.regions, function (key, value) {
                        var activeClass = result.activeFilter.region == value ? "c-interactivemap-navigation__submenu--active" : "";
                        $("#regionsFilter").append("<li class='" + activeClass + "' data-filter='region'>" + value + "</li>")
                    });

                    /** STAGE FILTER **/
                    $("#stageFilter").html("");
                    $("#stageFilter").append("<li data-filter='stage'>stage</li>")

                    $.each(result.stages, function (key, value) {
                        var activeClass = result.activeFilter.stage === value.Id ? "c-interactivemap-navigation__submenu--active" : "";
                        $("#stageFilter").append("<li class='" + activeClass + "' data-filter='stage' data-filter-id='" + value.Id + "'>" + value.Name + "</li>")
                    });

                    $("#stageActive").html(result.activeFilter.stage > 0 ? $("#stageFilter .c-interactivemap-navigation__submenu--active").text() : "stage");

                    /** PROGRESS FILTER **/
                    $("#progressFilter").html("");
                    $("#progressFilter").append("<li data-filter='progress'>progress</li>")

                    $.each(result.progress, function (key, value) {
                        var activeClass = result.activeFilter.progress === value.Id ? "c-interactivemap-navigation__submenu--active" : "";
                        $("#progressFilter").append("<li class='" + activeClass + "' data-filter='progress' data-filter-id='" + value.Id + "'>" + value.Name + "</li>")
                    });

                    $("#progressActive").html(result.activeFilter.progress > 0 ? $("#progressFilter .c-interactivemap-navigation__submenu--active").text() : "progress");

                    map = $('#mapplic').mapplic({
                        source: data,
                        height: Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
                        markers: true,
                        sidebar: false,
                        minimap: false,
                        fullscreen: false,
                        developer: developer,
                        lightbox: true,
                        zoombuttons: false,
                        clearbutton: false,
                        maxscale: 4
                    });

                    self = map.data('mapplic');
                    // Location opened
                    map.on('locationopened', function (e, location) {
                        $("#locationFilterValue").val(location.title);
                    });


                    if (result.activeFilter.country != "") {
                        self.showLocation(result.activeFilter.country, 1);
                    }
                    else if (result.activeFilter.location != "") {
                        self.showLocation(result.activeFilter.location, 1);
                    }

                }
            });
        },
        Unicef: function () {

            var windowHeight = (typeof window.outerHeight != 'undefined') ? Math.min(window.outerHeight, $(window).height()) : $(window).height();
            var map;
            var self;
            var developer = false;
            let urlParams = new URLSearchParams(window.location.search);
            let location = urlParams.get('location');

            var url = $('#c-unicefmap-holder').data("url");
            $.ajax({
                url: url + "GetData",
                cache: false,
                dataType: "json",
                data: { Location: location },
                success: function (result) {
                    developer = result.developer;
                    if (developer) {
                        console.log(result);
                    }
                    var countriesObj = [];

                    $.each(result.countries, function (key, obj) {
                        var shortCode = "";
                        if (obj.CountryCode != null && obj.CountryCode != "") {
                            shortCode = obj.CountryCode.toLowerCase();
                        }
                        var xyOrLangLat;
                        if (obj.Ycord && obj.Xcord) {
                            xyOrLangLat = {
                                y: "" + obj.Ycord,
                                x: "" + obj.Xcord
                            };
                        }
                        else {
                            xyOrLangLat = {
                                lat: "" + obj.Latitude,
                                lng: "" + obj.Longitude
                            };
                        }
                        if (obj.MapItems.length > 0) {
                            countryItemList[obj.Name] = [];
                            var description = "<ul>";

                            $.each(obj.MapItems, function (k, item) {
                                var longtext = "";
                                var image = "";
                                var year = "";
                                if (item.LongText != null) {
                                    longtext = item.LongText.Fragments[0].InternalFormat;
                                }
                                if (item.Image != null) {
                                    image = item.Image.Uri;
                                }
                                if (item.Year != 0) {
                                    year = item.Year + " - ";
                                }

                                var CountryList = {
                                    "guid": item.Guid,
                                    "name": item.ShortText,
                                    "year": item.Year,
                                    "ingress": obj.Name + (item.Year > 0 ? " - " + item.Year : ""),
                                    "longtext": longtext,
                                    "image": image,
                                    "logotype": (obj.PinColor == "black" ? "<div class=\"c-logo__link c-logo__link--unicef\"></div>" : "<div class=\"c-logo__link c-logo__link--small\"></div>")
                                };

                                countryItemList[obj.Name].push(CountryList);
                                description += "<li>" +
                                    "<a href='#' onClick='GWP.lightbox.Browse($(this));' " +
                                    "data-country='" + obj.Name + "' data-guid=" + item.Guid + " > " +
                                    year +
                                    item.Name + "</a></li>";
                            });
                            description += "</ul>";

                            var pinColor = obj.PinColor;
                            switch (obj.PinColor) {
                                case "green":
                                    pinColor = "unicefgreen";
                                    break;
                                case "black":
                                    pinColor = "unicefblue";
                                    break;
                            }

                            var mapItemObj = {
                                id: obj.Name,
                                title: obj.Name,
                                label: "" + obj.MapItems.length,
                                description: description,
                                pin: "pin-label " + pinColor
                            };
                            mapItemObj = mergeObject(xyOrLangLat, mapItemObj);

                            if (obj.MapItems.length == 1) {
                                mapItemObj.action = "none";
                                mapItemObj.country = obj.Name;
                                mapItemObj.guid = countryItemList[obj.Name][0].guid;

                            }
                            countriesObj.push(mapItemObj);
                        }

                        var countryObj = {
                            id: shortCode,
                            title: obj.Name,
                            label: "" + obj.MapItems.length,
                            description: description,
                            pin: "hidden",
                            fill: "" + obj.Color,
                            action: "none"
                        };
                        countryObj = mergeObject(xyOrLangLat, countryObj);
                        countriesObj.push(countryObj);
                    });
                    var data = {
                        "mapwidth": "1200",
                        "mapheight": "760",
                        "bottomLat": "-59",
                        "leftLng": "-190",
                        "topLat": "59",
                        "rightLng": "190",
                        "categories": [
                        ],
                        "levels": [
                            {
                                "id": "World",
                                "title": "World",
                                "map": "/Scripts/mapplic/maps/world-unicef.svg",
                                "locations": countriesObj
                            }
                        ]
                    };

                    map = $('#mapplic').mapplic({
                        source: data,
                        height: Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
                        markers: true,
                        sidebar: false,
                        minimap: false,
                        fullscreen: false,
                        developer: developer,
                        lightbox: true,
                        zoombuttons: false,
                        clearbutton: false,
                        maxscale: 4
                    });
                    console.log(result);
                    self = map.data('mapplic');
                    // Location opened
                    map.on('locationopened', function (e, location) {
                        if (location.label === "1") {
                            var container = document.createElement("a");
                            container.dataset.country = location.country;
                            container.dataset.guid = location.guid;
                            GWP.lightbox.Browse($(container));
                        }
                    });
                    if (result.activeFilter.location != "") {
                        self.showLocation(result.activeFilter.location, 1);
                    }

                }
            });

        },
        RegionMap: function () {

            var windowHeight = (typeof window.outerHeight != 'undefined') ? Math.min(window.outerHeight, $(window).height()) : $(window).height();
            var map;
            var self;
            var developer = false;
            var url = $('#c-regionmap-holder').data("url");
            $.ajax({
                url: url + "GetData",
                cache: false,
                dataType: "json",
                success: function (result) {
                    developer = result.developer;
                    if (developer) {
                        console.log(result);
                    }
                    var countriesObj = [];
                    var regions = {};

                    $.each(result.countries, function (key, obj) {
                        var shortCode = "";
                        if (obj.CountryCode != null && obj.CountryCode != "") {
                            shortCode = obj.CountryCode.toLowerCase();
                        }
                        var xyOrLangLat;
                        if (obj.Ycord && obj.Xcord) {
                            xyOrLangLat = {
                                y: "" + obj.Ycord,
                                x: "" + obj.Xcord
                            };
                        }
                        else {
                            xyOrLangLat = {
                                lat: "" + obj.Latitude,
                                lng: "" + obj.Longitude
                            };
                        }
                        var description = "";
                        if (obj.IsAccredited) {
                            description += "<div class='accreditedHeading'>Accredited Country Water Partnership (CWP)</div>";
                        }
                        if (obj.Description != null) {
                            description += obj.Description;
                        }
                        description += "<hr>" +
                            "<a class=\"backLink\" onclick='GWP.mapplic.ShowLocation(\"" + obj.Region.Name + "\", 1)'>" +
                            "Back to " + obj.Region.Name + "</a>";


                        var countryObj = {
                            id: shortCode,
                            name: obj.Name,
                            title:  obj.Name,
                            label: obj.Name,
                            description: description,
                            pin: "hidden",
                            fill: "" + obj.Color,
                            region: obj.Region,
                            isAccredited: obj.IsAccredited
                        };
                        countryObj = mergeObject(xyOrLangLat, countryObj);
                        countriesObj.push(countryObj);

                        if (!regions[obj.Region.Name]) {

                            var RegionDescription = "";
                            if (obj.Region.description != null) {
                                RegionDescription = obj.Region.description;
                            }
                            //pin: "pin-label " + obj.PinColor,
                            regions[obj.Region.Name] = {
                                id: obj.Region.Name,
                                name: obj.Region.Name,
                                title: obj.Region.Name,
                                description: RegionDescription,
                                pin: "pin-label region",
                                label: obj.Region.Name,
                                region: obj.Region.Name,
                                isAccredited: obj.IsAccredited,
                                countries: []
                            };
                            if (obj.Region.Xcord > 0 && obj.Region.Ycord > 0) {
                                xyOrLangLat = {
                                    y: "" + obj.Region.Ycord,
                                    x: "" + obj.Region.Xcord
                                };
                            }
                            regions[obj.Region.Name] = mergeObject(xyOrLangLat, regions[obj.Region.Name]);
                        }
                        regions[obj.Region.Name]["countries"].push(countryObj);
                    });

                    for (var i in regions) {
                        if (regions.hasOwnProperty(i)) {
                            var description = "<ul class='countryList'>";
                            for (var country in regions[i].countries) {
                                var accredited = "";
                                if (regions[i]["countries"][country].isAccredited) {
                                    accredited = " class='accredited'";
                                }

                                description += "<li>" +
                                    "<a " + accredited +" onclick='GWP.mapplic.ShowLocation(\"" + regions[i]["countries"][country].id + "\", 1)'>" +
                                    regions[i]["countries"][country].name + "</a></li>";
                            }
                            description += "</ul>";
                            regions[i]["description"] = description;

                            var regionDescription = regions[i]["countries"][country]["region"].Description;
                            if (regionDescription != null && regions[i]["countries"][country]["region"].Description != "") {
                                regions[i]["description"] += "<hr>" + regionDescription
                            }

                            delete regions[i].countries;
                            countriesObj.push(regions[i]);
                        }
                    }
                    var data = {
                        "mapwidth": "1200",
                        "mapheight": "760",
                        "bottomLat": "-59",
                        "leftLng": "-190",
                        "topLat": "59",
                        "rightLng": "190",
                        "categories": [
                        ],
                        "levels": [
                            {
                                "id": "World",
                                "title": "World",
                                "map": "/Scripts/mapplic/maps/world.svg",
                                "locations": countriesObj
                            }
                        ]
                    };
                    map = $('#mapplic').mapplic({
                        source: data,
                        height: Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
                        markers: true,
                        sidebar: false,
                        minimap: false,
                        fullscreen: false,
                        developer: developer,
                        lightbox: true,
                        zoombuttons: false,
                        clearbutton: false,
                        maxscale: 4
                    });

                    self = map.data('mapplic');
                    // Location opened
                    map.on('locationopened', function (e, location) {
                        if (location.label === "1") {
                            var container = document.createElement("a");
                            container.dataset.country = location.country;
                            container.dataset.guid = location.guid;
                        }
                    });


                }
            });
        },
        ShowLocation: function (id, time) {
            $("#mapplic").mapplic().data("mapplic").showLocation(id, time);
        },
        Events: function () {
            $("#resetFilter").click(function () {
                $('form[name="filterNavigationForm"]').find('input').val("");
                $("#filterNavigationForm").submit();
            });

            $("li").on("click", "[data-filter]", function (event) {
                var filterType = $(this).data("filter");
                var filterOptionalValue = $(this).data("filter-id");
                var filterValue = $(this).text();

                if (filterValue == filterType) {
                    filterValue = "";
                }
                else if (filterType == "IWRM" && filterValue == "IWRM Components") {
                    filterValue = "";
                }
                else if (filterType == "theme") {
                    filterValue = [];
                    $('.themebox:checkbox:checked').each(function () {
                        filterValue.push($(this).val());
                    });
                    filterValue = filterValue.join(";");
                }
                else if (filterOptionalValue != undefined) {
                    filterValue = filterOptionalValue;
                }

                $("#" + filterType + "FilterValue").val(filterValue);
                $("#filterNavigationForm").submit();
            });

            $('.c-interactivemap-header__hamburger').click(function () {
                $('.c-interactivemap-navigation').toggle();
            });

        },
        NameOfFilterID: function (filterArray, filterIDs, withIcon) {
            if (filterArray.length === 0 || filterIDs === null)
                return "";

            var filters = filterIDs.split(",");
            var filterName = "";
            for (i = 0; i < filters.length; i++) {
                var arrayIndex = GWP.lightbox.ArrayObjectIndexOf(filterArray, filters[i], 'Id');
                if (withIcon == true) {
                    if (filterArray[arrayIndex].IconClass) {
                        var icon = filterArray[arrayIndex].IconClass;
                        var file = icon.substr(icon.indexOf('.'), icon.length);
                        switch (file) {
                            case '.svg':
                                icon = GWP.mapplic.GetSvg('/Images/' + icon, 14, 14, '#fff');
                                break;
                            default:
                                icon = "<i class='" + filterArray[arrayIndex].IconClass + "' aria-hidden='true' style='margin-right: 4px;'></i>";
                                break;
                        }
                        filterName += icon;
                    }
                }
                filterName += filterArray[arrayIndex].Name;

                if (i != filters.length - 1) {
                    filterName += ", ";
                }
            }
            return filterName;
        },
        GetSvg: function (filename, width, height, color) {
            var image = '<img src="' + filename + '" style="width: ' + width + 'px;height: ' + height + 'px;fill: ' + color + ';margin-right: 4px;">';
            return image;
        }
    };
    return instance;
};
GWP.lightbox = new function () {
    var instance = {
        Init: function () {
            $(document).click(function (e) {
                var lightbox = $("#lightbox");
                if (lightbox.is(e.target)) {
                    lightbox.hide();
                }
            });
            $("body").keydown(function (e) {

                var lightBoxShown = $("#lightbox").is(":visible");

                if (e.keyCode == 37 && lightBoxShown) { // left
                    var prevBtn = $('#lightbox .btn--prev');
                    if (prevBtn.is(":visible")) {
                        prevBtn.click();
                    }
                }
                else if (e.keyCode == 39 && lightBoxShown) { // right
                    var nextBtn = $('#lightbox .btn--next');
                    if (nextBtn.is(":visible")) {
                        nextBtn.click();
                    }
                }
            });
        },

        Browse: function (obj) {
            var countryString = obj.data("country");
            var guid = obj.data("guid");
            var countryArray = countryItemList[countryString];
            var countryItemIndex = GWP.lightbox.ArrayObjectIndexOf(countryArray, guid, 'guid');
            var countryItem = countryArray[countryItemIndex];
            var headline = countryItem.name;
            var ingress = countryItem.ingress;
            var longtext = countryItem.longtext;

            var image = countryItem.image;
            var logotype = countryItem.logotype;

            var impactStory = countryItem.ImpactStory;
            var caseStudy = countryItem.CaseStudy;

            var downloadUrl = countryItem.documenturl;
            var downloadText = countryItem.documenttext;

            var IWRM = countryItem.IWRM;
            var IWRMNames = countryItem.IWRMNames;
            var themeIDs = countryItem.theme;
            var themeNames = countryItem.themeNames;

            var prev = $("#lightbox .btn--prev");
            var next = $("#lightbox .btn--next");

            next.hide();
            prev.hide();

            if (countryItemIndex > 0) {
                $('.btn--prev').data("guid", countryArray[countryItemIndex - 1].guid);
                $('.btn--prev').data("country", countryString);
                prev.show();
            }

            if (countryItemIndex != (countryArray.length - 1)) {
                $('.btn--next').data("guid", countryArray[countryItemIndex + 1].guid);
                $('.btn--next').data("country", countryString);
                next.show();
            }

            $("#lightbox .headline").html(headline);
            $("#lightbox .ingress").html(ingress);
            $("#lightbox .longtext").html(longtext);

            $("#lightbox .container .extraStory").addClass("u-hide");
            $("#lightbox .container .extraStory__impactStory").addClass("u-hide");
            $("#lightbox .container .extraStory__caseStudy").addClass("u-hide");

            if (image != null && image.length > 0) {
                $("#lightbox .image").html("<img src='" + image + "'>");
            } else {
                $("#lightbox .image").html("");
            }

            if (logotype != null) {
                $("#lightbox .logotype").html(logotype);
            }

            if (downloadUrl != null && downloadText != null && downloadUrl.length > 0 && downloadText.length > 0) {
                $("#lightbox .download")
                    .attr("href", downloadUrl)
                    .removeClass("u-hide")
                    .find("span")
                    .text(downloadText);
            }
            else {
                $("#lightbox .download").addClass("u-hide");
            }

            if (impactStory != null || caseStudy != null) {
                var showBox = false;

                if (impactStory && impactStory.toLowerCase != "impact story") {
                    var story = $("#lightbox .container .extraStory__impactStory");
                    story.removeClass("u-hide");
                    story.find("a").attr("href", impactStory);
                    showBox = true;
                }

                if (caseStudy && caseStudy.toLowerCase != "case study") {
                    var study = $("#lightbox .container .extraStory__caseStudy");
                    study.removeClass("u-hide");
                    study.find("a").attr("href", caseStudy);
                    showBox = true;
                }

                if (showBox) $("#lightbox .container .extraStory").removeClass("u-hide");

            }

            $("#lightbox .container .extraFilter").addClass("u-hide");
            $("#lightbox .container .extraFilter__iwrm").addClass("u-hide");
            $("#lightbox .container .extraFilter__theme").addClass("u-hide");
            //console.log(countryItem);
            if (IWRM != null || themeIDs != null) {
                var showBox = false;

                if (IWRM) {
                    $("#lightbox .container .extraFilter__iwrm").removeClass("u-hide").find("span").html(IWRMNames);
                    showBox = true;
                }
                if (themeIDs) {
                    $("#lightbox .container .extraFilter__theme").removeClass("u-hide").find("span").html(themeNames);
                    showBox = true;
                }

                if (showBox) $("#lightbox .container .extraFilter").removeClass("u-hide");
            }

            $("#lightbox").show();

        },
        ArrayObjectIndexOf: function (myArray, searchTerm, property) {
            for (var i = 0, len = myArray.length; i < len; i++) {
                if (myArray[i][property] === searchTerm) return i;
            }
            return -1;
        }
    };
    return instance;
};
GWP.menu = new function () {
    var instance = {
        Init: function () {
            $('.c-interactivemap-navigation li').click(function () {
                $(this).find('.c-interactivemap-navigation__submenu').toggle();
                $(this).find('.c-interactivemap-navigation__item__headline').toggleClass("c-interactivemap-navigation__item__headline__active");
            });
        }
    };
    return instance;
};

function mergeObject(objectToAdd, objectResult) {
    // Loop through our object
    for (var i in objectToAdd) {
        if (objectToAdd.hasOwnProperty(i)) {
            // Push each value from `obj` into `extended`
            objectResult[i] = objectToAdd[i];
        }
    }
    return objectResult;
};
; (function () {
    $(window).scroll(function () {
        var scroll = $(window).scrollTop();
        if (scroll > 50) {
            $('.header').addClass('-scrolled');
        }
        else {
            $('.header').removeClass('-scrolled');
        }
    });
})($, window, document, undefined);;
; (function ($, window, document, undefined) {
    'use strict';

    //återställ till utgångsläge vid vid brytpunkts-skifte
    const mqLarge = window.matchMedia("(max-width: 757px)");

    mqLarge.addEventListener("change", mqHandler);

    function mqHandler(e) {
        if (e.matches) {
            let allCarousels = document.querySelectorAll(".carousel");
            Array.from(allCarousels).forEach((carousel) => {

                let id = carousel.children[0].id;
                carousel.setAttribute("data-scrollpos", id);

                setIndicator(carousel, id);

                carousel.scrollTo({
                    left: 0,
                    behavior: 'smooth'
                });
            });
        }
    }

    //alla element med carousel-klassen
    const carousels = document.querySelectorAll('.carousel');
    //loopa igenom och anropa funktion för att skapa karusell
    Array.from(carousels).forEach((carousel) => createCarousel(carousel));

    function createCarousel(carousel) {
        var id = Math.floor((1 + Math.random()) * 0x10000)
            .toString(16)
            .substring(1);

        const items = carousel.childElementCount;
        let children = carousel.children;

        if (carousel.nodeName !== "UL") {
            carousel.classList.add("carousel--cloned");
        }

        for (var i = 0; i < children.length; i) {
            if (children[i].nodeName !== "LI") {
                var clone = children[i].cloneNode(true);
                clone.classList.add('cloned');
                carousel.before(clone);
            }

            children[i].setAttribute("id", "slide-" + id + ++i);
            createObserver(carousel, children[i - 1]);
        }

        let div = document.createElement("div")
        div.classList.add("carousel-nav");
               

        for (let i = 1; i < items + 1; i++) {
            let button = document.createElement("button");
            button.classList.add("carousel-btn");
            button.setAttribute("data-controls", "slide-" + id + i);
            button.setAttribute("aria-label", "Visa vy " + i);

            button.addEventListener('click', () => {
                var left = document.getElementById("slide-" + id + i).offsetLeft;

                carousel.scrollTo({
                    left: left-1,
                    behavior: 'smooth'
                });
            });
            div.append(button);
        }

        carousel.after(div);
    }


    function createObserver(carousel, view) {
        let options = {
            root: carousel,
            threshold: 0.51
        }

        let callback = (entries, observer) => {
            entries.forEach((entry) => {
                if (entry.isIntersecting) {
                    setIndicator(carousel, entry.target.id);
                }
            });
        };

        let observer = new IntersectionObserver(callback, options);
        observer.observe(view);
    }

    function setIndicator(carousel, id) {

        let el = document.querySelector('[data-controls="' + id + '"]');
        const buttons = el.parentNode.querySelectorAll(".carousel-btn");

        Array.from(buttons).forEach((btn) => {
            btn.classList.remove("carousel-btn--active");
        });

        el.classList.add("carousel-btn--active");
        carousel.setAttribute("data-scrollpos", id);
    }
})($, window, document, undefined);;
; (function () {
    var cards = document.querySelectorAll("[data-card]");

    //loops through all buttons and adds listener for click
    Array.from(cards).forEach((card) => addEL(card));

    function addEL(card) {
        var link = card.querySelector("[data-card-link]");
        if (link) {
            card.classList.add("-clickable");

            link.addEventListener("focus", function () {
                card.classList.add("card-focus");
            });
            link.addEventListener("blur", function () {
                card.classList.remove("card-focus");
            });
            card.addEventListener("click", function () {
                var url = link.getAttribute("href");
                location.href = url;
                link.preventDefault;
            });
        }
    }
})($, window, document, undefined);;
; (function ($, window, document, undefined) {
    $(document).on('click', '[data-toggle="mobile-menu"]', function (e) {
        e.stopPropagation();
        $(this).toggleClass('-open');
        $('.nav-container').toggleClass('-open');
        $('body').toggleClass('-freeze');
    })

    $(document).on('click', '[data-nav-item-toggler]', function (e) {
        $(this).closest('[data-nav-item]').toggleClass('-open');
    })
})($, window, document, undefined);


;
