// Copyright 2007 Hans-Thomas Mueller
// Distributed under the terms of the GNU General Public License v2
//=============================================================================
//   navigation.js --- select box navigation
//=============================================================================

function makeNavigation() {
    var choice = function(e) {
        window.location = e.src().value;
    }
    var chooser = function(choices) {
        var option = function(item) {
            var attrs = {'value': item.href};
            if (item.selected)
                attrs.selected = 'yes';
            return OPTION(attrs, item.title);
        }
        var group = function(group) {
            return OPTGROUP({'label': group.label}, map(option, group.items));
        }
        var options = new Array();
        if(choices.items != undefined)
            extend(options, map(option, choices.items));
        if(choices.groups != undefined)
            extend(options, map(group, choices.groups));
        var chooser = SELECT({'id': 'navigation-' + choices.name, 'class': 'chooser'}, options);
        connect(chooser, 'onchange', choice);
        return chooser;
    }
    swapDOM('navigation', FORM({'id': 'navigation'}, map(chooser, navigation)));
}
addLoadEvent(makeNavigation);

//.............................................................................
//   navigation.js
