(function($){
    Drupal.behaviors.seed = {
      attach:function(context, settings) {

     	if ($('body.not-logged-in').length && !jQuery(".transparency").length) {
            $(document).bind("contextmenu",function(e) {
             e.preventDefault();
            });
        }

        let url = window.location.href;
        $('.enlace-principal-unidades a').each(function() {
            if (this.href === url) {
                $(this).closest('.enlace-principal-unidades').addClass('active');
            }
        });


        $( ".socialmedia-button" ).click(function() {
            if ($( ".socialmedia-button" ).hasClass('selected')) {
                $( "#block-views-redes-sociales-block" ).show();
            } else {
                $( "#block-views-redes-sociales-block" ).hide();
            }
        });


        window.onload = function(){

            if( $('.view-slider-home-principal .vscc-next-processed').length > 0){
                $('.view-slider-home-principal .vscc-next-processed a img').hide()
            }

            if( $('.view-slider-home-principal .vscc-previous-processed').length > 0){
                $('.view-slider-home-principal .vscc-previous-processed a img').hide()
            }


            if($('.views_slideshow_cycle_teaser_section').length > 0){
                $('.views_slideshow_cycle_teaser_section').css('width', '100% !important');
            }
        };

      }
    }
}(jQuery));


var myScreenData = { smd: 768, ssm: 480 };
var Seed_revista_criminalidad = {
    init: function($){
        this.$=$;
        this.$(window).resize(function() { Seed_revista_criminalidad.initAnimation(); });
        Seed_revista_criminalidad.initAnimation();
    },
    onResize: function() {
        var anchoventana = Seed_revista_criminalidad.$(window).width();
        try{ var anchoventana=window.innerWidth; } catch(err) { console.warn('Problem: Browser compatibility') }
        if(anchoventana<myScreenData.smd)
        {
            var revistaHeight = this.$('.page-revista-criminalidad #content .view-revista-criminalidad > .view-content .views-row .grup-2 .views-field-field-thumbnail').height();
            this.$('.page-revista-criminalidad #content .view-revista-criminalidad > .view-content .views-row .grup-1').css('margin-top',(revistaHeight+Seed_revista_criminalidad.marginExtra)+'px');
        }
        else
        { this.$('.page-revista-criminalidad #content .view-revista-criminalidad > .view-content .views-row .grup-1').css('margin-top','0px'); }
    },
    bnAnimate: true,
    marginExtra: 40,
    countAnimation: 0,
    numMaxAnimations: 10,
    initAnimation: function() { Seed_revista_criminalidad.countAnimation=0; Seed_revista_criminalidad.animate(); },
    animate: function() {
        if(Seed_revista_criminalidad.countAnimation<Seed_revista_criminalidad.numMaxAnimations)
        {
            if(Seed_revista_criminalidad.bnAnimate)
            { Seed_revista_criminalidad.timeout = window.setTimeout(function() { Seed_revista_criminalidad.onResize(); Seed_revista_criminalidad.animate(); },1000); }

            Seed_revista_criminalidad.countAnimation++;
        }
        else
        {
            Seed_revista_criminalidad.countAnimation=0;
        }
    },
};

(function($){ Seed_revista_criminalidad.init($); })(jQuery);

