Jump to content

MediaWiki:Common.js: Difference between revisions

The comprehensive free global encyclopedia of CEOs, corporate leadership, and business excellence
Updated to dynamically build 3D tag cloud from placeholder
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
 
(34 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/* 3D Tag Cloud - Dynamic Builder */
/* Common.js - Site-wide JavaScript */
(function() {
    if (typeof window.CEOTagCloudInit !== 'undefined') return;
    window.CEOTagCloudInit = true;


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


        // Build the HTML structure
    // Create the copyright footer
        var tagCloudHTML = '<div class="mp-card" style="margin-top: 1em;">' +
    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>';
            '<div class="mp-card-title">Explore Popular Topics</div>' +
            '<div class="mp-card-content" style="padding: 2em 1em;">' +
            '<div style="text-align: center; margin-bottom: 1em; color: #54595d;">Interactive 3D cloud of most popular pages</div>' +
            '<div id="tagcloud-container" style="width: 100%; height: 350px; position: relative; perspective: 800px; background: radial-gradient(circle at center, #f8f9fa 0%, #e5e7eb 100%); border-radius: 12px; overflow: hidden; box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);">' +
            '<div id="tagcloud-sphere" style="position: absolute; width: 100%; height: 100%; transform-style: preserve-3d;"></div>' +
            '</div>' +
            '<div style="text-align: center; margin-top: 1em; font-size: 0.85em; color: #6b7280;"><em>Hover and move mouse to rotate</em></div>' +
            '</div></div>';


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


        // Tag data
/* 3D CEO Cloud - FIXED centering and visibility */
        var tags = [
$(document).ready(function() {
            {text: 'Satya Nadella', href: '/wiki/Satya_Nadella', weight: 10},
    var placeholder = document.getElementById('ceocloud-placeholder');
            {text: 'Tim Cook', href: '/wiki/Tim_Cook', weight: 9},
    if (!placeholder) return;
            {text: 'Mary Barra', href: '/wiki/Mary_Barra', weight: 8},
            {text: 'Andy Jassy', href: '/wiki/Andy_Jassy', weight: 9},
            {text: 'Sundar Pichai', href: '/wiki/Sundar_Pichai', weight: 10},
            {text: 'CEO Profiles', href: '/wiki/Category:Chief_executive_officers', weight: 7},
            {text: 'Companies', href: '/wiki/Category:Companies', weight: 6},
            {text: 'Business Strategy', href: '/wiki/Category:Business_strategies', weight: 5},
            {text: 'Governance', href: '/wiki/Category:Corporate_governance', weight: 5},
            {text: 'CEOs by Country', href: '/wiki/Category:CEOs_by_country', weight: 6},
            {text: 'American CEOs', href: '/wiki/Category:American_CEOs', weight: 7},
            {text: 'Tech CEOs', href: '/wiki/Category:Technology_CEOs', weight: 8},
            {text: 'Random', href: '/wiki/Special:Random', weight: 4},
            {text: 'Industry Analysis', href: '/wiki/Category:Industry_analysis', weight: 5},
            {text: 'Microsoft', href: '/wiki/Microsoft', weight: 7},
            {text: 'Apple', href: '/wiki/Apple_Inc.', weight: 8},
            {text: 'Amazon', href: '/wiki/Amazon', weight: 7},
            {text: 'Google', href: '/wiki/Google', weight: 8},
            {text: 'General Motors', href: '/wiki/General_Motors', weight: 6},
            {text: 'Fortune 500', href: '/wiki/Category:Fortune_500_CEOs', weight: 6}
        ];


        // Create tag elements
    var ceoDataEl = document.getElementById('ceo-data');
        var container = document.getElementById('tagcloud-sphere');
    if (!ceoDataEl) return;
        if (!container) return;


        tags.forEach(function(tag) {
    var ceoDataJson = ceoDataEl.getAttribute('data-ceos');
            var a = document.createElement('a');
    if (!ceoDataJson) return;
            a.href = tag.href;
 
            a.className = 'tag-item';
    var tags;
            a.setAttribute('data-weight', tag.weight);
    try {
            a.textContent = tag.text;
        tags = JSON.parse(ceoDataJson);
            a.style.position = 'absolute';
    } catch(e) {
            a.style.left = '50%';
        console.log('CEO Cloud: JSON parse error');
            a.style.top = '50%';
        return;
            a.style.whiteSpace = 'nowrap';
    }
            a.style.textDecoration = 'none';
    if (!tags || tags.length === 0) return;
            a.style.color = '#1e3a5c';
 
            a.style.fontWeight = '600';
    console.log('CEO Cloud: Initializing with ' + tags.length + ' CEOs');
            a.style.padding = '0.4em 0.8em';
 
            a.style.background = 'linear-gradient(135deg, #ffffff 0%, #f0f9ff 100%)';
    // Create cloud container
            a.style.border = '2px solid #0066cc';
    var cloud = document.createElement('div');
            a.style.borderRadius = '20px';
    cloud.style.cssText = 'position:relative;width:100%;height:500px;overflow:hidden;cursor:grab;';
            a.style.cursor = 'pointer';
 
            a.style.userSelect = 'none';
    // Create sphere container - FIXED: moved up by 30px to compensate for visual offset
            a.style.boxShadow = '0 2px 8px rgba(0, 102, 204, 0.2)';
    var sphere = document.createElement('div');
            a.style.transition = 'all 0.3s ease';
    sphere.style.cssText = 'position:absolute;left:50%;top:calc(50% - 30px);width:1px;height:1px;transform-style:preserve-3d;will-change:transform;';
           
 
            var fontSize = 0.9 + (tag.weight / 10) * 0.5;
    // Ellipsoid parameters
            a.style.fontSize = fontSize + 'em';
    var radiusX = 320;
           
    var radiusY = 100;
            a.addEventListener('mouseenter', function() {
    var radiusZ = 240;
                this.style.background = 'linear-gradient(135deg, #0066cc 0%, #0052a3 100%)';
    var phi = Math.PI * (3 - Math.sqrt(5));
                this.style.color = '#ffffff';
    var ceoElements = [];
                this.style.transform = 'scale(1.2)';
    var numTags = tags.length;
                this.style.boxShadow = '0 4px 16px rgba(0, 102, 204, 0.4)';
 
                this.style.zIndex = '100';
    // Pre-calculate positions and create elements
            });
    for (var i = 0; i < numTags; i++) {
           
        var tag = tags[i];
            a.addEventListener('mouseleave', function() {
        var y = 1 - (i / (numTags - 1)) * 2;
                this.style.background = 'linear-gradient(135deg, #ffffff 0%, #f0f9ff 100%)';
        var radiusAtY = Math.sqrt(1 - y * y);
                this.style.color = '#1e3a5c';
        var theta = phi * i;
                this.style.transform = 'scale(1)';
        var x = Math.cos(theta) * radiusAtY;
                this.style.boxShadow = '0 2px 8px rgba(0, 102, 204, 0.2)';
        var z = Math.sin(theta) * radiusAtY;
                this.style.zIndex = 'auto';
 
            });
        var posX = x * radiusX;
           
        var posY = y * radiusY;
            container.appendChild(a);
         var posZ = z * radiusZ;
         });


        // 3D Animation Engine
         var link = document.createElement('a');
         var elements = container.getElementsByClassName('tag-item');
         link.href = tag.url;
         var radius = 150;
         link.textContent = tag.text;
         var dtr = Math.PI / 180;
         // FIXED: Removed backface-visibility:hidden so text is always visible
         var mcList = [];
         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%);';
         var active = false;
        var lasta = 0.5;
        var lastb = 0.5;
        var tspeed = 2;
        var size = 200;
        var mouseX = 0;
        var mouseY = 0;
          
          
         var sa, ca, sb, cb, sc, cc;
         link.dataset.x = posX;
        link.dataset.y = posY;
        link.dataset.z = posZ;
        link.dataset.size = tag.size;


         // Initialize positions
         // Hover effects
         for (var i = 0; i < elements.length; i++) {
         link.onmouseenter = function() {
             var oTag = {};
            this.style.color = '#fbbf24';
             oTag.offsetWidth = elements[i].offsetWidth;
            this.style.fontWeight = '700';
             oTag.offsetHeight = elements[i].offsetHeight;
            this.style.fontSize = (parseFloat(this.dataset.size) * 1.4) + 'px';
             mcList.push(oTag);
            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 = '';
         };


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


        setInterval(update, 30);
    cloud.appendChild(sphere);
    placeholder.innerHTML = '';
    placeholder.appendChild(cloud);


        function update() {
    // Animation state
            var a, b;
    var angleX = 10, angleY = 0;
           
    var targetAngleX = 10, targetAngleY = 0;
            if (active) {
    var zoom = 1.7, targetZoom = 1.7;
                a = (-Math.min(Math.max(-mouseY, -size), size) / radius) * tspeed;
    var autoRotate = true;
                b = (Math.min(Math.max(-mouseX, -size), size) / radius) * tspeed;
    var rotationSpeed = 0.15;
            } else {
    var frameCount = 0;
                a = lasta * 0.98;
                b = lastb * 0.98;
            }


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


            if (Math.abs(a) <= 0.01 && Math.abs(b) <= 0.01 && !active) {
        for (var i = 0; i < ceoElements.length; i++) {
                a = 0.3;
            var ceo = ceoElements[i];
                b = 0.3;
            // Calculate rotated Z position
             }
            var newZ = ceo.z * cosRad - ceo.x * sinRad;
 
              
             sineCosine(a, b, 0);
            // 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;
              
              
             for (var i = 0; i < mcList.length; i++) {
             ceo.el.style.opacity = opacity;
                var rx1 = mcList[i].cx;
            ceo.el.style.zIndex = Math.round(depthFactor * 100);
                var ry1 = mcList[i].cy * ca + mcList[i].cz * (-sa);
        }
                var rz1 = mcList[i].cy * sa + mcList[i].cz * ca;
    }


                var rx2 = rx1 * cb + rz1 * sb;
    // Main animation loop
                var ry2 = ry1;
    function animate() {
                var rz2 = rx1 * (-sb) + rz1 * cb;
        if (autoRotate) {
            targetAngleY += rotationSpeed;
        }


                mcList[i].cx = rx2;
        // Smooth interpolation
                mcList[i].cy = ry2;
        angleX += (targetAngleX - angleX) * 0.1;
                mcList[i].cz = rz2;
        angleY += (targetAngleY - angleY) * 0.1;
        zoom += (targetZoom - zoom) * 0.1;


                var per = 350 / (350 + rz2);
        // Update transform
                mcList[i].x = rx2 * per;
        sphere.style.transform = 'scale(' + zoom + ') rotateX(' + angleX + 'deg) rotateY(' + angleY + 'deg)';
                mcList[i].y = ry2 * per;
                mcList[i].scale = per;
                mcList[i].alpha = per;
                mcList[i].alpha = (mcList[i].alpha - 0.6) * (10 / 6);
            }


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


         function depthSort() {
         requestAnimationFrame(animate);
            var aTmp = [];
    }
            for (var i = 0; i < elements.length; i++) {
 
                aTmp.push(elements[i]);
    // Initial depth calculation
                elements[i].cz = mcList[i].cz;
    updateDepth();
            }
    animate();


            aTmp.sort(function(vItem1, vItem2) {
    // Mouse drag controls
                if (vItem1.cz > vItem2.cz) return -1;
    var isDragging = false, prevX = 0, prevY = 0;
                else if (vItem1.cz < vItem2.cz) return 1;
                else return 0;
            });


             for (var i = 0; i < aTmp.length; i++) {
    cloud.onmousedown = function(e) {
                aTmp[i].style.zIndex = i;
        if (e.target.tagName !== 'A') {
             }
            isDragging = true;
             autoRotate = false;
            prevX = e.clientX;
            prevY = e.clientY;
            cloud.style.cursor = 'grabbing';
             e.preventDefault();
         }
         }
    };


         function positionAll() {
    document.onmousemove = function(e) {
             var phi, theta, max = mcList.length;
         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;
        }
    };


            for (var i = 0; i < max; i++) {
    document.onmouseup = function() {
                phi = Math.acos(-1 + (2 * i) / max);
        if (isDragging) {
                theta = Math.sqrt(max * Math.PI) * phi;
            isDragging = false;
            cloud.style.cursor = 'grab';
            setTimeout(function() { autoRotate = true; }, 2000);
        }
    };


                mcList[i].cx = radius * Math.cos(theta) * Math.sin(phi);
    // Mouse wheel zoom
                mcList[i].cy = radius * Math.sin(theta) * Math.sin(phi);
    cloud.onwheel = function(e) {
                mcList[i].cz = radius * Math.cos(phi);
        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);
    };


                elements[i].style.left = mcList[i].cx + container.offsetWidth / 2 - mcList[i].offsetWidth / 2 + 'px';
    // Touch support
                elements[i].style.top = mcList[i].cy + container.offsetHeight / 2 - mcList[i].offsetHeight / 2 + 'px';
    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();
         }
         }
    };


        function doPosition() {
    document.ontouchmove = function(e) {
             var l = container.offsetWidth / 2;
        if (isDragging && e.touches.length === 1) {
             var t = container.offsetHeight / 2;
             targetAngleY += (e.touches[0].clientX - prevX) * 0.5;
              
             targetAngleX = Math.max(-40, Math.min(40, targetAngleX - (e.touches[0].clientY - prevY) * 0.3));
            for (var i = 0; i < mcList.length; i++) {
             prevX = e.touches[0].clientX;
                var item = elements[i];
            prevY = e.touches[0].clientY;
                var mc = mcList[i];
        }
    };


                item.style.left = mc.x + l - mc.offsetWidth / 2 + 'px';
    document.ontouchend = function() {
                item.style.top = mc.y + t - mc.offsetHeight / 2 + 'px';
        if (isDragging) {
               
            isDragging = false;
                var baseSize = parseFloat(item.getAttribute('data-weight')) / 10;
            setTimeout(function() { autoRotate = true; }, 2000);
                item.style.fontSize = (0.9 + baseSize * 0.5) * mc.scale + 'em';
                item.style.opacity = Math.max(0.3, mc.alpha);
            }
         }
         }
    };


        function sineCosine(a, b, c) {
    // Control hints
            sa = Math.sin(a * dtr);
    var hints = document.createElement('div');
            ca = Math.cos(a * dtr);
    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;';
             sb = Math.sin(b * dtr);
    hints.innerHTML = '🖱️ Drag to rotate • 🔍 Scroll to zoom';
             cb = Math.cos(b * dtr);
    cloud.appendChild(hints);
             sc = Math.sin(c * dtr);
 
             cc = Math.cos(c * dtr);
    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);
         }
         }


         // Mouse interaction
         imageWidth = Math.max(150, Math.min(400, imageWidth));
        var containerElem = document.getElementById('tagcloud-container');
 
         containerElem.addEventListener('mouseover', function() {
         $('table[style*="width: 33%"] img, table[style*="width: 25%"] img').each(function() {
             active = true;
             var $img = $(this);
        });
            var src = $img.attr('src');
            if (!src || src.indexOf('File:') === -1) return;


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


        containerElem.addEventListener('mousemove', function(ev) {
            $img.css({ 'max-width': '100%', 'height': 'auto', 'width': 'auto', 'display': 'block', 'margin': '0 auto' });
             var rect = containerElem.getBoundingClientRect();
             $img.removeAttr('width').removeAttr('height');
            mouseX = ev.clientX - rect.left - containerElem.offsetWidth / 2;
             $img.parent('a').css({ 'display': 'block', 'text-align': 'center' });
             mouseY = ev.clientY - rect.top - containerElem.offsetHeight / 2;
         });
         });
     }
     }


     if (document.readyState === 'loading') {
     resizeCEOImages();
         document.addEventListener('DOMContentLoaded', buildAndInitTagCloud);
 
     } else {
    var resizeTimer;
         buildAndInitTagCloud();
    $(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);
    });
});