/*
Creates a jump menu, select box from an unordered list... ul.jump
*/
var jumpMenuList = Class.create({

    initialize : function(ul, i) {
        // Setup variables
        var a;
        var liElements = ul.childElements();

        // Create Select
        var newSelect = Builder.node('select', { id : 'jumpMenu_' + i, className : 'jumpmenu' });
        if (AC.Detector.isWebKit()) {
            newSelect.style.border = '1px solid #bdbdbd';
        }

        // Add options
        var title = ul.title;
        if (title) {
            newSelect.options[0] = new Option(title);
            newSelect.options[0].value = '';
        }
        liElements.each(function(li, x) {
            a = li.down(0);
            newSelect.options[x + 1] = new Option(a.innerHTML, a.readAttribute('href'));
        });

        // Swap ul for Select
        ul.replace(newSelect);

        // Add onchange event
        Event.observe(newSelect, 'change', function(){
            if (this.value != '') {
                window.location = this.value;
            }
        }.bind(newSelect));
    }

});

Event.observe(window, 'load', function() {

    // Gather all of the lists to create menus
    var ulElements = $$('ul.jump');

    // Cycle through them and replace
    if (ulElements.length > 0) {
        ulElements.each(function(ul, x) {
            new jumpMenuList(ul, x);
        });
    }

});