var Seed_mainmenu = {
    init: function($){
        this.$ = $;
        Seed_mainmenu.social.content.createButton();
        Seed_mainmenu.social.addEventOnLeave();
        Seed_mainmenu.topmenu.content.createButton();
        Seed_mainmenu.topmenu.addEventOnLeave();
        Seed_mainmenu.mainmenu.button.addEvents();
        this.$(window).resize(function() { Seed_mainmenu.onResize(); });
        this.onResize();
    },
    onResize: function() {
        var ancho = Seed_mainmenu.$(window).width();
        if(ancho<=myScreenData.smd)
        {
            this.onScreenSizeMd();
        }
        else if(ancho<=myScreenData.ssm)
        {
            this.onScreenSizeSm();
        }
    },
    onScreenSizeMd: function()
    {

    },
    onScreenSizeSm: function()
    {

    },
    social: {
        identificator: '.block-widgets-s-socialmedia-profile-default',
        classNameButtom: 'socialmedia-button',
        bnVisible: false,
        show: function(){
            Seed_mainmenu.$('.'+this.classNameButtom).addClass('selected');
            return this.bnVisible=true;
        },
        hide: function(){
            Seed_mainmenu.$('.'+this.classNameButtom).removeClass('selected');
            return this.bnVisible=false;
        },
        switch: function(){
            if(!this.bnVisible)
            { return this.show(); }
            else
            { return this.hide(); }
        },
        bnEventOnLeave: false,
        addEventOnLeave: function(){
            if(!this.bnEventOnLeave)
            {
                Seed_mainmenu.$(Seed_mainmenu.social.identificator).mouseleave(function(){
                    if(!Seed_mainmenu.social.hide())
                    { Seed_mainmenu.$(Seed_mainmenu.social.identificator).removeClass('selected'); }
                });

                this.bnEventOnLeave=true;
            }
        },
        content: {
            identificator: '.region-sidebar-second',
            bnButton: false,
            createButton: function() {
                if(!this.bnButton)
                {
                    this.button=document.createElement('div');
                    this.button.className=Seed_mainmenu.social.classNameButtom;
                    Seed_mainmenu.$(this.button).click(function(){
                        if(Seed_mainmenu.social.switch())
                        { Seed_mainmenu.$(Seed_mainmenu.social.identificator).addClass('selected'); }
                        else
                        { Seed_mainmenu.$(Seed_mainmenu.social.identificator).removeClass('selected'); }
                    });
                    Seed_mainmenu.$(this.identificator).prepend(this.button);

                    this.bnButton=true;
                }
            }
        }
    },
    topmenu: {
        identificator: '#topbar-third',
        classNameButtom: 'topmenu-button',
        bnVisible: false,
        show: function(){
            Seed_mainmenu.$('.'+this.classNameButtom).addClass('selected');
            return this.bnVisible=true;
        },
        hide: function(){
            Seed_mainmenu.$('.'+this.classNameButtom).removeClass('selected');
            return this.bnVisible=false;
        },
        switch: function(){
            if(!this.bnVisible)
            { return this.show(); }
            else
            { return this.hide(); }
        },
        bnEventOnLeave: false,
        addEventOnLeave: function(){
            if(!this.bnEventOnLeave)
            {
                Seed_mainmenu.$(Seed_mainmenu.topmenu.identificator).mouseleave(function(){
                    if(!Seed_mainmenu.topmenu.hide())
                    { Seed_mainmenu.$(Seed_mainmenu.topmenu.identificator).removeClass('selected'); }
                });

                this.bnEventOnLeave=true;
            }
        },
        content: {
            identificator: '#topbar>.zone-wrapper',
            bnButton: false,
            createButton: function() {
                if(!this.bnButton)
                {
                    this.button=document.createElement('div');
                    this.button.className=Seed_mainmenu.topmenu.classNameButtom;
                    Seed_mainmenu.$(this.button).click(function(){
                        if(Seed_mainmenu.topmenu.switch())
                        { Seed_mainmenu.$(Seed_mainmenu.topmenu.identificator).addClass('selected'); }
                        else
                        { Seed_mainmenu.$(Seed_mainmenu.topmenu.identificator).removeClass('selected'); }
                    });
                    Seed_mainmenu.$(this.identificator).prepend(this.button);

                    this.bnButton=true;
                }
            }
        }
    },
    mainmenu: {
        bnShow: false,
        show: function() { this.button.show(); this.menu.show(); this.bnShow=true; },
        hide: function() { this.button.hide(); this.menu.hide(); this.bnShow=false; },
        switch: function() {
            if(!this.bnShow)
            { return this.show(); }
            else
            { return this.hide(); }
        },
        button: {
            identificator: '.block-system-main-menu h2.block-title',
            content: { identificator: '' },
            show: function() { Seed_mainmenu.$(Seed_mainmenu.mainmenu.button.identificator).addClass('selected'); },
            hide: function() { Seed_mainmenu.$(Seed_mainmenu.mainmenu.button.identificator).removeClass('selected'); },
            bnAddEvents: false,
            addEvents: function() {
                if(!this.bnAddEvents)
                {
                    Seed_mainmenu.$(this.identificator).click(function(){ Seed_mainmenu.mainmenu.switch(); });

                    this.bnAddEvents=true;
                }
            },
        },
        menu: {
            identificator: '.block-system-main-menu > .content',
            show: function() { Seed_mainmenu.$(Seed_mainmenu.mainmenu.menu.identificator).addClass('selected'); },
            hide: function() { Seed_mainmenu.$(Seed_mainmenu.mainmenu.menu.identificator).removeClass('selected'); },
            bnEventOnLeave: false,
            addEventOnLeave: function(){
                if(!this.bnEventOnLeave)
                {
                    Seed_mainmenu.$(this.identificator).mouseleave(function() {
                        Seed_mainmenu.mainmenu.hide();
                    });

                    this.bnEventOnLeave=true;
                }
            },
        }
    }
};

