if (!document.getElementById) {
    document.getElementById = function() { return null; }
}

var menuCookie = "menusToExpand";
var itemCookie = "itemToHighlight";

function getElementsByClass(name) {
    var found = 0;
    var elems = new Array();
    var alltags = document.getElementsByTagName("*");
    if (alltags) {
        for (i=0; i < alltags.length; i++) {
            if (alltags[i].className == "") {
                continue;
            }
            classes = alltags[i].className.split(" ");
            for (ii=0; ii<classes.length; ii++) {
                if (classes[ii] == name) {
                    elems[found++] = alltags[i];
                    continue;
                }
            }
        }
    }
    return(elems);
}

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;
   
    var actualMenu = document.getElementById('actualMenu');
    if (actualMenu && actualMenu.value==menuId) {
        menu.parentNode.style.backgroundImage 
                = "url(images/minus.gif)";
        menu.style.display = "block";
        actuator.style.color = "red";
        document.getElementById(actualMenu.value).parentNode.style.backgroundImage 
                = "url("+frontendUrl+"/images/minus.gif)";
        document.getElementById(actualMenu.value).style.display = "block";
    }

    actuator.onclick = function() {
        // Tárolja a jelenlegi állapotot
        var display = menu.style.display;    
        // Bezár minden csoportot
        var menuElements = getElementsByClass('menu');
        for(i=0; i<menuElements.length; i++) {
            menuElements[i].parentNode.style.backgroundImage 
                    = "url(images/plus.gif)";
            menuElements[i].style.display = "none";
        }        
        // Kezeli a csoportot        
        this.parentNode.style.backgroundImage =
            (display == "block") ? "url(images/plus.gif)" : "url(images/minus.gif)";
        menu.style.display = (display == "block") ? "none" : "block";
        return false;
    }
}


