jQuery(document).ready(function($) {
    "use strict";
 
        $('#main').fadeTo(500, 1);
    $('.blog-post-image img, .img-featured-posts-image img, .featured-posts-image img, .small-image img, .tv-big-image img, .multi-category-image img').wrap("<div class='" + image_effect + "'></div>");
    $('#secondary .home-widget').each(function() {
        $(this).removeClass('two-parts three-parts four-parts').addClass('one-part')
    });
    //wp-widgets width
    $('.widget_text, .widget_recent_comments, .widget_recent_entries, .widget_calendar, .widget_nav_menu, .widget_pages, .widget_archive, .widget_links, .widget_meta, .widget_tag_cloud, .widget_rss, .widget_search, .widget_categories, .woocommerce, .widget[id*=bbp_], .widget[id*=bp_]').each(function() {
        $(this).closest('.home-widget').addClass('one-part');
    });
    $('.img-featured-title h2 a, .super-slider-title a, .carousel-title a').each(function() {
        var html = $(this).html();
        var split = html.split(" ");
        if (split.length > 3) {
            split[split.length - 1] = "<span class='first-word'>" + split[split.length - 1] + "</span>";
            split[split.length - 2] = "<span class='first-word'>" + split[split.length - 2] + "</span>";
            $(this).html(split.join(" "));
        } else {}
    });
    $('.widget-title:not(:has(a)), .widget-title a').not('.popular-part .widget-title').each(function() {
        var html = $(this).html();
        var split = html.split(" ");
        split[0] = "<span class='first-word'>" + split[0] + "</span>";
        $(this).html(split.join(" "));
    });

    $(window).load(function() {
        $('.widget-title').not('.popular-part .widget-title').each(function(){
            var gradientwidth = $(this).find('.first-word').width() + 120;
            var gradientcolor = $(this).find('.first-word').css('color');

            $('<div/>', {class: 'widget-title-gradient-line', }).appendTo(this);

             $(this).find('.widget-title-gradient-line').css('width', gradientwidth);     
           

        });
    });

        //ticker

        function tick() {
            var first_tick = $("ul.ticker-list li:first").width();
            $("ul.ticker-list li:first").animate({
                marginLeft: -first_tick
            }, 800, function() {
                $(this).detach().appendTo("ul.ticker-list").removeAttr("style");
                var first_tick = $("ul.ticker-list li:first").width();
            });
        }

        function tak() {
            var last_tick = $("ul.ticker-list li:last-child").width();
            $("ul.ticker-list li:first").animate({
                marginLeft: last_tick
            }, 800, function() {
                $("ul.ticker-list li:last-child").detach().prependTo("ul.ticker-list");
                $("ul.ticker-list li").removeAttr("style");
                var last_tick = $("ul.ticker-list li:last-child").width();
            });
        }
        $('.ticker-right').click(function() {
            tick();
        });
        $('.ticker-left').click(function() {
            tak();
        });

        var interval = setInterval(tick, 5000);

        $('ul.ticker-list li, .ticker-left, .ticker-right').hover(function() {
            clearInterval(interval);
        }, function() {
            interval = setInterval(tick, 5000);
        });
        

        function ticket_width() {
            $('#ticker-list-box').css('width', $('#ticker').width() - $('.ticker-heading').outerWidth() - 20);
        }
        $(window).load(function() {
        ticket_width();
        $(window).resize(ticket_width);
        });




    //carousel
    function carousel_init() {
        if ($('.carousel').length) {
            $('.carousel').each(function() {
                function normalcarousel_grid() {
                    if ($(widget_size).hasClass('one-part')) {
                        return (window.innerWidth < 700) ? 1 : (window.innerWidth < 1024) ? 1 : 1;
                    } else {
                        return (window.innerWidth < 700) ? 1 : (window.innerWidth < 1024) ? 3 : carouselitems;
                    }
                }
                var resizeTimer;
                $(window).on('resize', function(e) {
                    clearTimeout(resizeTimer);
                    resizeTimer = setTimeout(function() {
                        $('.carousel').each(function() {
                            function normalcarousel_grid1() {
                                if ($(widget_size).hasClass('one-part')) {
                                    return (window.innerWidth < 700) ? 1 : (window.innerWidth < 1024) ? 1 : 1;
                                } else {
                                    return (window.innerWidth < 700) ? 1 : (window.innerWidth < 1024) ? 3 : carouselitems;
                                }
                            }
                            var widget_size = $(this).closest('.home-widget');
                            if ($(widget_size).hasClass('one-part')) {
                                var carouselitems = 1;
                            } else if ($(widget_size).hasClass('two-parts')) {
                                var carouselitems = 3;
                            } else if ($(widget_size).hasClass('three-parts')) {
                                var carouselitems = 4;
                            } else if ($(widget_size).hasClass('four-parts')) {
                                var carouselitems = 5;
                            }
                            var gridSize = normalcarousel_grid1();
                            $(this).data('flexslider').vars.minItems = gridSize;
                            $(this).data('flexslider').vars.maxItems = gridSize;
                            $(this).data('flexslider').vars.move = gridSize;
                        });
                    }, 200);
                });
                var widget_size = $(this).closest('.home-widget');
                if ($(widget_size).hasClass('one-part')) {
                    var carouselitems = 1;
                } else if ($(widget_size).hasClass('two-parts')) {
                    var carouselitems = 3;
                } else if ($(widget_size).hasClass('three-parts')) {
                    var carouselitems = 4;
                } else if ($(widget_size).hasClass('four-parts')) {
                    var carouselitems = 5;
                }
                $(this).flexslider({
                    animation: 'slide',
                    itemWidth: 210,
                    itemMargin: 10,
                    minItems: normalcarousel_grid(),
                    maxItems: normalcarousel_grid(),
                    move: normalcarousel_grid(),
                    slideshow: false,
                    controlNav: false,
                    directionNav: true,
                    start: function(slider) {
                        slider.fadeTo(1000, 1);
                        slider.removeClass('loading');
                    }
                });
            });
        }
    }
    carousel_init();
    //Masonry script
    if ($('#fullwidth').length) {
        var fullwidthmas = $('#fullwidth').masonry({
            columnWidth: function(containerWidth) {
                return containerWidth / 4;
            },
            itemSelector: '.home-widget',
            animationOptions: {
                duration: 30
            }
        });
        fullwidthmas.imagesLoaded(function() {
            setTimeout(function() {
                fullwidthmas.masonry();
                setTimeout(function() {
                    fullwidthmas.masonry();
                }, 1500);
            }, 10);
        });
        $(window).load(function() {
            $('.trending-posts ul, .newsroll ul.one-parts-height').height('20px');
            $('.newsroll ul.two-parts-height').height((((($('#main').width() - 10) * 0.25) - 10) / 0.877));
            setTimeout(function() {
                $('#fullwidth').masonry().masonry('reloadItems');
            }, 10);
        });
        $(window).resize(function() {
            setTimeout(function() {
                $('.trending-posts ul, .newsroll ul.one-parts-height').height('20px');
                $('.newsroll ul.two-parts-height').height((((($('#main').width() - 10) * 0.25) - 10) / 0.877));
                fullwidthmas.masonry();
                setTimeout(function() {
                    fullwidthmas.masonry();
                }, 1500);
            }, 10);
        });
    }

    function debounce(func, wait, immediate) {
        var timeout;
        return function() {
            var context = this,
                args = arguments;
            var later = function() {
                timeout = null;
                if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
        };
    };
    var myEfficientFn = debounce(function() {
        $('.carousel').each(function() {
            $(this).data('flexslider').resize();
        });
    }, 250);
    $(window).load(function() {
    window.addEventListener('resize', myEfficientFn);
    });
    //share-icons
    function sharewidthresponsive() {
        var sharewidthfull = $('.share-post').outerWidth(true);
        var sharewidth = $('.share-title').outerWidth(true);
        $('.share-post ul').css('width', sharewidthfull - sharewidth - 2);
    };
    sharewidthresponsive();
    $(window).resize(sharewidthresponsive);
    //fixed-menu    
    var aboveHeight = $('#nav-wrapper').offset().top - $('#wpadminbar').height();
    $(window).scroll(function() {
        if ($(window).scrollTop() > aboveHeight) {
            $('.show-menu').addClass('fixed-menu').trigger('menuchanged');
        } else {
            $('.show-menu').removeClass('fixed-menu').trigger('menuchanged');
        }
    });
    //fixed-floating-share    
    if ($('.floating-share-icons').length) {
        $('.floating-share-icons').height($('#post-content').height() + $('.title-and-subtitle-wrap').height());
        $(window).scroll(function() {
            $('.floating-share-icons').height($('#post-content').height() + $('.title-and-subtitle-wrap').height());
            var above = ($('.floating-share-icons').offset().top) - ($('#wpadminbar').height() + $('#nav-wrapper .fixed-menu').height());
            if ($(window).scrollTop() - above + 20 > 0 && ($(window).scrollTop() - above) - ($('.title-and-subtitle-wrap').height() + $('#post-content').height() - $('.floating-share-icons ul').height() - $('#wpadminbar').height() + 20) < 0) {
                $('.floating-share-icons ul').css('position', 'fixed').css('top', $('#nav-wrapper .fixed-menu').height() + $('#wpadminbar').height() + 20).css('bottom', 'auto');
            } else if ($(window).scrollTop() - above > 0 && ($(window).scrollTop() - above) - ($('.title-and-subtitle-wrap').height() + $('#post-content').height() - $('.floating-share-icons ul').height() - $('#wpadminbar').height() - 20) > 0) {
                $('.floating-share-icons ul').css('position', 'absolute').css('top', 'auto').css('bottom', -20);
            } else {
                $('.floating-share-icons ul').css('position', 'absolute').css('top', 0).css('bottom', 'auto');
            }
        });
    }
    //sidebar height
    function sidebarheight() {
        $(window).load(function() {
            var fullsize = $('#wrapper').width();
            var primaryheight = $('#primary').height();
            if (fullsize > 1024) {
                $('#secondary').css('min-height', primaryheight);
            } else {
                $('#secondary').css('min-height', 0);
            }
        });
    }

    $(window).load(function() {
        setTimeout(function() {
            sidebarheight();
        }, 500);
    });
    $(window).resize(sidebarheight);
    //fixed-sidebar-last widget
    $(window).load(function() {
        if ($('#secondary.stickylastwidget .home-widget:last-child').length) {
            var widgetaboveHeight = $('#secondary .home-widget:last-child ').offset().top - ($('#wpadminbar').height() + $('#nav-wrapper .show-menu').height());
            if ($('#navigation').hasClass('show-menu')) {
                $('#secondary .home-widget:last-child').addClass('navigation-has-menu');
            }
            var primaryheight = $('#primary').height();
            var secondaryheight = 0;
            $('#secondary .home-widget').each(function() {
                secondaryheight = $(this).height();
            });
            //fixed widget in #secondary area           
            $(window).scroll(function() {
                if (primaryheight - secondaryheight < 0) {
                    $('#secondary .fixed-widget').css('position', 'relative');
                    $('#secondary .home-widget:last-child ').css('top', '0');
                } else {
                    if ($(window).scrollTop() > widgetaboveHeight && primaryheight > $('#secondary').height()) {
                        $('#secondary .home-widget:last-child').addClass('fixed-widget');
                    } else {
                        $('#secondary .home-widget:last-child ').removeClass('fixed-widget');
                    }
                    if ($('#footer').offset().top - ($(window).scrollTop() + $('.fullwidth ').not('.popular-part').height() + $('#secondary .home-widget:last-child').height() + $('#navigation.fixed-menu').height() + 70) < 0) {
                        $('#secondary .home-widget:last-child ').css('top', $('#footer').offset().top - ($(window).scrollTop() + $('.fullwidth ').not('.popular-part').height() + $('#secondary .home-widget:last-child').height() + 40));
                    } else {
                        $('#secondary .home-widget:last-child ').css('top', '')
                    }
                }
            });
        };
    });

    function fixedwidgetwidth() {
        var secondarywidth = $('#secondary').width();
        $('#secondary .home-widget:last-child ').css('max-width', secondarywidth);
    }
    fixedwidgetwidth();
    $(window).resize(fixedwidgetwidth);
    //and fullwidth image
    function superslidermargin() {
        $('.home-widget.body-super-slider, .fullwidth-ticker, .fullwidth-image').css('max-width', $(window).width());
        $('.home-widget.body-super-slider, .fullwidth-ticker, .fullwidth-image').css('margin-left', -($('#main').offset().left + parseInt($('#main').css('padding-left'))));
    };
    superslidermargin();
    $(window).load(function() {
        superslidermargin();
    });
    $(window).resize(superslidermargin);


    //scroll effects
    $(window).scroll(function() {
        var informer_magazinetop = $(this).scrollTop();
        var informer_magazineheight = $(this).height();
        var informer_magazinebottom = informer_magazinetop + informer_magazineheight;
        $('#fullwidth .home-widget').each(function() {
            var geget = $(this).offset().top;
            if (informer_magazinebottom > geget && geget > informer_magazineheight) {
                $(this).find('.widget').addClass(widget_fx);
            }
        });
    });
    $(window).load(function() {
        $('.score-line').each(function() {
            $(this).find('.score-width').addClass('active');
        });
    });
    //super-slider
    function super_slider_init() {
        if ($('.super-slider').length) {
            $('.super-slider').each(function() {
                function normalcarousel_grid() {
                return (window.innerWidth < 700) ? 1 : (window.innerWidth < 1024) ? 2 : (window.innerWidth < 1350) ? 3 : (window.innerWidth < 1550) ? 3 : 3;                  
                }
                var resizeTimer;
                $(window).on('resize', function(e) {
                    clearTimeout(resizeTimer);
                    resizeTimer = setTimeout(function() {
                        $('.super-slider').each(function() {
                            function normalcarousel_grid1() {

                                    return (window.innerWidth < 700) ? 1 : (window.innerWidth < 1024) ? 2 : (window.innerWidth < 1350) ? 3 : (window.innerWidth < 1550) ? 3 : 3;
                                
                            }
    
                            var gridSize = normalcarousel_grid1();
                            $(this).data('flexslider').vars.minItems = gridSize;
                            $(this).data('flexslider').vars.maxItems = gridSize;
                            $(this).data('flexslider').vars.move = gridSize;
                        });
                    }, 200);
                });

                $(this).flexslider({
                    animation: 'slide',
                    itemWidth: 210,
                    itemMargin: 0,
                    minItems: normalcarousel_grid(),
                    maxItems: normalcarousel_grid(),
                    move: normalcarousel_grid(),
                    slideshow: false,
                    controlNav: false,
                    directionNav: true,
                    start: function(slider) {
                        slider.fadeTo(1000, 1);
                        slider.removeClass('loading');
                    }
                });
            });
        }
    }
    //super_slider_init();
    $(window).load(function() {
        super_slider_init();
     });

    //video type page carousel
    if ($('.tv-carousel').length) {
        var tv_carousel;
        $(window).load(function() {
            function tv_carousel_grid() {
                return (window.innerWidth < 700) ? 3 : (window.innerWidth < 1024) ? 4 : 5;
            }
            $('.tv-carousel').flexslider({
                animation: 'slide',
                itemWidth: 210,
                itemMargin: 15,
                useCSS: false,
                minItems: tv_carousel_grid(),
                maxItems: tv_carousel_grid(),
                move: tv_carousel_grid(),
                slideshow: false,
                controlNav: false,
                directionNav: true,
                start: function(slider) {
                    tv_carousel = slider;
                },
                after: function(slider) {
                    tv_carousel.resize();
                }
            });
            $(window).resize(function() {
                var gridSize = tv_carousel_grid();
                tv_carousel.vars.minItems = gridSize;
                tv_carousel.vars.maxItems = gridSize;
            });
        });
    }
    //type pages ajax
    $('.term-post-format-video').on('click', '.ajax', function(e) {
        e.preventDefault();
        var post_id = $(this).attr("data-number");
        jQuery.ajax({
            post: post_id,
            type: "POST",
            data: {
                id: post_id
            },
            success: function(output) {
                $(".tv-video-wrapper").replaceWith($('.tv-video-wrapper', output));
                $(".tv-format-title").replaceWith($('.tv-format-title', output));
                $(".tv-format-subtitle").replaceWith($('.tv-format-subtitle', output));
            }
        });
    });
    $(window).load(function() {
        $('.term-post-format-gallery').on('click', '.ajax', function(e) {
            e.preventDefault();
            var post_id = $(this).attr("data-number");
            jQuery.ajax({
                post: post_id,
                type: "POST",
                data: {
                    id: post_id
                },
                success: function(output) {
                    $(".tv-video-wrapper").replaceWith($('.tv-video-wrapper', output));
                    $(".tv-format-title").replaceWith($('.tv-format-title', output));
                    $(".tv-format-subtitle").replaceWith($('.tv-format-subtitle', output));
                    $('.post-page-gallery-thumbnails').flexslider({
                        animation: 'slide',
                        controlNav: false,
                        animationLoop: false,
                        slideshow: false,
                        itemWidth: 166,
                        itemMargin: 0,
                        minItems: 4,
                        maxItems: 4,
                        move: 4,
                        directionNav: true,
                        asNavFor: '.post-page-gallery-slider',
                        start: function(slider) {
                            slider.fadeTo(1000, 1);
                            slider.removeClass('loading');
                        }
                    });
                    $('.post-page-gallery-slider').flexslider({
                        animation: slide_picker,
                        controlNav: false,
                        animationLoop: false,
                        slideshow: false,
                        sync: '.post-page-gallery-thumbnails',
                        start: function(slider) {
                            slider.fadeTo(1000, 1);
                            slider.removeClass('loading');
                        }
                    });
                }
            });
        });
    });
    $('.term-post-format-video, .term-post-format-gallery').on('click', '.pagination a', function(e) {
        e.preventDefault();
        var link = $(this).attr('href');
        $('.tv-page-widget').append('<div class="more-posts"></div>');
        $('.pagination').replaceWith('<div class="load-content"><div class="load-circle"></div></div>');
        $('.more-posts').load(link + ' .tv-page-widget li, .pagination', function() {
            $('.more-posts li').hide().detach().appendTo('.tv-page-widget ul').css('opacity', '0').fadeIn().fadeTo('slow', 1);
            $('.more-posts .pagination').css('opacity', '0').detach().appendTo('.tv-page-widget').fadeTo('slow', 1);
            $('.more-posts').remove();
            $('.load-content').remove();
        });
    });
    $('.archive #primary, .blog #primary').on('click', '.pagination a', function(e) {
        e.preventDefault();
        var link = $(this).attr('href');
        $('#blog-list').append('<div class="more-posts"></div>');
        $('.pagination').replaceWith('<div class="load-content"><div class="load-circle"></div></div>');
        $('.more-posts').load(link + ' #blog-list li, .pagination', function() {
            $('.more-posts li').hide().detach().appendTo('#blog-list ul').css('opacity', '0').fadeIn().fadeTo('slow', 1);
            $('.more-posts .pagination').css('opacity', '0').detach().appendTo('#blog-list').fadeTo('slow', 1);
            $('.more-posts').remove();
            $('.load-content').remove();
        });
    });
    //keyboard navigation next prev         
    $(document).keydown(function(e) {
        var url = false;
        if (e.which == 37) { // Left arrow key code
            url = $('.previous-title a').attr('href');
        } else if (e.which == 39) { // Right arrow key code
            url = $('.next-title a').attr('href');
        }
        if (url) {
            window.location = url;
        }
    });
    //menu button for responsive mobile
    $("#mob-menu .mob-menu-button").click(function() {
        $("#main-nav ul, #navigation").toggleClass("active");
        $('#mob-menu').toggleClass("active");
        $('body').toggleClass("mob-menu-active");
    });
    //Gallery slider
    $(window).load(function() {
        $('.post-page-gallery-thumbnails').flexslider({
            animation: 'slide',
            controlNav: false,
            animationLoop: false,
            slideshow: false,
            itemWidth: 166,
            itemMargin: 0,
            minItems: 4,
            maxItems: 4,
            move: 4,
            directionNav: true,
            asNavFor: '.post-page-gallery-slider',
            start: function(slider) {
                slider.fadeTo(1000, 1);
                slider.removeClass('loading');
            }
        });
        $('.post-page-gallery-slider').flexslider({
            animation: slide_picker,
            controlNav: false,
            animationLoop: false,
            slideshow: false,
            sync: '.post-page-gallery-thumbnails',
            start: function(slider) {
                slider.fadeTo(1000, 1);
                slider.removeClass('loading');
            }
        });
    });
    //super-menu scripts
    $('#header .menu-item-has-children').append('<span class="subsignmeni"></span>');

    function mobile_menu_sub() {
        if ($(window).width() < 700) {
            $('.subsignmeni').off().on('click', function() {
                $(this).prev('.sub-menu-wrapper, .sub-meni').slideToggle(100).toggleClass('mob-cat');
            });
        }
    }
    mobile_menu_sub();
    $(window).resize(mobile_menu_sub);

    function hover_intent_menu() {
        function mousein_triger() {
            if ($(window).width() > 700) {
                $(".menu-item").removeClass("active");
                $(this).addClass("active");
                $(this).find('.sub-menu-wrapper').css('visibility', 'hidden').show();
                $(this).find('.sub-menu-wrapper').height($(this).find('.sub-menu').height() + $(this).find('.menu-links.inside-menu').outerHeight());
                $(this).find('.sub-menu-wrapper').css('min-height', $(this).find('.menu-links.inside-menu').outerHeight());
                $(this).find('.sub-menu-wrapper').css('visibility', 'visible').hide();
                $(this).children('.sub-menu-wrapper, .sub-meni').fadeIn(150);
            } else {
                $('.menu-item').removeClass('active');
                $('.sub-menu-wrapper').removeAttr('style');
            }
        }

        function mouseout_triger() {
            if ($(window).width() > 700) {
                $(this).children('.sub-menu-wrapper, .sub-meni').fadeOut(150);
            }
        }
        var settings = {
            sensitivity: 4,
            interval: 150,
            timeout: 300,
            over: mousein_triger,
            out: mouseout_triger
        };
        $('.menu-item').not('.inside-menu .menu-item').hoverIntent(settings);
        var settings1 = {
            sensitivity: 4,
            interval: 0,
            timeout: 300,
            over: mousein_triger,
            out: mouseout_triger
        };
        $('.inside-menu .menu-item').hoverIntent(settings1);
    }
    hover_intent_menu();
    $(window).resize(hover_intent_menu);
    //autoload for all
    $(window).scroll(function() {
        $('.auto-load').each(function() {
            var loadHeight = $(this).offset().top;
            if ($(window).scrollTop() > loadHeight - $(window).height()) {
                $(this).find('a').trigger("click");
            }
        });
    });
    //load more for blogroll1
    if ($('.widget_blog_category_informer_magazine .pagination').length) {
        $('.widget_blog_category_informer_magazine').off().on('click', '.pagination a', function(e) {
            e.preventDefault();
            var parent = $(this).parents('.widget_blog_category_informer_magazine').attr('id');
            parent = '#' + parent;
            var link = $(this).attr('href');
            $(parent + '.widget_blog_category_informer_magazine').append('<div class="more-posts"></div>');
            $(parent).find('.pagination').replaceWith('<div class="load-content"><div class="load-circle"></div></div>');
            $(parent).find('.more-posts').load(link + ' ' + parent + ' .blog-category li, ' + parent + ' .pagination', function() {
                $(parent).find('.more-posts li').hide().detach().appendTo(parent + ' .blog-category ul').css('opacity', '0').fadeIn().fadeTo('slow', 1);
                $(parent).find('.more-posts .pagination').css('opacity', '0').detach().appendTo(parent + ' .blog-category').fadeTo('slow', 1);
                $(parent).find('.more-posts').remove();
                $(parent).find('.load-content').remove();
                if ($('#fullwidth').length) {
                    $('#fullwidth').masonry().masonry('reloadItems');
                    setTimeout(function() {
                        $('#fullwidth').masonry().masonry('reloadItems');
                    }, 500);
                }
            });
        });
    }
    //load more for featured big images
    if ($('.widget_img_featured_category_informer_magazine .pagination').length) {
        $('.widget_img_featured_category_informer_magazine').off().on('click', '.pagination a', function(e) {
            e.preventDefault();
            var parent = $(this).parents('.widget_img_featured_category_informer_magazine').attr('id');
            parent = '#' + parent;
            var link = $(this).attr('href');
            $(parent + '.widget_img_featured_category_informer_magazine').append('<div class="more-posts"></div>');
            $(parent).find('.pagination').replaceWith('<div class="load-content"><div class="load-circle"></div></div>');
            $(parent).find('.more-posts').load(link + ' ' + parent + ' .img-featured-category.big li, ' + parent + ' .pagination', function() {
                $(parent).find('.more-posts li').hide().detach().appendTo(parent + ' .img-featured-category.big ul').css('opacity', '0').fadeIn().fadeTo('slow', 1);
                $(parent).find('.more-posts .pagination').css('opacity', '0').detach().appendTo(parent + ' .img-featured-category.big').fadeTo('slow', 1);
                $(parent).find('.more-posts').remove();
                $(parent).find('.load-content').remove();
                if ($('#fullwidth').length) {
                    $('#fullwidth').masonry().masonry('reloadItems');
                    setTimeout(function() {
                        $('#fullwidth').masonry().masonry('reloadItems');
                    }, 500);
                }
            });
        });
    }
    //load more for featured huge images
    if ($('.widget_huge_img_featured_category_informer_magazine .pagination').length) {
        $('.widget_huge_img_featured_category_informer_magazine').off().on('click', '.pagination a', function(e) {
            e.preventDefault();
            var parent = $(this).parents('.widget_huge_img_featured_category_informer_magazine').attr('id');
            parent = '#' + parent;
            var link = $(this).attr('href');
            $(parent + '.widget_huge_img_featured_category_informer_magazine').append('<div class="more-posts"></div>');
            $(parent).find('.pagination').replaceWith('<div class="load-content"><div class="load-circle"></div></div>');
            $(parent).find('.more-posts').load(link + ' ' + parent + ' .img-featured-category.huge li, ' + parent + ' .pagination', function() {
                $(parent).find('.more-posts li').hide().detach().appendTo(parent + ' .img-featured-category.huge ul').css('opacity', '0').fadeIn().fadeTo('slow', 1);
                $(parent).find('.more-posts .pagination').css('opacity', '0').detach().appendTo(parent + ' .img-featured-category.huge').fadeTo('slow', 1);
                $(parent).find('.more-posts').remove();
                $(parent).find('.load-content').remove();
                if ($('#fullwidth').length) {
                    $('#fullwidth').masonry().masonry('reloadItems');
                    setTimeout(function() {
                        $('#fullwidth').masonry().masonry('reloadItems');
                    }, 500);
                }
            });
        });
    }
    //smart ones
    
        function smartblocks() {
            $('.trending-posts ul, .newsroll ul.one-parts-height, .newsroll ul.two-parts-height').height('20px');
            setTimeout(function() {
                $('#fullwidth .newsroll').each(function() {
                    var $tdiv = $(this).parents('.home-widget');
                    var $nex = $('.home-widget').filter(function() {
                        return $(this).offset().top >= ($tdiv.offset().top + $tdiv.height()) && $(this).offset().left + $(this).width() - $tdiv.offset().left >= 0
                    }).eq(0);
                    if ($nex.length) {
                        var additionHeight = $nex.offset().top - ($tdiv.offset().top + $tdiv.height()) + $tdiv.find('.newsroll ul').height();
                        if ($nex.offset().top > $tdiv.offset().top + $tdiv.height()) {
                            $tdiv.find('.newsroll ul').height(additionHeight);
                        }
                    } else {
                        var $nex = $('#footer');
                        var additionHeight = $nex.offset().top - ($tdiv.offset().top + $tdiv.height()) + $tdiv.find('.newsroll ul').height();
                        $tdiv.find('.newsroll ul').height(additionHeight - 40);
                    }
                });
                $('#fullwidth .trending-posts').each(function() {
                    var $tdiv = $(this).parents('.home-widget');
                    var $nex = $('.home-widget').filter(function() {
                        return $(this).offset().top >= ($tdiv.offset().top + $tdiv.height()) && $(this).offset().left + $(this).width() - $tdiv.offset().left >= 0
                    }).eq(0);
                    if ($nex.length) {
                        var additionHeight = $nex.offset().top - ($tdiv.offset().top + $tdiv.height()) + $tdiv.find('.trending-posts ul').height();
                        if ($nex.offset().top > $tdiv.offset().top + $tdiv.height()) {
                            $tdiv.find('.trending-posts ul').height(additionHeight);
                        }
                    } else {
                        var $nex = $('#footer');
                        var additionHeight = $nex.offset().top - ($tdiv.offset().top + $tdiv.height()) + $tdiv.find('.trending-posts ul').height();
                        $tdiv.find('.trending-posts ul').height(additionHeight - 40);
                    }
                });
            }, 350);
        }


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

        $('.newsroll ul.two-parts-height').height($('#main').width() / 2.86);
        $(window).load(function() {
            $('.trending-posts ul, .newsroll ul').height('20px');
            $('#fullwidth').masonry().masonry('reloadItems');
            smartblocks();
            setTimeout(function() {
                $('.trending-posts ul, .newsroll ul').height('20px');
                $('#fullwidth').masonry().masonry('reloadItems');
                smartblocks();
            }, 500);
        });

        var resizeTimer;
        $(window).on('resize', function(e) {
            clearTimeout(resizeTimer);
            resizeTimer = setTimeout(function() {
                $('.trending-posts ul, .newsroll ul').height('20px');
                $('#fullwidth').masonry().masonry('reloadItems');
                smartblocks();
                setTimeout(function() {
                    $('.trending-posts ul, .newsroll ul').height('20px');
                    $('#fullwidth').masonry().masonry('reloadItems');
                    smartblocks();
                }, 500);
            }, 100);
        });

    //responsive widgets layout
    function checkWidth() {
        if ($('#fullwidth').length) {
            var fullsize = $('#main').width();
            var id,
                gid = 0;
            if (fullsize < 984 && fullsize > 631) {
                if ($('#fullwidth .responsive-part').length) {} else {
                    $('#fullwidth .one-part').each(function() {
                        id = 'responsive-part-' + gid++;
                        $(this).before('<div class="responsive-part ' + id + '"></div>').appendTo('#fullwidth').data('responsive-part', id);
                    });
                }
            } else if (fullsize < 631) {
                if ($('#fullwidth .responsive-part').length) {
                    $('#fullwidth .one-part').each(function() {
                        $(this).appendTo('.responsive-part.' + $(this).data('responsive-part')).unwrap().data('responsive-part', undefined);
                    });
                }
            } else if (fullsize > 984) {
                if ($('#fullwidth .responsive-part').length) {
                    $('#fullwidth .one-part').each(function() {
                        $(this).appendTo('.responsive-part.' + $(this).data('responsive-part')).unwrap().data('responsive-part', undefined);
                    });
                }
            }
        }
    }
    $(window).load(function() {
        checkWidth();
        var checkWidthvar = debounce(function() {
                checkWidth();
                super_slider_init();
                ticket_width();                  
                carousel_init();
                smartblocks();
                if ($('.super-slider').length) {
                  $('.super-slider').each(function() {
                    $(this).data('flexslider').resize();
                });

                }

                setTimeout(function() {
                    if ($('#fullwidth').length) {
                        jQuery('#fullwidth').masonry().masonry('reloadItems');
                        smartblocks();
                    }
                }, 300);
        }, 200);
        window.addEventListener('resize', checkWidthvar);
    });


}




        //this is only usable in customizer
        if ('undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh) {
            function titles_colors() {
                $('.widget_text, .widget_recent_comments, .widget_recent_entries, .widget_calendar, .widget_nav_menu, .widget_pages, .widget_archive, .widget_links, .widget_meta, .widget_tag_cloud, .widget_rss, .widget_search, .widget_categories, .woocommerce, .widget[id*=bbp_], .widget[id*=bp_]').each(function() {
                    $(this).closest('.home-widget').addClass('one-part');
                });
                $('.first-word').contents().unwrap();
                $('.first-word, .widget-title-gradient-line').remove();

                    super_slider_init();
                     $('.ticker-right').click(function() {
                        tick();
                    });
                    $('.ticker-left').click(function() {
                        tak();
                    });
                 ticket_width();                  
                carousel_init();
                smartblocks();
                setTimeout(function() {
                    if ($('#fullwidth').length) {
                        jQuery('#fullwidth').masonry().masonry('reloadItems');
                        smartblocks();
                        superslidermargin();
                    }
                }, 100);

                setTimeout(function() {
                    if ($('#fullwidth').length) {
                        jQuery('#fullwidth').masonry().masonry('reloadItems');
                        smartblocks();
                    }
                }, 1000);

                $('.img-featured-title h2 a, .super-slider-title a, .carousel-title a').not(':has(span)').each(function() {
                    var html = $(this).html();
                    var split = html.split(" ");
                    if (split.length > 3) {
                        split[split.length - 1] = "<span class='first-word'>" + split[split.length - 1] + "</span>";
                        split[split.length - 2] = "<span class='first-word'>" + split[split.length - 2] + "</span>";
                        $(this).html(split.join(" "));
                    } else {}
                });
                $('.widget-title').not('.popular-part .widget-title, :has(span), .widget-title a, :has(a)').each(function() {
                        var html = $(this).parents('.home-widget').find('.widget-title').text();
                        var split = html.split(" ");
                        if (split.length > 1) {
                        split[0] = "<span class='first-word'>" + split[0] + "</span>";
                         $(this).html(split.join(" "));                
                         $('<div/>', {class: 'widget-title-gradient-line', }).appendTo($(this).parents('.home-widget').find('.widget-title'));
                         var gradientwidth = $(this).parents('.home-widget').find('.first-word').width() + 120;
                         $(this).parents('.home-widget').find('.widget-title-gradient-line').css('width', gradientwidth);    
                    }else{
                        $(this).html(html);                      
                        $(this).parents('.home-widget').find('.widget-title').contents().filter(function() {
                                return this.nodeType == 3 && $.trim(this.textContent) != '';
                            }).wrap('<span class="first-word" />');
                        $('<div/>', {class: 'widget-title-gradient-line', }).appendTo($(this).parents('.home-widget').find('.widget-title'));
                        var gradientwidth = $(this).parents('.home-widget').find('.first-word').width() + 120;
                        $(this).parents('.home-widget').find('.widget-title-gradient-line').css('width', gradientwidth); 
                    }

                });

                $('.widget-title a').each(function() {
                    var id = $(this).parents('.home-widget').find('.widget').attr('id');
                    var link = $(this).attr('href');
                    var csa = $(this).attr('class');
                    var html = $(this).parents('.home-widget').find('.widget-title').text();
                    var split = html.split(" ");
                        split[0] = "<span class='first-word'>" + split[0] + "</span>";
                    $(this).parents('.home-widget').find('.widget-title').empty().wrapInner('<a class="' + csa + '" href="' + link + '">'+ split.join(" ") +'</a>').append('<div class="widget-title-gradient-line">');
                         var gradientwidth = $('#'+id).find('.first-word').width() + 120;
                         $('#'+id).find('.widget-title-gradient-line').css('width', gradientwidth);  


                });
    //fixed-sidebar-last widget

                var secondarywidth = $('#secondary').width();
        $('#secondary .home-widget:last-child ').css('max-width', secondarywidth);
        $('#secondary .home-widget:last-child ').removeClass('fixed-widget');
        if ($('#secondary.stickylastwidget .home-widget:last-child').length) {
            var widgetaboveHeight = $('#secondary .home-widget:last-child ').offset().top - ($('#wpadminbar').height() + $('#nav-wrapper .show-menu').height());
            if ($('#navigation').hasClass('show-menu')) {
                $('#secondary .home-widget:last-child').addClass('navigation-has-menu');
            }
            var primaryheight = $('#primary').height();
            var secondaryheight = 0;
            $('#secondary .home-widget').each(function() {
                secondaryheight = $(this).height();
            });
            //fixed widget in #secondary area           
            $(window).scroll(function() {
                if (primaryheight - secondaryheight < 0) {
                    $('#secondary .fixed-widget').css('position', 'relative');
                    $('#secondary .home-widget:last-child ').css('top', '0');
                } else {
                    if ($(window).scrollTop() > widgetaboveHeight && primaryheight > $('#secondary').height()) {
                        $('#secondary .home-widget:last-child').addClass('fixed-widget');
                    } else {
                        $('#secondary .home-widget:last-child ').removeClass('fixed-widget');
                    }
                    if ($('#footer').offset().top - ($(window).scrollTop() + $('.fullwidth ').not('.popular-part').height() + $('#secondary .home-widget:last-child').height() + $('#navigation.fixed-menu').height() + 70) < 0) {
                        $('#secondary .home-widget:last-child ').css('top', $('#footer').offset().top - ($(window).scrollTop() + $('.fullwidth ').not('.popular-part').height() + $('#secondary .home-widget:last-child').height() + 40));
                    } else {
                        $('#secondary .home-widget:last-child ').css('top', '')
                    }
                }
            });
        };

            }
            wp.customize.selectiveRefresh.bind('sidebar-updated', function() {
                titles_colors();
            });
            wp.customize.selectiveRefresh.bind('widget-updated', function() {
                titles_colors();
            });
            wp.customize.selectiveRefresh.bind('partial-content-moved', function() {
                titles_colors();
            });
            wp.customize.selectiveRefresh.bind('widget-added', function() {
                titles_colors();
            });
            wp.customize.selectiveRefresh.bind('partial-content-rendered', function() {
                titles_colors();
            });
        }

        


    

});