Event.observe(window, 'load', function() {
    menuHighlight();
});

function menuHighlight() {
    var i = window.location.pathname == '/ns/cv.php' ? 1 : 0;
    Ext.select('#menu li').elements[i].setAttribute('class', 'active');
    //$('menu').childNodes[1].class = "active"
}

function makeCollapsible() {
    // Adds the togglable box arrow (wedge div)
    Ext.select(".wbox").each(function(wbox) {
        Ext.DomHelper.append(wbox, {tag: 'div', cls: 'wedge wedgeup'});
    });
    // Attaches events for displaying togglable box
    Ext.select(".toggler").on({
            click: function(ev) {
                //ev.stopEvent();
                // Hide all already displayed divs
                // FIXME: problem when reclicking an expanded wbox to collapse it
                new Ext.Element(this).parent().select('li .wbox').each(function(el) {
                    if (this != el.parent().dom) el.setVisibilityMode(Ext.Element.DISPLAY).hide();
                }, this);
                // Show clicked li div
                var wbox = Ext.select('.wbox', false, this).setVisibilityMode(Ext.Element.DISPLAY);
                if (wbox.el.isVisible()) wbox.hide(); else wbox.slideIn(null, {duration:.3});
            }
    });
return;
    /* OLD DOM CODE
    var els = document.getElementsByClassName("toggler");
    for (var i=0; i<els.length; i++) {
        // The collapsible element should be the first li contained div
        Event.observe(els[i], 'click', function(ev) {
            Event.stop(ev);
            // Hide all already displayed divs
            var liEls = this.parentNode.getElementsByTagName("li");
            for (var j=0; j<liEls.length; j++) {
                if (liEls[j] == this) continue;
                var box = liEls[j].getElementsByTagName("div")[0];
                if (box) box.style.display = "none";
            }
            // Show clicked li div
            var box = this.getElementsByTagName("div")[0];
            box.style.display = box.style.display == 'block' ? 'none' : 'block';
        });
    }
    */
}


function createPopupLinks() {
    Ext.each(Ext.select('.popup'), function(a) {
        a.on({
            click: function(e) {
                e.stopEvent();
                var window = new Ext.Window({
                    title: '<a href="'+this.href+'" target="_blank" title="Ouvrir dans une nouvelle fenêtre">'+this.href+'</a>',
                    html: '<iframe src="'+this.href+'" style="border:none; width:100%; height:100%"/>',
                    layout: 'fit',
                    width: Ext.getBody().getViewSize().width * 0.8,
                    height: Ext.getBody().getViewSize().height * 0.8,
                    modal: true
                });
                window.show();
            }
        });
    });
}
