Jump to content

MediaWiki:Common.js: Difference between revisions

The comprehensive free global encyclopedia of CEOs, corporate leadership, and business excellence
Fixed 3D tag cloud - now auto-rotates continuously, uses Canvas for visibility, clickable tags, proper depth sorting
FIX: 1) Moved cloud up 30px for proper centering 2) Removed backface-visibility:hidden so text never disappears, just fades to 25% opacity when behind
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/**
/* Common.js - Site-wide JavaScript */
* Add statistics banner to account creation page
 
*/
/* Add copyright footer at the very bottom of page - single occurrence only */
(function() {
$(document).ready(function() {
     // Only run on Special:CreateAccount page
     // Remove any existing copyright footers first to prevent duplicates
     if (mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') {
     $('#footer-info-copyright, .ceo-copyright-footer').remove();
        return;
 
    }
    // Create the copyright footer
    var copyright = '<div class="ceo-copyright-footer" id="footer-info-copyright" style="text-align: center; padding: 20px; background: #f8f9fa; border-top: 1px solid #ddd; margin-top: 40px; font-size: 0.85em; line-height: 1.6;">Text is available under the <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="nofollow">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="/wiki/CEO.wiki:Terms_of_Use">Terms of Use</a>, <a href="/wiki/CEO.wiki:Privacy_Policy">Privacy Policy</a>, and all <a href="/wiki/CEO.wiki:General_disclaimer">disclaimers</a>. CEO.wiki is operated as an independent collaborative encyclopedia project and is not affiliated with Wikipedia or the Wikimedia Foundation. See our <a href="/wiki/CEO.wiki:Takedown_Request_Policy">Takedown Request Policy</a> for content concerns.</div>';


     // Get site statistics via API
     // Append to the very bottom of the body
     var api = new mw.Api();
     $('body').append(copyright);
});


    api.get({
/* 3D CEO Cloud - FIXED centering and visibility */
        action: 'query',
$(document).ready(function() {
        meta: 'siteinfo',
    var placeholder = document.getElementById('ceocloud-placeholder');
        siprop: 'statistics',
    if (!placeholder) return;
        format: 'json'
    }).done(function(data) {
        var stats = data.query.statistics;


        // Create statistics banner
    var ceoDataEl = document.getElementById('ceo-data');
        var banner = $('<div>').addClass('createaccount-statistics').html(
    if (!ceoDataEl) return;
            '<div class="createaccount-statistics-title">CEO.wiki is made by people like you.</div>' +
            '<div class="createaccount-statistics-grid">' +
                '<div class="createaccount-stat-item">' +
                    '<div class="createaccount-stat-number">' + stats.edits.toLocaleString() + '</div>' +
                    '<div class="createaccount-stat-label">Edits</div>' +
                '</div>' +
                '<div class="createaccount-stat-item">' +
                    '<div class="createaccount-stat-number">' + stats.pages.toLocaleString() + '</div>' +
                    '<div class="createaccount-stat-label">Pages</div>' +
                '</div>' +
                '<div class="createaccount-stat-item">' +
                    '<div class="createaccount-stat-number">' + stats.activeusers.toLocaleString() + '</div>' +
                    '<div class="createaccount-stat-label">Recent Contributors</div>' +
                '</div>' +
            '</div>'
        );


        // Insert banner before the form
    var ceoDataJson = ceoDataEl.getAttribute('data-ceos');
        $('#userloginForm').before(banner);
     if (!ceoDataJson) return;
     });
})();


/**
    var tags;
* Simple 3D Rotating Tag Cloud for Main Page
    try {
* Auto-rotates continuously, very visible
        tags = JSON.parse(ceoDataJson);
*/
    } catch(e) {
(function() {
        console.log('CEO Cloud: JSON parse error');
    // Only run on Main Page
    if (mw.config.get('wgPageName') !== 'Main_Page') {
         return;
         return;
     }
     }
    if (!tags || tags.length === 0) return;
    console.log('CEO Cloud: Initializing with ' + tags.length + ' CEOs');
    // Create cloud container
    var cloud = document.createElement('div');
    cloud.style.cssText = 'position:relative;width:100%;height:500px;overflow:hidden;cursor:grab;';
    // Create sphere container - FIXED: moved up by 30px to compensate for visual offset
    var sphere = document.createElement('div');
    sphere.style.cssText = 'position:absolute;left:50%;top:calc(50% - 30px);width:1px;height:1px;transform-style:preserve-3d;will-change:transform;';
    // Ellipsoid parameters
    var radiusX = 320;
    var radiusY = 100;
    var radiusZ = 240;
    var phi = Math.PI * (3 - Math.sqrt(5));
    var ceoElements = [];
    var numTags = tags.length;


     $(document).ready(function() {
     // Pre-calculate positions and create elements
         var placeholder = document.getElementById('ceo-tagcloud-placeholder');
    for (var i = 0; i < numTags; i++) {
         if (!placeholder) return;
        var tag = tags[i];
        var y = 1 - (i / (numTags - 1)) * 2;
         var radiusAtY = Math.sqrt(1 - y * y);
        var theta = phi * i;
        var x = Math.cos(theta) * radiusAtY;
         var z = Math.sin(theta) * radiusAtY;


         // Topics
         var posX = x * radiusX;
         var topics = [
         var posY = y * radiusY;
            { text: 'Satya Nadella', url: '/wiki/Satya_Nadella' },
         var posZ = z * radiusZ;
            { text: 'Tim Cook', url: '/wiki/Tim_Cook' },
            { text: 'Elon Musk', url: '/wiki/Elon_Musk' },
            { text: 'Mark Zuckerberg', url: '/wiki/Mark_Zuckerberg' },
            { text: 'Sundar Pichai', url: '/wiki/Sundar_Pichai' },
            { text: 'Andy Jassy', url: '/wiki/Andy_Jassy' },
            { text: 'Jensen Huang', url: '/wiki/Jensen_Huang' },
            { text: 'Lisa Su', url: '/wiki/Lisa_Su' },
            { text: 'Mary Barra', url: '/wiki/Mary_Barra' },
            { text: 'Jamie Dimon', url: '/wiki/Jamie_Dimon' },
            { text: 'Microsoft', url: '/wiki/Microsoft' },
            { text: 'Apple', url: '/wiki/Apple_Inc.' },
            { text: 'Amazon', url: '/wiki/Amazon' },
            { text: 'Google', url: '/wiki/Google' },
            { text: 'Tesla', url: '/wiki/Tesla' },
            { text: 'Leadership', url: '/wiki/Category:Chief_executive_officers' },
            { text: 'Innovation', url: '/wiki/Category:Business_strategies' },
            { text: 'Technology', url: '/wiki/Category:Companies' },
            { text: 'Strategy', url: '/wiki/Category:Business_strategies' },
            { text: 'Cloud Computing', url: '/wiki/Category:Industry_analysis' }
         ];


        // Create container
         var link = document.createElement('a');
         var container = $('<div>').css({
        link.href = tag.url;
            'background': 'linear-gradient(135deg, #0a1929 0%, #1a2942 50%, #0d2744 100%)',
        link.textContent = tag.text;
            'padding': '40px 20px',
        // FIXED: Removed backface-visibility:hidden so text is always visible
            'border-radius': '12px',
        link.style.cssText = 'position:absolute;left:0;top:0;color:#fff;text-decoration:none;font-size:' + tag.size + 'px;font-weight:400;font-family:"Linux Libertine",Georgia,serif;white-space:nowrap;text-shadow:0 2px 10px rgba(0,0,0,0.9);cursor:pointer;transform-style:preserve-3d;user-select:none;will-change:transform,opacity;transform:translate3d(' + posX + 'px,' + posY + 'px,' + posZ + 'px) translate(-50%,-50%);';
            'box-shadow': '0 15px 40px rgba(0,0,0,0.4)',
       
            'min-height': '400px',
        link.dataset.x = posX;
            'position': 'relative',
        link.dataset.y = posY;
            'overflow': 'hidden'
        link.dataset.z = posZ;
         });
         link.dataset.size = tag.size;


         // Title
         // Hover effects
         var title = $('<div>').text('TRENDING TOPICS').css({
         link.onmouseenter = function() {
             'color': 'white',
            this.style.color = '#fbbf24';
             'font-size': '1.4em',
             this.style.fontWeight = '700';
             'font-weight': '700',
            this.style.fontSize = (parseFloat(this.dataset.size) * 1.4) + 'px';
             'text-align': 'center',
             this.style.textShadow = '0 3px 20px rgba(251,191,36,1),0 0 50px rgba(251,191,36,0.8)';
             'margin-bottom': '30px',
             this.style.zIndex = '1000';
             'text-shadow': '0 4px 10px rgba(0,0,0,0.5)'
        };
        });
        link.onmouseleave = function() {
         container.append(title);
            this.style.color = '#fff';
             this.style.fontWeight = '400';
             this.style.fontSize = this.dataset.size + 'px';
             this.style.textShadow = '0 2px 10px rgba(0,0,0,0.9)';
            this.style.zIndex = '';
         };


         // Canvas for 3D cloud
         ceoElements.push({ el: link, x: posX, y: posY, z: posZ });
        var canvas = $('<canvas>').attr({
         sphere.appendChild(link);
            'id': 'tagcloud3d-canvas',
    }
            'width': '800',
            'height': '400'
        }).css({
            'display': 'block',
            'margin': '0 auto',
            'max-width': '100%'
        });
         container.append(canvas);
        placeholder.appendChild(container[0]);


        // 3D Tag Cloud Implementation
    cloud.appendChild(sphere);
        var ctx = canvas[0].getContext('2d');
    placeholder.innerHTML = '';
        var tags = [];
    placeholder.appendChild(cloud);
        var radius = 150;
        var fallLength = 500;
        var angleX = 0;
        var angleY = 0;
        var speedX = 0.01; // Auto-rotation speed
        var speedY = 0.015;


        // Initialize tags in 3D space
    // Animation state
        topics.forEach(function(topic, i) {
    var angleX = 10, angleY = 0;
            var phi = Math.acos(-1 + (2 * i) / topics.length);
    var targetAngleX = 10, targetAngleY = 0;
            var theta = Math.sqrt(topics.length * Math.PI) * phi;
    var zoom = 1.7, targetZoom = 1.7;
    var autoRotate = true;
    var rotationSpeed = 0.15;
    var frameCount = 0;


            tags.push({
    // FIXED: Proper depth calculation - text always visible, just faded when behind
                text: topic.text,
    function updateDepth() {
                url: topic.url,
        var rad = angleY * Math.PI / 180;
                x: radius * Math.sin(phi) * Math.cos(theta),
        var cosRad = Math.cos(rad);
                y: radius * Math.cos(phi),
        var sinRad = Math.sin(rad);
                z: radius * Math.sin(phi) * Math.sin(theta),
                originalX: radius * Math.sin(phi) * Math.cos(theta),
                originalY: radius * Math.cos(phi),
                originalZ: radius * Math.sin(phi) * Math.sin(theta)
            });
        });


         // Rotation functions
         for (var i = 0; i < ceoElements.length; i++) {
        function rotateX(x, y, z, angle) {
            var ceo = ceoElements[i];
             var cos = Math.cos(angle);
            // Calculate rotated Z position
             var sin = Math.sin(angle);
            var newZ = ceo.z * cosRad - ceo.x * sinRad;
             return {
           
                x: x,
            // Normalize to 0-1 range (front to back)
                y: y * cos - z * sin,
             var depthFactor = (newZ + radiusZ) / (radiusZ * 2);
                z: y * sin + z * cos
             depthFactor = Math.max(0, Math.min(1, depthFactor));
             };
              
            // FIXED: Text at back (depthFactor near 0) still visible but faded
            // Front text: opacity 1.0, Back text: opacity 0.25
            var opacity = 0.25 + depthFactor * 0.75;
              
            ceo.el.style.opacity = opacity;
            ceo.el.style.zIndex = Math.round(depthFactor * 100);
         }
         }
    }


        function rotateY(x, y, z, angle) {
    // Main animation loop
            var cos = Math.cos(angle);
    function animate() {
             var sin = Math.sin(angle);
        if (autoRotate) {
            return {
             targetAngleY += rotationSpeed;
                x: x * cos + z * sin,
                y: y,
                z: -x * sin + z * cos
            };
         }
         }


         // Animation loop
         // Smooth interpolation
         function animate() {
         angleX += (targetAngleX - angleX) * 0.1;
            // Clear canvas
        angleY += (targetAngleY - angleY) * 0.1;
            ctx.clearRect(0, 0, canvas[0].width, canvas[0].height);
        zoom += (targetZoom - zoom) * 0.1;
 
        // Update transform
        sphere.style.transform = 'scale(' + zoom + ') rotateX(' + angleX + 'deg) rotateY(' + angleY + 'deg)';
 
        // Update depth every 3 frames for performance
        frameCount++;
        if (frameCount % 3 === 0) {
            updateDepth();
        }


            // Auto-rotate
        requestAnimationFrame(animate);
            angleX += speedX;
    }
            angleY += speedY;


            // Update and draw tags
    // Initial depth calculation
            tags.forEach(function(tag) {
    updateDepth();
                // Apply rotations
    animate();
                var rotated = rotateX(tag.originalX, tag.originalY, tag.originalZ, angleX);
                rotated = rotateY(rotated.x, rotated.y, rotated.z, angleY);


                tag.x = rotated.x;
    // Mouse drag controls
                tag.y = rotated.y;
    var isDragging = false, prevX = 0, prevY = 0;
                tag.z = rotated.z;
            });


            // Sort by z-depth (back to front)
    cloud.onmousedown = function(e) {
            tags.sort(function(a, b) {
        if (e.target.tagName !== 'A') {
                return a.z - b.z;
            isDragging = true;
             });
            autoRotate = false;
            prevX = e.clientX;
            prevY = e.clientY;
            cloud.style.cursor = 'grabbing';
             e.preventDefault();
        }
    };


            // Draw tags
    document.onmousemove = function(e) {
            tags.forEach(function(tag) {
        if (isDragging) {
                var scale = fallLength / (fallLength + tag.z);
            targetAngleY += (e.clientX - prevX) * 0.5;
                var x = tag.x * scale + canvas[0].width / 2;
            targetAngleX = Math.max(-40, Math.min(40, targetAngleX - (e.clientY - prevY) * 0.3));
                var y = tag.y * scale + canvas[0].height / 2;
            prevX = e.clientX;
                var alpha = (tag.z + radius) / (2 * radius);
            prevY = e.clientY;
                alpha = Math.max(0.3, Math.min(1, alpha));
        }
    };


                // Font size based on depth
    document.onmouseup = function() {
                var fontSize = Math.floor(14 + 10 * scale);
        if (isDragging) {
            isDragging = false;
            cloud.style.cursor = 'grab';
            setTimeout(function() { autoRotate = true; }, 2000);
        }
    };


                ctx.save();
    // Mouse wheel zoom
                ctx.font = fontSize + 'px sans-serif, "Helvetica Neue", Helvetica, Arial';
    cloud.onwheel = function(e) {
                ctx.fillStyle = 'rgba(255, 255, 255, ' + alpha + ')';
        e.preventDefault();
                ctx.textAlign = 'center';
        targetZoom = Math.max(0.8, Math.min(2.5, targetZoom + (e.deltaY > 0 ? -0.1 : 0.1)));
                ctx.textBaseline = 'middle';
        autoRotate = false;
                ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
        clearTimeout(cloud.zoomTimeout);
                ctx.shadowBlur = 5;
        cloud.zoomTimeout = setTimeout(function() { autoRotate = true; }, 1500);
                ctx.fillText(tag.text, x, y);
    };
                ctx.restore();
            });


             requestAnimationFrame(animate);
    // Touch support
    cloud.ontouchstart = function(e) {
        if (e.touches.length === 1) {
            isDragging = true;
            autoRotate = false;
            prevX = e.touches[0].clientX;
            prevY = e.touches[0].clientY;
             e.preventDefault();
         }
         }
    };


         // Start animation
    document.ontouchmove = function(e) {
        animate();
         if (isDragging && e.touches.length === 1) {
            targetAngleY += (e.touches[0].clientX - prevX) * 0.5;
            targetAngleX = Math.max(-40, Math.min(40, targetAngleX - (e.touches[0].clientY - prevY) * 0.3));
            prevX = e.touches[0].clientX;
            prevY = e.touches[0].clientY;
        }
    };


        // Make tags clickable
    document.ontouchend = function() {
        canvas.on('click', function(e) {
        if (isDragging) {
            var rect = canvas[0].getBoundingClientRect();
             isDragging = false;
             var x = e.clientX - rect.left;
             setTimeout(function() { autoRotate = true; }, 2000);
             var y = e.clientY - rect.top;
        }
    };


            // Check if click is near any tag
    // Control hints
            for (var i = tags.length - 1; i >= 0; i--) {
    var hints = document.createElement('div');
                var tag = tags[i];
    hints.style.cssText = 'position:absolute;bottom:10px;left:50%;transform:translateX(-50%);color:rgba(255,255,255,0.6);font-size:12px;text-align:center;pointer-events:none;font-family:sans-serif;';
                var scale = fallLength / (fallLength + tag.z);
    hints.innerHTML = '🖱️ Drag to rotate • 🔍 Scroll to zoom';
                var tagX = tag.x * scale + canvas[0].width / 2;
    cloud.appendChild(hints);
                var tagY = tag.y * scale + canvas[0].height / 2;


                ctx.font = Math.floor(14 + 10 * scale) + 'px sans-serif';
    console.log('CEO Cloud: Initialization complete');
                var metrics = ctx.measureText(tag.text);
});
                var width = metrics.width;
                var height = Math.floor(14 + 10 * scale);


                if (x >= tagX - width/2 && x <= tagX + width/2 &&
/* ============================================
                    y >= tagY - height/2 && y <= tagY + height/2) {
  RESPONSIVE CEO PROFILE IMAGES
                    window.location.href = tag.url;
  ============================================ */
                    break;
$(document).ready(function() {
                }
    if (!$('body').hasClass('page-Main_Page')) return;
            }
        });


        // Change cursor on hover
    function resizeCEOImages() {
         canvas.on('mousemove', function(e) {
         var windowWidth = $(window).width();
             var rect = canvas[0].getBoundingClientRect();
        var imageWidth;
             var x = e.clientX - rect.left;
       
             var y = e.clientY - rect.top;
        if (windowWidth > 1200) {
             var overTag = false;
             imageWidth = Math.floor((windowWidth - 100) / 3 * 0.7);
        } else if (windowWidth > 768) {
             imageWidth = Math.floor((windowWidth - 80) / 2 * 0.7);
        } else if (windowWidth > 480) {
             imageWidth = Math.floor((windowWidth - 40) * 0.8);
        } else {
             imageWidth = Math.floor((windowWidth - 40) * 0.9);
        }


            for (var i = tags.length - 1; i >= 0; i--) {
        imageWidth = Math.max(150, Math.min(400, imageWidth));
                var tag = tags[i];
                var scale = fallLength / (fallLength + tag.z);
                var tagX = tag.x * scale + canvas[0].width / 2;
                var tagY = tag.y * scale + canvas[0].height / 2;


                ctx.font = Math.floor(14 + 10 * scale) + 'px sans-serif';
        $('table[style*="width: 33%"] img, table[style*="width: 25%"] img').each(function() {
                var metrics = ctx.measureText(tag.text);
            var $img = $(this);
                var width = metrics.width;
            var src = $img.attr('src');
                var height = Math.floor(14 + 10 * scale);
            if (!src || src.indexOf('File:') === -1) return;


                if (x >= tagX - width/2 && x <= tagX + width/2 &&
            if (src.indexOf('/thumb/') !== -1) {
                    y >= tagY - height/2 && y <= tagY + height/2) {
                $img.attr('src', src.replace(/\/\d+px-/, '/' + imageWidth + 'px-'));
                    overTag = true;
                    break;
                }
             }
             }


             canvas.css('cursor', overTag ? 'pointer' : 'default');
             $img.css({ 'max-width': '100%', 'height': 'auto', 'width': 'auto', 'display': 'block', 'margin': '0 auto' });
            $img.removeAttr('width').removeAttr('height');
            $img.parent('a').css({ 'display': 'block', 'text-align': 'center' });
         });
         });
    }
    resizeCEOImages();
    var resizeTimer;
    $(window).on('resize', function() {
        clearTimeout(resizeTimer);
        resizeTimer = setTimeout(resizeCEOImages, 250);
    });
    $(window).on('orientationchange', function() {
        setTimeout(resizeCEOImages, 300);
     });
     });
})();
});

