Jump to content

MediaWiki:Common.js: Difference between revisions

The comprehensive free global encyclopedia of CEOs, corporate leadership, and business excellence
Increased tag cloud text size by 300% and changed to Wikipedia-style serif font (Linux Libertine, Georgia)
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
 
(19 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 (typeof mw !== 'undefined' && mw.config && mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') {
     $('#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;
         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;';


     if (typeof mw !== 'undefined' && mw.Api && typeof $ !== 'undefined') {
     // Ellipsoid parameters
        // Get site statistics via API
    var radiusX = 320;
        var api = new mw.Api();
    var radiusY = 100;
    var radiusZ = 240;
    var phi = Math.PI * (3 - Math.sqrt(5));
    var ceoElements = [];
    var numTags = tags.length;


        api.get({
    // Pre-calculate positions and create elements
            action: 'query',
    for (var i = 0; i < numTags; i++) {
            meta: 'siteinfo',
        var tag = tags[i];
            siprop: 'statistics',
        var y = 1 - (i / (numTags - 1)) * 2;
            format: 'json'
        var radiusAtY = Math.sqrt(1 - y * y);
         }).done(function(data) {
        var theta = phi * i;
            var stats = data.query.statistics;
         var x = Math.cos(theta) * radiusAtY;
        var z = Math.sin(theta) * radiusAtY;


            // Create statistics banner
        var posX = x * radiusX;
            var banner = $('<div>').addClass('createaccount-statistics').html(
        var posY = y * radiusY;
                '<div class="createaccount-statistics-title">CEO.wiki is made by people like you.</div>' +
        var posZ = z * radiusZ;
                '<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 link = document.createElement('a');
             $('#userloginForm').before(banner);
        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);
* 3D Rotating Tag Cloud - Large Text with Wikipedia-style Font
     placeholder.innerHTML = '';
*/
     placeholder.appendChild(cloud);
(function() {
 
     'use strict';
     // Animation state
      
    var angleX = 10, angleY = 0;
    console.log('[TagCloud] Script loaded');
    var targetAngleX = 10, targetAngleY = 0;
   
    var zoom = 1.7, targetZoom = 1.7;
     // Check if we're on Main Page
     var autoRotate = true;
     if (typeof mw !== 'undefined' && mw.config) {
    var rotationSpeed = 0.15;
         var pageName = mw.config.get('wgPageName');
    var frameCount = 0;
         console.log('[TagCloud] Page name:', pageName);
 
         if (pageName !== 'Main_Page') {
    // FIXED: Proper depth calculation - text always visible, just faded when behind
             console.log('[TagCloud] Not Main Page, exiting');
    function updateDepth() {
             return;
         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);
         }
         }
     }
     }
   
 
    var attempts = 0;
     // Main animation loop
    var maxAttempts = 50;
     function animate() {
      
         if (autoRotate) {
     function tryInitialize() {
            targetAngleY += rotationSpeed;
         attempts++;
         }
          
 
         // Look for the placeholder div
         // Smooth interpolation
         var placeholder = document.getElementById('ceocloud-placeholder');
         angleX += (targetAngleX - angleX) * 0.1;
         if (!placeholder) {
         angleY += (targetAngleY - angleY) * 0.1;
            if (attempts < maxAttempts) {
        zoom += (targetZoom - zoom) * 0.1;
                console.log('[TagCloud] Placeholder not found yet, retrying... (attempt ' + attempts + '/' + maxAttempts + ')');
 
                setTimeout(tryInitialize, 100);
        // Update transform
            } else {
        sphere.style.transform = 'scale(' + zoom + ') rotateX(' + angleX + 'deg) rotateY(' + angleY + 'deg)';
                console.error('[TagCloud] Placeholder div not found after ' + maxAttempts + ' attempts. Giving up.');
 
            }
        // Update depth every 3 frames for performance
             return;
        frameCount++;
        if (frameCount % 3 === 0) {
             updateDepth();
         }
         }
       
 
         console.log('[TagCloud] Placeholder found after ' + attempts + ' attempts! Creating canvas...');
         requestAnimationFrame(animate);
       
    }
        // Create canvas element dynamically
 
        var canvas = document.createElement('canvas');
    // Initial depth calculation
        canvas.id = 'tagcanvas';
    updateDepth();
        canvas.width = 800;
    animate();
        canvas.height = 400;
 
         canvas.style.maxWidth = '100%';
    // Mouse drag controls
        canvas.style.height = 'auto';
    var isDragging = false, prevX = 0, prevY = 0;
       
 
        // Clear placeholder and add canvas
    cloud.onmousedown = function(e) {
        placeholder.innerHTML = '';
         if (e.target.tagName !== 'A') {
        placeholder.appendChild(canvas);
            isDragging = true;
       
            autoRotate = false;
        console.log('[TagCloud] Canvas created and added to DOM');
            prevX = e.clientX;
       
            prevY = e.clientY;
        var ctx = canvas.getContext('2d');
            cloud.style.cursor = 'grabbing';
        if (!ctx) {
             e.preventDefault();
             console.error('[TagCloud] Could not get 2D context');
            return;
         }
         }
       
    };
        var width = canvas.width;
 
        var height = canvas.height;
    document.onmousemove = function(e) {
       
         if (isDragging) {
        console.log('[TagCloud] Canvas size:', width, 'x', height);
             targetAngleY += (e.clientX - prevX) * 0.5;
          
            targetAngleX = Math.max(-40, Math.min(40, targetAngleX - (e.clientY - prevY) * 0.3));
        // Tags configuration - 300% larger (3x original sizes)
             prevX = e.clientX;
        var tags = [
             prevY = e.clientY;
            { text: 'Satya Nadella', url: '/wiki/Satya_Nadella', size: 72 },
             { text: 'Tim Cook', url: '/wiki/Tim_Cook', size: 66 },
            { text: 'Elon Musk', url: '/wiki/Elon_Musk', size: 78 },
            { text: 'Mark Zuckerberg', url: '/wiki/Mark_Zuckerberg', size: 60 },
            { text: 'Sundar Pichai', url: '/wiki/Sundar_Pichai', size: 60 },
            { text: 'Andy Jassy', url: '/wiki/Andy_Jassy', size: 54 },
            { text: 'Jensen Huang', url: '/wiki/Jensen_Huang', size: 66 },
            { text: 'Lisa Su', url: '/wiki/Lisa_Su', size: 54 },
            { text: 'Mary Barra', url: '/wiki/Mary_Barra', size: 54 },
            { text: 'Jamie Dimon', url: '/wiki/Jamie_Dimon', size: 54 },
            { text: 'Microsoft', url: '/wiki/Microsoft', size: 48 },
            { text: 'Apple', url: '/wiki/Apple_Inc.', size: 48 },
            { text: 'Amazon', url: '/wiki/Amazon', size: 48 },
            { text: 'Google', url: '/wiki/Google', size: 48 },
            { text: 'Tesla', url: '/wiki/Tesla', size: 48 },
            { text: 'Leadership', url: '/wiki/Category:Chief_executive_officers', size: 42 },
            { text: 'Innovation', url: '/wiki/Category:Business_strategies', size: 42 },
            { text: 'Technology', url: '/wiki/Category:Companies', size: 42 },
            { text: 'Strategy', url: '/wiki/Category:Business_strategies', size: 42 },
            { text: 'Cloud Computing', url: '/wiki/Category:Industry_analysis', size: 42 }
        ];
       
        // Initialize 3D positions
        var radius = 180;
        var dtr = Math.PI / 180;
        var mcList = [];
        var lasta = 1;
        var lastb = 1;
        var tspeed = 0.5;
        var size = 250;
        var mouseX = 0;
        var mouseY = 0;
        var active = false;
       
        // Build tag objects
        for (var i = 0; i < tags.length; i++) {
            var oTag = {};
            oTag.offsetWidth = tags[i].size * 5;
            oTag.offsetHeight = tags[i].size;
             oTag.text = tags[i].text;
             oTag.url = tags[i].url;
            oTag.size = tags[i].size;
            mcList.push(oTag);
         }
         }
       
    };
        var sa, ca, sb, cb, sc, cc;
 
       
    document.onmouseup = function() {
        function sineCosine(a, b, c) {
        if (isDragging) {
            sa = Math.sin(a * dtr);
             isDragging = false;
             ca = Math.cos(a * dtr);
             cloud.style.cursor = 'grab';
             sb = Math.sin(b * dtr);
             setTimeout(function() { autoRotate = true; }, 2000);
             cb = Math.cos(b * dtr);
            sc = Math.sin(c * dtr);
            cc = Math.cos(c * dtr);
         }
         }
       
    };
        function positionAll() {
 
            var phi = 0;
    // Mouse wheel zoom
            var theta = 0;
    cloud.onwheel = function(e) {
            var max = mcList.length;
        e.preventDefault();
           
        targetZoom = Math.max(0.8, Math.min(2.5, targetZoom + (e.deltaY > 0 ? -0.1 : 0.1)));
            for (var i = 0; i < max; i++) {
        autoRotate = false;
                phi = Math.acos(-1 + (2 * i + 1) / max);
        clearTimeout(cloud.zoomTimeout);
                theta = Math.sqrt(max * Math.PI) * phi;
        cloud.zoomTimeout = setTimeout(function() { autoRotate = true; }, 1500);
               
    };
                mcList[i].cx = radius * Math.cos(theta) * Math.sin(phi);
 
                mcList[i].cy = radius * Math.sin(theta) * Math.sin(phi);
    // Touch support
                mcList[i].cz = radius * Math.cos(phi);
    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() {
 
            ctx.clearRect(0, 0, width, height);
    document.ontouchmove = function(e) {
           
        if (isDragging && e.touches.length === 1) {
            for (var i = 0; i < mcList.length; i++) {
            targetAngleY += (e.touches[0].clientX - prevX) * 0.5;
                var tag = mcList[i];
            targetAngleX = Math.max(-40, Math.min(40, targetAngleX - (e.touches[0].clientY - prevY) * 0.3));
                var x = tag.x + width / 2;
            prevX = e.touches[0].clientX;
                var y = tag.y + height / 2;
            prevY = e.touches[0].clientY;
               
                var alpha = Math.max(0.2, Math.min(1, tag.alpha));
                var fontSize = Math.max(10, tag.size * tag.scale);
               
                ctx.save();
                // Use Wikipedia-style serif font (Linux Libertine, Georgia, Times)
                ctx.font = fontSize + 'px "Linux Libertine", Georgia, "Times New Roman", serif';
                ctx.fillStyle = 'rgba(255, 255, 255, ' + alpha + ')';
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
                ctx.shadowBlur = 4;
                ctx.shadowOffsetX = 0;
                ctx.shadowOffsetY = 2;
                ctx.fillText(tag.text, x, y);
                ctx.restore();
               
                tag.cx = x;
                tag.cy = y;
            }
         }
         }
       
    };
         function depthSort() {
 
             mcList.sort(function(a, b) {
    document.ontouchend = function() {
                return (b.cz - a.cz);
         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;
          
          
         function update() {
         if (windowWidth > 1200) {
             var a, b;
             imageWidth = Math.floor((windowWidth - 100) / 3 * 0.7);
           
        } else if (windowWidth > 768) {
            if (active) {
             imageWidth = Math.floor((windowWidth - 80) / 2 * 0.7);
                a = (-Math.min(Math.max(-mouseY, -size), size) / radius) * tspeed;
        } else if (windowWidth > 480) {
                b = (Math.min(Math.max(-mouseX, -size), size) / radius) * tspeed;
             imageWidth = Math.floor((windowWidth - 40) * 0.8);
            } else {
        } else {
                a = lasta * 0.98;
            imageWidth = Math.floor((windowWidth - 40) * 0.9);
                b = lastb * 0.98 + 0.01;
             }
           
            lasta = a;
            lastb = b;
           
            if (Math.abs(a) <= 0.01 && Math.abs(b) <= 0.01) {
                return;
            }
           
            var c = 0;
            sineCosine(a, b, c);
              
            for (var i = 0; i < mcList.length; i++) {
                var rx1 = mcList[i].cx;
                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;
                var ry2 = ry1;
                var rz2 = rx1 * (-sb) + rz1 * cb;
               
                var rx3 = rx2 * cc + ry2 * (-sc);
                var ry3 = rx2 * sc + ry2 * cc;
                var rz3 = rz2;
               
                mcList[i].cx = rx3;
                mcList[i].cy = ry3;
                mcList[i].cz = rz3;
               
                var per = size / (size + rz3);
               
                mcList[i].x = rx3 * per;
                mcList[i].y = ry3 * per;
                mcList[i].scale = per;
                mcList[i].alpha = per;
                mcList[i].alpha = (mcList[i].alpha - 0.6) * (10 / 6);
            }
           
            doPosition();
            depthSort();
         }
         }
       
 
         // Event handlers
         imageWidth = Math.max(150, Math.min(400, imageWidth));
        canvas.onmouseover = function() {
 
            active = true;
         $('table[style*="width: 33%"] img, table[style*="width: 25%"] img').each(function() {
        };
             var $img = $(this);
          
             var src = $img.attr('src');
        canvas.onmouseout = function() {
             if (!src || src.indexOf('File:') === -1) return;
            active = false;
 
        };
             if (src.indexOf('/thumb/') !== -1) {
       
                 $img.attr('src', src.replace(/\/\d+px-/, '/' + imageWidth + 'px-'));
        canvas.onmousemove = function(ev) {
             var rect = canvas.getBoundingClientRect();
             mouseX = ev.clientX - rect.left - width / 2;
             mouseY = ev.clientY - rect.top - height / 2;
        };
       
        canvas.onclick = function(ev) {
            var rect = canvas.getBoundingClientRect();
            var mx = ev.clientX - rect.left;
            var my = ev.clientY - rect.top;
           
             for (var i = 0; i < mcList.length; i++) {
                var tag = mcList[i];
                var dx = mx - tag.cx;
                 var dy = my - tag.cy;
                var dist = Math.sqrt(dx * dx + dy * dy);
               
                if (dist < 50) {
                    window.location.href = tag.url;
                    break;
                }
             }
             }
        };
 
       
            $img.css({ 'max-width': '100%', 'height': 'auto', 'width': 'auto', 'display': 'block', 'margin': '0 auto' });
        canvas.style.cursor = 'pointer';
            $img.removeAttr('width').removeAttr('height');
       
            $img.parent('a').css({ 'display': 'block', 'text-align': 'center' });
        // Initialize
        });
        sineCosine(0, 0, 0);
        positionAll();
        setInterval(update, 30);
       
        console.log('[TagCloud] Successfully initialized with large text! Animation started.');
     }
     }
      
 
     // Start trying to find the placeholder
     resizeCEOImages();
     tryInitialize();
 
})();
     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);
    });
});