/*
 * @author Jacek Suchocki
 */

// Resize navigation node
function resizeNavNode(node)
{
    //    console.log(node);
    var nodes = node.select('li.level1');
    var count = nodes.size();
    //    console.log(count);

    if(count > 0)
    {
        // Get maximum heights
        var rowsMax = [];
        nodes.each(function(s, index)
        {
            var height = s.getHeight();
            var row = Math.floor(index / 4);
            if(rowsMax.length > row)
            {
                if(rowsMax[row] < height)
                {
                    rowsMax[row] = height;
                }
            }
            else
            {
                rowsMax.push(height);
            }
        });

        // Set height values
        var height = 0;
        nodes.each(function(s, index)
        {
            var row = Math.floor(index / 4);
            if(rowsMax.length > row)
            {
                height = rowsMax[row];
                Element.setStyle(s, {
                    height: typeof height == 'number' ? height + 'px' : height
                });
            }
        });
    }
}

document.observe('dom:loaded', function()
{    
    $$('li.level0').each(function(s)
    {
        resizeNavNode(s);
    });
});