Latest revision as of 12:24, 29 November 2025

/* Common.js - Site-wide JavaScript */

/* Add copyright footer at the very bottom of page - single occurrence only */
$(document).ready(function() {
    // Remove any existing copyright footers first to prevent duplicates
    $('#footer-info-copyright, .ceo-copyright-footer').remove();

    // Create the copyright footer
    var copyright = '<div class="ceo-copyright-footer" id="footer-info-copyright" style="text-align: center; padding: 20px; background: #f8f9fa; border-top: 1px solid #ddd; margin-top: 40px; font-size: 0.85em; line-height: 1.6;">Text is available under the <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="nofollow">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="/wiki/CEO.wiki:Terms_of_Use">Terms of Use</a>, <a href="/wiki/CEO.wiki:Privacy_Policy">Privacy Policy</a>, and all <a href="/wiki/CEO.wiki:General_disclaimer">disclaimers</a>. CEO.wiki is operated as an independent collaborative encyclopedia project and is not affiliated with Wikipedia or the Wikimedia Foundation. See our <a href="/wiki/CEO.wiki:Takedown_Request_Policy">Takedown Request Policy</a> for content concerns.</div>';

    // Append to the very bottom of the body
    $('body').append(copyright);
});

/* 3D CEO Cloud - FIXED centering and visibility */
$(document).ready(function() {
    var placeholder = document.getElementById('ceocloud-placeholder');
    if (!placeholder) return;

    var ceoDataEl = document.getElementById('ceo-data');
    if (!ceoDataEl) return;

    var ceoDataJson = ceoDataEl.getAttribute('data-ceos');
    if (!ceoDataJson) return;

    var tags;
    try {
        tags = JSON.parse(ceoDataJson);
    } catch(e) {
        console.log('CEO Cloud: JSON parse error');
        return;
    }
    if (!tags || tags.length === 0) return;

    console.log('CEO Cloud: Initializing with ' + tags.length + ' CEOs');

    // Create cloud container
    var cloud = document.createElement('div');
    cloud.style.cssText = 'position:relative;width:100%;height:500px;overflow:hidden;cursor:grab;';

    // Create sphere container - FIXED: moved up by 30px to compensate for visual offset
    var sphere = document.createElement('div');
    sphere.style.cssText = 'position:absolute;left:50%;top:calc(50% - 30px);width:1px;height:1px;transform-style:preserve-3d;will-change:transform;';

    // Ellipsoid parameters
    var radiusX = 320;
    var radiusY = 100;
    var radiusZ = 240;
    var phi = Math.PI * (3 - Math.sqrt(5));
    var ceoElements = [];
    var numTags = tags.length;

    // Pre-calculate positions and create elements
    for (var i = 0; i < numTags; i++) {
        var tag = tags[i];
        var y = 1 - (i / (numTags - 1)) * 2;
        var radiusAtY = Math.sqrt(1 - y * y);
        var theta = phi * i;
        var x = Math.cos(theta) * radiusAtY;
        var z = Math.sin(theta) * radiusAtY;

        var posX = x * radiusX;
        var posY = y * radiusY;
        var posZ = z * radiusZ;

        var link = document.createElement('a');
        link.href = tag.url;
        link.textContent = tag.text;
        // FIXED: Removed backface-visibility:hidden so text is always visible
        link.style.cssText = 'position:absolute;left:0;top:0;color:#fff;text-decoration:none;font-size:' + tag.size + 'px;font-weight:400;font-family:"Linux Libertine",Georgia,serif;white-space:nowrap;text-shadow:0 2px 10px rgba(0,0,0,0.9);cursor:pointer;transform-style:preserve-3d;user-select:none;will-change:transform,opacity;transform:translate3d(' + posX + 'px,' + posY + 'px,' + posZ + 'px) translate(-50%,-50%);';
        
        link.dataset.x = posX;
        link.dataset.y = posY;
        link.dataset.z = posZ;
        link.dataset.size = tag.size;

        // Hover effects
        link.onmouseenter = function() {
            this.style.color = '#fbbf24';
            this.style.fontWeight = '700';
            this.style.fontSize = (parseFloat(this.dataset.size) * 1.4) + 'px';
            this.style.textShadow = '0 3px 20px rgba(251,191,36,1),0 0 50px rgba(251,191,36,0.8)';
            this.style.zIndex = '1000';
        };
        link.onmouseleave = function() {
            this.style.color = '#fff';
            this.style.fontWeight = '400';
            this.style.fontSize = this.dataset.size + 'px';
            this.style.textShadow = '0 2px 10px rgba(0,0,0,0.9)';
            this.style.zIndex = '';
        };

        ceoElements.push({ el: link, x: posX, y: posY, z: posZ });
        sphere.appendChild(link);
    }

    cloud.appendChild(sphere);
    placeholder.innerHTML = '';
    placeholder.appendChild(cloud);

    // Animation state
    var angleX = 10, angleY = 0;
    var targetAngleX = 10, targetAngleY = 0;
    var zoom = 1.7, targetZoom = 1.7;
    var autoRotate = true;
    var rotationSpeed = 0.15;
    var frameCount = 0;

    // FIXED: Proper depth calculation - text always visible, just faded when behind
    function updateDepth() {
        var rad = angleY * Math.PI / 180;
        var cosRad = Math.cos(rad);
        var sinRad = Math.sin(rad);

        for (var i = 0; i < ceoElements.length; i++) {
            var ceo = ceoElements[i];
            // Calculate rotated Z position
            var newZ = ceo.z * cosRad - ceo.x * sinRad;
            
            // Normalize to 0-1 range (front to back)
            var depthFactor = (newZ + radiusZ) / (radiusZ * 2);
            depthFactor = Math.max(0, Math.min(1, depthFactor));
            
            // FIXED: Text at back (depthFactor near 0) still visible but faded
            // Front text: opacity 1.0, Back text: opacity 0.25
            var opacity = 0.25 + depthFactor * 0.75;
            
            ceo.el.style.opacity = opacity;
            ceo.el.style.zIndex = Math.round(depthFactor * 100);
        }
    }

    // Main animation loop
    function animate() {
        if (autoRotate) {
            targetAngleY += rotationSpeed;
        }

        // Smooth interpolation
        angleX += (targetAngleX - angleX) * 0.1;
        angleY += (targetAngleY - angleY) * 0.1;
        zoom += (targetZoom - zoom) * 0.1;

        // Update transform
        sphere.style.transform = 'scale(' + zoom + ') rotateX(' + angleX + 'deg) rotateY(' + angleY + 'deg)';

        // Update depth every 3 frames for performance
        frameCount++;
        if (frameCount % 3 === 0) {
            updateDepth();
        }

        requestAnimationFrame(animate);
    }

    // Initial depth calculation
    updateDepth();
    animate();

    // Mouse drag controls
    var isDragging = false, prevX = 0, prevY = 0;

    cloud.onmousedown = function(e) {
        if (e.target.tagName !== 'A') {
            isDragging = true;
            autoRotate = false;
            prevX = e.clientX;
            prevY = e.clientY;
            cloud.style.cursor = 'grabbing';
            e.preventDefault();
        }
    };

    document.onmousemove = function(e) {
        if (isDragging) {
            targetAngleY += (e.clientX - prevX) * 0.5;
            targetAngleX = Math.max(-40, Math.min(40, targetAngleX - (e.clientY - prevY) * 0.3));
            prevX = e.clientX;
            prevY = e.clientY;
        }
    };

    document.onmouseup = function() {
        if (isDragging) {
            isDragging = false;
            cloud.style.cursor = 'grab';
            setTimeout(function() { autoRotate = true; }, 2000);
        }
    };

    // Mouse wheel zoom
    cloud.onwheel = function(e) {
        e.preventDefault();
        targetZoom = Math.max(0.8, Math.min(2.5, targetZoom + (e.deltaY > 0 ? -0.1 : 0.1)));
        autoRotate = false;
        clearTimeout(cloud.zoomTimeout);
        cloud.zoomTimeout = setTimeout(function() { autoRotate = true; }, 1500);
    };

    // Touch support
    cloud.ontouchstart = function(e) {
        if (e.touches.length === 1) {
            isDragging = true;
            autoRotate = false;
            prevX = e.touches[0].clientX;
            prevY = e.touches[0].clientY;
            e.preventDefault();
        }
    };

    document.ontouchmove = function(e) {
        if (isDragging && e.touches.length === 1) {
            targetAngleY += (e.touches[0].clientX - prevX) * 0.5;
            targetAngleX = Math.max(-40, Math.min(40, targetAngleX - (e.touches[0].clientY - prevY) * 0.3));
            prevX = e.touches[0].clientX;
            prevY = e.touches[0].clientY;
        }
    };

    document.ontouchend = function() {
        if (isDragging) {
            isDragging = false;
            setTimeout(function() { autoRotate = true; }, 2000);
        }
    };

    // Control hints
    var hints = document.createElement('div');
    hints.style.cssText = 'position:absolute;bottom:10px;left:50%;transform:translateX(-50%);color:rgba(255,255,255,0.6);font-size:12px;text-align:center;pointer-events:none;font-family:sans-serif;';
    hints.innerHTML = '🖱️ Drag to rotate • 🔍 Scroll to zoom';
    cloud.appendChild(hints);

    console.log('CEO Cloud: Initialization complete');
});

