(function($) {
    wp.customize.bind('ready', function() {
        // Map sections to their CSS selectors in the preview window
        var sectionMap = {
            'blog_over_topbar_section': '.blog-over-topbar',
            'blog_over_ticker_section': '#ticker',
            'blog_over_hero_section': '.blog-over-hero-wrapper',
            'blog_over_featured_section': '.blog-over-featured-links-wrapper',
            'Blog_Over_section': '#primary, .blog-over-main-content',
            'blog_over_tabbed_magazine_section': '.blog-over-tabbed-magazine',
            'blog_over_feature_story_section': '.blog-over-feature-story-wrapper',
            'blog_over_advertisement_section': '.blog-over-ad-banner-wrapper',
            'blog_over_youmissed_section': '.blog-over-missed-wrapper',
            'blog_over_footer_section': '.site-footer'
        };

        // Bind expanded event for each mapped section
        $.each(sectionMap, function(sectionId, selector) {
            wp.customize.section(sectionId, function(section) {
                section.expanded.bind(function(isExpanded) {
                    if (isExpanded) {
                        wp.customize.previewer.send('blog-over-scroll-to', selector);
                    }
                });
            });
        });
    });
})(jQuery);