(function($){ Seed_mainmenu.init($); })(jQuery);


/* Source: HTML5-Boilerplate https://github.com/h5bp/html5-boilerplate/blob/master/src/js/plugins.js */
// Avoid `console` errors in browsers that lack a console.
(function($) {
    Drupal.behaviors.seed_police = {
        attach: function (context, settings) {
            var s_sm = 480;
            var s_md = 1024;
            var s_lg = 1400;

            //---- .load function by loading images ----//
            jQuery(window).load(function() {

                //---- Autoplay slider Home ----//
                var SliderHome = 0;
                var SliderHomeLength = jQuery('#slideshow-home-principal .slideshow-inner li').length;
                function TimeSliderHome() {
                    if(SliderHome === SliderHomeLength) {
                        SliderHome = -1;
                    }
                    SliderHome = SliderHome + 1;
                    $('#shpbutton-'+ SliderHome).attr("checked", "checked");
                }
                jQuery('#slideshow-home-principal label').click(function(event){
                    var GetAttribute = jQuery(this).attr("for");
                    var GetNumber = GetAttribute.substr(GetAttribute.length - 1);
                    var ChangeText = parseInt(GetNumber);
                    SliderHome = ChangeText;
                });
                setInterval(TimeSliderHome, 5000);



                //---- Autoplay slider Home Recommended. ----//
                var SliderRecommended = 0;
                var SliderRecommendedLength = jQuery('#slideshow-home-recomendados .slideshow-inner li').length;
                function TimeSliderRecommended() {
                    if(SliderRecommended === SliderRecommendedLength ) {
                        SliderRecommended = -1;
                    }
                    SliderRecommended = SliderRecommended + 1;
                    jQuery('#srbutton-' + SliderRecommended ).attr("checked", "checked");
                }
                jQuery('#slideshow-home-recomendados label').click(function(event){
                    var GetAttribute = jQuery(this).attr("for");
                    var GetNumber = GetAttribute.substr(GetAttribute.length - 1);
                    var ChangeText = parseInt(GetNumber);
                    SliderRecommended = ChangeText;
                });
                setInterval(TimeSliderRecommended, 5000);

                //---- Autoplay slider unit observatory ----//
                var SliderObservatory = 0;
                var SliderObservatoryLength = jQuery('#slideshow-observatorio-delito .slideshow-inner li').length;
                function TimeSliderObservatory() {
                    if(SliderObservatory === SliderObservatoryLength) {
                        SliderObservatory = -1;
                    }
                    SliderObservatory = SliderObservatory + 1;
                    $('#oddbutton-'+ SliderObservatory).attr("checked", "checked");
                }
                jQuery('#slideshow-observatorio-delito label').click(function(event){
                    var GetAttribute = jQuery(this).attr("for");
                    var GetNumber = GetAttribute.substr(GetAttribute.length - 1);
                    var ChangeText = parseInt(GetNumber);
                    SliderObservatory = ChangeText;
                });
                setInterval(TimeSliderObservatory, 5000);

                // CarouFredSel Unit Observatory
               if ( $(".view-polired-slider").length > 0 ) {
                  jQuery('.view-polired-slider .view-content ul').carouFredSel({
                    auto: 5000,
                    responsive : true,
                    height: 'variable',
                    items: {
                        height: 'variable'
                    },
                    pagination: '#pager-slider-polired',
                  });
                }



                // CarouFredSel Unit Observatory
          /*      jQuery('.view-polired-coest .view-content ul').carouFredSel({
                    auto: 5000,
                    responsive : true,
                    height: 'variable',
                    items: {
                        height: 'variable'
                    },
                    pagination: '#pager-slider-polired-coest',
                }); */

                // CarouFredSel template
                 if ( $(".field-name-plantilla-slider").length > 0 ) {
                  jQuery('.field-name-plantilla-slider .field-content').carouFredSel({
                      auto: 5000,
                      responsive : true,
                      pagination: '#pager-slider-template',
                  });
                }

                // CarouFredSel calendar.
                jQuery('.mini-day-on a').hover(function(){
                    jQuery('.bt-content ul').after('<span id="prev">Prev</span><span id="next">Next</span>');
                    jQuery('.bt-content ul').carouFredSel({
                        auto: false,
                        responsive : true,
                        height: 'variable',
                        items: {
                            height: 'variable'
                        },
                        prev:    '#prev',
                        next:    '#next',
                    });
                });

                // Calendar event.
                if (jQuery('.view-eventos .view-content .event-calendar').length < 1) {
                    jQuery('.view-eventos .view-content').addClass('not-calendar');
                }

                // Page news.
                jQuery('.page-noticias .view-id-solr_noticias .view-footer').prependTo('.page-noticias .view-id-solr_noticias .item-list');


                // js que manipula los estilos y comportamientos del reproductor del himno

                    function AudioItem(SelectAudio) {

                    jQuery('audio').attr('id', 'audio');
                    audio.controls = false;

                    jQuery(SelectAudio).append("<div id='songPlay'></div>");
                    jQuery(SelectAudio).append("<div class='content-slider'><div id='songSlider'></div> <div id='trackProgress'></div> <div>");
                    jQuery(SelectAudio).append("<div id='songTime'></div>");

                    var activeSong = document.getElementById('audio');
                    function play() {
                        if (activeSong.paused){
                            activeSong.play();
                        }
                        else{
                            activeSong.pause();
                        }
                    }
                    activeSong.ontimeupdate = function(){updateTime()};

                    function updateTime() {
                        var currentSeconds = (Math.floor(activeSong.currentTime % 60) ? '0' : '') + Math.floor(activeSong.currentTime % 60);
                        var currentMinutes = Math.floor(activeSong.currentTime / 60);
                        document.getElementById('songTime').innerHTML = currentMinutes + ":" + currentSeconds + ' / ' + Math.floor(activeSong.duration / 60) + ":" + (Math.floor(activeSong.duration % 60) ? '0' : '') + Math.floor(activeSong.duration % 60);
                        var percentageOfSong = (activeSong.currentTime/activeSong.duration);
                        var percentageOfSlider = document.getElementById('songSlider').offsetWidth * percentageOfSong;
                        document.getElementById('trackProgress').style.width = Math.round(percentageOfSlider) + "px";
                    }

                    function setLocation(percentage){
                        activeSong.currentTime = activeSong.duration * percentage;
                    }

                    function setSongPosition(obj,e){
                        var songSliderWidth = obj.offsetWidth;
                        var evtobj=window.event? event : e;
                        clickLocation = evtobj.layerX - obj.offsetLeft;
                        var percentage = (clickLocation/songSliderWidth);
                        setLocation(percentage);
                    }
                    jQuery('#songSlider').click(function(){
                        setSongPosition(this,event);
                    });
                    jQuery('#songPlay').click(function(){
                        play();
                        jQuery(this).toggleClass('pause')
                    });
                    activeSong.timeupdate = updateTime();
                    }
                    if (jQuery('audio').length > 0 ){
                        if(jQuery('.views-field-field-audio').length > 0) {
                            AudioItem('.views-field-field-audio');
                        }
                        else {
                            AudioItem('.field-name-field-audio');
                        }
                    }

            });

            var SliderRecommendedLength = jQuery('#slideshow-home-recomendados .slideshow-inner li').length;
            jQuery('#slideshow-home-recomendados ul').css({ width : SliderRecommendedLength + '00%' });
            jQuery('#slideshow-home-recomendados ul li').css({ width :  'calc(100% / ' + SliderRecommendedLength + ')' });

            //Menu main expander
            jQuery('.block-system-main-menu > .content > .menu > .expanded > .menu').wrap('<div class="content-father-main element-invisible"></div>');
            jQuery('.block-system-main-menu > .content > .menu > .expanded > .content-father-main').append('<div class="close"></div>');

            jQuery('.block-system-main-menu > .content > .menu > .expanded .nolink').click(function(event){
                jQuery('body').addClass('active-menu-expanded');
                jQuery(event.target).siblings('.content-father-main').removeClass('element-invisible');
            });

            jQuery('.content-father-main .close').click(function(event){
                jQuery('body').removeClass('active-menu-expanded');
                jQuery(event.target).closest('.content-father-main').addClass('element-invisible');
            });

            //ScrollTop

            jQuery(window).scroll(function() {
                var win = jQuery(window);

                var new_window_scroll_top = $(window).scrollTop();

                if(new_window_scroll_top > 10 ) {
                    jQuery('#block-policia-link-subir').show();
                }
                else {
                    jQuery('#block-policia-link-subir').hide();
                }

                var scrool_Bottom = jQuery(window).height() + new_window_scroll_top + 341;

                if( scrool_Bottom = jQuery(document).height() ) {
                    jQuery('#block-policia-link-subir').css({
                        "bottom": 345,
                    });
                }
                else {
                    jQuery('#block-policia-link-subir').css({
                        "bottom": "10%",
                    });
                }
            });

            jQuery('#block-policia-link-subir a').click(function(e){
                e.preventDefault();
                jQuery("html, body").animate({ scrollTop: 0 }, "slow");
            });

            // Menu topbar expander
            jQuery('.menu-father ~ .menu').append('<div class="close"></div>');
            jQuery('.menu-father ~ .menu').wrap('<div class="content-father element-invisible"></div>');


            jQuery('.menu-father').click(function(){
                jQuery('body').addClass('active-menu-expanded');
                jQuery('.menu-father ~ .content-father').removeClass('element-invisible');
            });

            jQuery('.content-father .close').click(function(){
                jQuery('body').removeClass('active-menu-expanded');
                jQuery('.menu-father ~ .content-father').addClass('element-invisible');
            });

            jQuery(document).bind('keydown',function(e){
                if ( e.which == 27 ) {
                    jQuery('body').removeClass('active-menu-expanded');
                    jQuery('.menu-father ~ .content-father').addClass('element-invisible');
                    jQuery('.content-father-main').addClass('element-invisible');
                };
            });
            // Menu topbar expander second level
            jQuery('.content-father > .menu > .menu-item.first > .menu > li.expanded').children('.menu').addClass('element-invisible');

            // Block incorporation
            jQuery('.block-menu-menu-incorporaci-n .block-title').wrap('<div class="content-title"></div>');

            jQuery('.block-menu-menu-incorporaci-n .content-title').click(function(){
                jQuery('.block-menu-menu-incorporaci-n').toggleClass('active');

                if ( jQuery(window).width() > s_md ) {
                    jQuery('.block-menu-menu-incorporaci-n .content').animate({
                        height: "toggle",
                        width: "toggle"
                    });
                }
                else if( jQuery(window).width() < s_md ) {
                    jQuery('.block-menu-menu-incorporaci-n .content').slideToggle(1000);
                }

            });

            //Tabs pages
            jQuery('.node-type-unidades .view-mode-escuelas_de_policia .horizontal-tabs-list').wrap('<div class="content-tabs"></div>');

            if( jQuery(window).width() < 768 ) {

                // Estado de las vias.
                jQuery('.view-estado-de-las-v-as .view-content .via ~ .views-fieldset legend').click(function (event) {
                    jQuery(this).toggleClass('active');
                    jQuery(this).siblings('.fieldset-wrapper').slideToggle(500);
                });

                jQuery('.view-estado-de-las-v-as .view-header').click(function (event) {
                    jQuery(this).siblings('.view-filters').slideToggle(500);
                });

                // Menu - Observatory
                jQuery('#menu-policia-unidad-observatorio > li > span').click(function (event) {
                    jQuery(this).toggleClass('active');
                    jQuery(this).siblings('.item-list').slideToggle(500);
                });
            }

            //Overflow menu
            function OverflowMenu (select_click, select_menu) {
                jQuery(select_click).click(function(){
                    if( jQuery(window).width() > 1024 ) {

                        var H_Window = jQuery(window).height();
                        var Size_Total = H_Window - 100;
                        var H_Menu = jQuery(select_menu).height();

                        if(Size_Total <= H_Menu) {
                            jQuery(select_menu).css({
                                height : Size_Total,
                                'overflow-y' : 'scroll',
                            });
                        }
                        else {
                            jQuery(select_menu).height('auto');
                            jQuery(select_menu).css({
                                'overflow-y' : 'hidden',
                            });
                        }
                    }
                });
                jQuery(window).resize(function() {
                    jQuery(select_menu).height('auto');
                    if( jQuery(window).width() > 1024 ) {

                        var H_Window = jQuery(window).height();
                        var Size_Total = H_Window - 100;
                        var H_Menu = jQuery(select_menu).height();

                        if(Size_Total <= H_Menu) {
                            jQuery(select_menu).css({
                                height : Size_Total,
                                'overflow-y' : 'scroll',
                            });
                        }
                        else {
                            jQuery(select_menu).height('auto');
                            jQuery(select_menu).css({
                                'overflow-y' : 'hidden',
                            });
                        }
                    }
                });
                jQuery('.close').click(function(){
                    jQuery(select_menu).height('auto');
                    jQuery(select_menu).css({
                        'overflow-y' : 'hidden',
                    });
                });
            }
            OverflowMenu('.block-menu-menu-menu-topbar > .content .menu-item .menu-father', '.block-menu-menu-menu-topbar > .content .menu-father ~ .content-father > .menu');
            OverflowMenu('.block-system-main-menu > .content > .menu > .menu-item > .nolink', '.block-system-main-menu > .content > .menu > li:nth-child(2) > .content-father-main > .menu');
            OverflowMenu('.block-system-main-menu > .content > .menu > .menu-item > .nolink', '.block-system-main-menu > .content > .menu > li.first > .content-father-main > .menu');
            OverflowMenu('.block-system-main-menu > .content > .menu > .menu-item > .nolink', '.block-system-main-menu > .content > .menu > li.last > .content-father-main > .menu');


            //Page basic images

            function BasiPageImages(SelectItem, SelectParent) {
                var NumbersElements = jQuery(SelectItem).length;
                if( NumbersElements <= 4 ) {
                    jQuery(SelectParent).addClass('two-col');
                }
                if (NumbersElements == 1 ){
                    jQuery(SelectParent).addClass('one-image');
                }

                jQuery(SelectItem).each(function() {
                    jQuery(this).children('a').addClass('link-element').children('img').appendTo(this);
                });
            }

            BasiPageImages('.node-type-p-gina #content .field-name-field-image .field-item', '.node-type-p-gina #content .field-name-field-image');
            BasiPageImages('.node-type-p-gina-unidad #content .field-name-field-imagen .field-item', '.node-type-p-gina-unidad #content .field-name-field-imagen');
            BasiPageImages('.node-type-p-gina-unidad #content .field-name-field-image .field-item', '.node-type-p-gina-unidad #content .field-name-field-image');
            BasiPageImages('.node-type-p-gina-unidad #content .field-name-field-image .field-item', '.node-type-p-gina-unidad #content .field-name-field-image');
            BasiPageImages('.node-type-p-gina-unidad #content .group-uniforme .field-name-field-fotografia', '.node-type-p-gina-unidad #content .group-uniforme');
            BasiPageImages('.node-type-p-gina-unidad #content .field-type-image .field-item', '.node-type-p-gina-unidad #content .field-name-field-imagen-galeria');

            //Imagenes establecimiento sanidad
            jQuery('.node-establecimientos-de-sanidad .field-name-field-image .field-item').each(function() {
                jQuery(this).children('a').addClass('link-element').children('img').appendTo(this);
            });

            //linea de emergencia Home.
            var ElementEmergency = jQuery('.view-lineas-de-emergencia .views-row').length;
            var WidthItemEmergency = (100 / ElementEmergency + "%");
            jQuery('.view-lineas-de-emergencia .views-row').css({
                width: WidthItemEmergency,
            });
        }
    }

    //Height elements
    Drupal.behaviors.height_elements = {
        attach: function (context, settings) {

            function HeightElements (selectItems) {
                jQuery(window).bind('load', function() {
                    if ( jQuery(window).width() >= 768) {
                        var maxH = 0;
                        jQuery(selectItems).each(function(i) {
                            var actH = jQuery(this).height();
                            if(actH > maxH) {
                                maxH = actH;
                            }
                        });
                        jQuery(selectItems).height(maxH);
                    }
                    else {
                        jQuery(selectItems).height('auto');
                        jQuery('.view-eventos .views-row-first .block-event').height('auto');
                    }

                    $(window).resize(function() {
                        jQuery(selectItems).height('auto');
                        if ( jQuery(window).width() >= 768) {
                         var maxH = 0;
                        jQuery(selectItems).each(function(i) {
                            var actH = jQuery(this).height();
                            if(actH > maxH) {
                                maxH = actH;
                            }
                        });
                        jQuery(selectItems).height(maxH);
                    }
                    else {
                        jQuery(selectItems).height('auto');
                        jQuery('.view-eventos .views-row-first .block-event').height('auto');
                    }
                    });
                });
            }

            HeightElements('.all-items-news .views-row');
            HeightElements('.node-type-p-gina #main .section #content .field-name-field-objetos .field-items .field-item');
            HeightElements('.field-name-field-lista-descargable .field-item');
            HeightElements('.view-eventos .view-content > .views-row');
            HeightElements('.node-type-unidades .director-grupo > div');
            HeightElements('.block-views-nodequeue-1-block-2 .news-block-group > .views-field');
            HeightElements('.block-views-nodequeue-1-block-2 .content > .view-nodequeue-1 > .view-content > .views-row > div');
            HeightElements('.group-asuntos-internacionales .group-grupo-2 .group-presencia-content .group-presencia > div');
            HeightElements('.group-director .unidades-director > .field-group-div');
            HeightElements('.node-type-polired .group-video-1 > .field');
            HeightElements('.node-type-polired .group-block-footer > div');
            HeightElements('.page-unidades-georeferenciacion-del-delito .group-georeferenciacion .field-item');
            HeightElements('.view-escalafon-de-horoes .views-row');
            HeightElements('.group-mision .field-collection-view  .field');
            HeightElements('.node-type-noticias .view-solr-noticias .view-content .views-row');
            HeightElements('.field-name-plantilla-bloques .view-plantilla .view-content .views-row');
            HeightElements('.group-escuela .group-grupo-2 > div');
            HeightElements('.node-type-subsitio .field-name-field-bloques .field-item');
            HeightElements('.view-noticias-unidades .view-content .views-row');
            HeightElements('.page-resultados-unidad .view-solr-noticias .views-row');
            HeightElements('.view-directores-y-comandantes .view-content .views-row');

                        //Imagen Bloques-subsitio.
            jQuery('.node-type-subsitio .field-name-subsitio-items .view-subsitio .views-row').each(function(){
                var HeightText = jQuery(this).children('.views-fieldset').children('.fieldset').outerHeight();
                var HeightImage = jQuery(this).children('.views-fieldset').children('.views-field-field-unica-imagen').outerHeight();

                if (HeightText > HeightImage) {
                    jQuery(this).children('.views-fieldset').children('.views-field-field-unica-imagen').children('.field-content').height(HeightText);
                }
            });
        }
    }

    // Method jQuery to add the behaviours for the History Block
    Drupal.behaviors.history_timeline_behaviours = {
        attach: function (context, settings) {
            if ($('.view-id-timeline.view-display-id-block_1').length > 0 ) {

                // Add numbers
                var count = $('.view-id-timeline.view-display-id-block_1').find('.history-title').length;
                $.each( $('.view-id-timeline.view-display-id-block_1').find('.history-title'), function( i, val) {
                  $(this).find('.views-field-title').prepend('<div class="counts">'+count+'</div>');
                  count--;
                });

                $('.history-title').click(function(){
                    $(this).siblings('.history-body').slideToggle(500);
                    $(this).toggleClass('active');
                });
            }
        }
    }

    //Coronel sin datos.
    if(jQuery('.view-mode-oficinas_asesoras .group-atencion').length === 0){
        jQuery('.view-mode-oficinas_asesoras .field-name-field-director').addClass('info-director');
    }

    if(jQuery('.view-mode-control_interno .group-resumen').length === 0){
        jQuery('.view-mode-control_interno .field-name-field-director').addClass('info-director-full-width');
    }

    $('input[required],textarea[required]').each(function(){
        jQuery(this).focusout(function()
        {

            if(jQuery(this).val()=='')
            {
                if(!this.tooltip)
                {


                    this.tooltip=jQuery('<div><div>');
                    this.tooltip.text('Completa este campo');

                    var thisPosition = jQuery(this).position();
                    this.tooltip.css({
                        position: 'absolute',
                        top: (thisPosition.top+jQuery(this).innerHeight())+10,
                        left: thisPosition.left,//+(jQuery(this).innerWidth()/2)-25,
                        //  width: jQuery(this).innerWidth(),
                        padding: '5px 17px 5px 15px',
                        'background-color': '#f6f4f2',
                        color: '#333',
                        'font-size': 15,
                        'box-shadow': '0px 0px 4px 1px #EEE',
                        'box-sizing': 'border-box',
                        'letter-spacing': '1px',
                        border: '1px solid #DDD',
                        'border-radius': '5px',

                    });

                    jQuery('body').append(this.tooltip);

                    this.tooltipArrow=jQuery('<div><div>');
                    this.tooltipArrow.css({
                        position: 'absolute',
                        'border-style': 'solid',
                        'border-width': '0 5px 5px 5px',
                        'border-color': 'transparent transparent #DDD transparent',
                        top: -5,
                        left: 20,
                    });

                    jQuery(this.tooltip).append(this.tooltipArrow);
                }

                this.tooltip.fadeIn(300);
                this.tooltip.delay(300).delay(1000).fadeOut(300);
            }
        });
        jQuery(this).focusin(function()
        {
            if(this.tooltip)
            {
                jQuery(this.tooltip).css('display','none');
            }
        });
    });

    Drupal.behaviors.glosario_behaviours = {
        attach: function (context, settings) {
            jQuery('.lexicon-links a').click(function(){
                jQuery('.lexicon-links a').removeClass('active-new');
                jQuery(this).addClass('active-new');
            });
            jQuery(window).scroll(function() {
                var PositionScrollTop = $(window).scrollTop();
                var PositionLetter = jQuery('.region-content').position().top;
                if (PositionScrollTop > PositionLetter) {
                    jQuery('.lexicon-links').addClass('fixed');
                }
                else {
                    jQuery('.lexicon-links').removeClass('fixed');
                }
            });

        }
    }
    Drupal.behaviors.menu_user_behaviours = {
        attach: function (context, settings) {
            if (jQuery('.menu-add-unidad-node').length > 0 ) {
                jQuery('.block-menu-menu-menu-topbar').addClass('user-menu');
            }

            jQuery('.menu-add-unidad-node .menu-list-1').click(function(event){
                jQuery('.menu-add-unidad-node ul.user-menu').toggleClass('menu-list-1');
            });
            jQuery('.menu-add-unidad-node .menu-editor-creation').click(function(){
                jQuery(this).toggleClass('active');
                jQuery('.menu-add-unidad-node ul.user-submenu').slideToggle(1000);
            });
        }
    }

    //Remove actice Ancla.
    Drupal.behaviors.menu_ancla_behaviours = {
        attach: function (context, settings) {
            jQuery('.block-menu li a').each(function(i){
                var SearchPlus = jQuery(this).attr('href');

                if(SearchPlus.indexOf("#") != -1) {
                    jQuery(this).removeClass('active');
                }
            });
        }
    }

    //Height breadcrumb
    Drupal.behaviors.breadcrumb_height_behaviours = {
        attach: function (context, settings) {
            if (jQuery('.block-seed-tools-seed-breadcrumb').length > 0){
                var heightBreadcrumb = jQuery('.block-seed-tools-seed-breadcrumb').outerHeight(true);

                jQuery('.not-front #preface-first').css({
                    'padding-top' : heightBreadcrumb,
                });
            }
        }
    }

    Drupal.behaviors.boton_behaviours = {
        attach: function (context, settings) {
            jQuery('#block-bean-discapacidad').click(function(){
                // jQuery('.region-blockgroup-accesibilidad').slideToggle(1000);
                jQuery('.region-blockgroup-accesibilidad').toggleClass('mostrar');
            });
        }
    }

})(jQuery);

// // Place any jQuery/helper plugins in here.