/* ============================================
   RESPONSIVE CEO PROFILE IMAGES
   ============================================ */
$(document).ready(function() {
    if (!$('body').hasClass('page-Main_Page')) return;

    function resizeCEOImages() {
        var windowWidth = $(window).width();
        var imageWidth;
        
        if (windowWidth > 1200) {
            imageWidth = Math.floor((windowWidth - 100) / 3 * 0.7);
        } else if (windowWidth > 768) {
            imageWidth = Math.floor((windowWidth - 80) / 2 * 0.7);
        } else if (windowWidth > 480) {
            imageWidth = Math.floor((windowWidth - 40) * 0.8);
        } else {
            imageWidth = Math.floor((windowWidth - 40) * 0.9);
        }

        imageWidth = Math.max(150, Math.min(400, imageWidth));

        $('table[style*="width: 33%"] img, table[style*="width: 25%"] img').each(function() {
            var $img = $(this);
            var src = $img.attr('src');
            if (!src || src.indexOf('File:') === -1) return;

            if (src.indexOf('/thumb/') !== -1) {
                $img.attr('src', src.replace(/\/\d+px-/, '/' + imageWidth + 'px-'));
            }

            $img.css({ 'max-width': '100%', 'height': 'auto', 'width': 'auto', 'display': 'block', 'margin': '0 auto' });
            $img.removeAttr('width').removeAttr('height');
            $img.parent('a').css({ 'display': 'block', 'text-align': 'center' });
        });
    }

    resizeCEOImages();

    var resizeTimer;
    $(window).on('resize', function() {
        clearTimeout(resizeTimer);
        resizeTimer = setTimeout(resizeCEOImages, 250);
    });

    $(window).on('orientationchange', function() {
        setTimeout(resizeCEOImages, 300);
    });
});