var fdMenu = new Class({
    initialize: function() {
        this.container = $('topMenu');
        this.show();
        this.people = new Array();
    },

    addPerson: function(name) {
        this.people[this.people.length] = name;
    },
    
    show: function() {
        this.container.empty();
                this.addItem('home', '/index.html', 52);
                this.addSeparator();
        this.addItem('our story', '/feldman/history.html', 64);
        this.addSeparator();
        this.peopleMenu = this.addItem('our people', null, 72);
        this.addSeparator();
        this.addItem('national and global affiliates', '/feldman/why.html', 170);
        this.addSeparator();
        this.addItem('contact us', '/feldman/contact.html', 72);
    },
    
    addItem: function(name, url, width) {
        var el = new Element('div', { 'styles': { 'float': 'left', 'width': width, 'text-align': 'center' }, 'events': {
            'mouseover': function() { this.setStyles( {'font-weight': 'bold', 'color': '#000' }); },
            'mouseout': function() { this.setStyles( {'font-weight': 'normal', 'color': '#455560' }); }
            }}).setText(name).injectInside(this.container);
        if (url) {
            el.setStyle('cursor', 'pointer');
            el.addEvent('click', function() { window.location.href=url; });
        }
        else {
            el.addEvent('mouseover', function() { this.showPopupMenu(el); }.bind(this));
            el.addEvent('mouseout', function() { fdMenu.hidePopupMenu(); });
        }
    },
    
    addSeparator: function() {
        new Element('div', { 'styles': { 'float': 'left', 'color': '#d0d0d0' }}).setText('|').injectInside(this.container);
    },
    
    showPopupMenu: function(el) {
        if (!fdMenu.popupMenu) {
            fdMenu.popupMenu = new Element('div', { 'styles': { 'position': 'absolute', 'padding': '4px', 
                'background-color': '#faf0e7', 'border': 'solid 1px #fff', 'display': 'none' }, 'events': {
                'mouseover': function() { fdMenu.keepPopupMenuActive(); },
                'mouseout': function() { fdMenu.hidePopupMenu(); }
                }}).injectInside(document.body);
            
            this.people.each(function(person) {
                var item = new Element('div', { 'styles': { 'z-index': '999', 'color': '#e77222', 'padding': '4px', 'cursor': 'pointer' }, 'events': {
                    'mouseover': function() { this.setStyle('font-weight', 'bold'); },
                    'mouseout': function() { this.setStyle('font-weight', 'normal'); },
                    'click': function() { window.location.href = '/feldman/bio/' + person + '.html'; }
                    }}).setText(person).injectInside(fdMenu.popupMenu);
            });

            fdMenu.popupMenu.setStyles({ 'display': 'inline', 'left': (el.getLeft()-4)+'px', 'top': (el.getTop()+16)+'px' });
        }
    }
});

fdMenu.hidePopupMenu = function() {
    fdMenu.popupTimer = setTimeout(fdMenu.doHidePopupMenu, 200);
};
fdMenu.doHidePopupMenu = function() {
    if (fdMenu.popupMenu) {
        fdMenu.popupMenu.remove();
        fdMenu.popupMenu = null;
    }
};
fdMenu.keepPopupMenuActive = function() {
    fdMenu.popupTimer = clearTimeout(fdMenu.popupTimer);
};

window.addEvent('domready', function(){
  var menu = new fdMenu();
menu.addPerson('Fred Feldman');
menu.addPerson('Corey J. Daxon');
menu.addPerson('Ron Meyers');
menu.addPerson('Warren M. Lundy');
menu.addPerson('Patrick Rowan');
menu.addPerson('John Hierlihy');
menu.addPerson('Katherine VanderBerg');
menu.addPerson('Sean Stewart');
menu.addPerson('Wendy Campbell');
});
