var Menu = Class.create();
Menu.defaultHighlightColor = "#FFFF99";
Menu.prototype = {
    initialize: function(href, base) {
        this.options = Object.extend({
            hoverClassName: 'hoverMenu',
            highlightcolor: Menu.defaultHighlightColor,
            highlightendcolor: "#EEEEEE"
        });
        this.menu = $('mainmenu');
        this.items = this.menu.getElementsBySelector('ul:first-child > li');
        if (!base.match(/\/$/))
            base += '/';
        var found = href==base;
        for (var i=0; i<this.items.length; i++) {
            a = this.items[i].getElementsBySelector('a').first();
            var re = eval('/^'+a.href.replace(/\//g,"\\/")+(found ? '$' : '')+'/i');
            if ((href.match(re) && found) || (href.match(re) && !found && base!=a.href)) {
                a.addClassName('current');
            } else {
                a.addClassName('visit');
                this.items[i].fx1 = this.enterHover.bindAsEventListener(this, this.items[i], this.options);
                this.items[i].fx2 = this.leaveHover.bindAsEventListener(this, this.items[i], this.options);
                Event.observe(this.items[i], 'mouseover', this.items[i].fx1);
                Event.observe(this.items[i], 'mouseout', this.items[i].fx2);
            }
        }
    },

    enterHover: function(event, elem, opts) {
        elem.style.backgroundColor = opts.highlightcolor;
        if (elem.effect) {
            elem.effect.cancel();
        }
        elem.addClassName(opts.hoverClassName)
    },

    leaveHover: function(event, elem, opts) {
        elem.removeClassName(opts.hoverClassName)
        elem.effect = new Effect.Highlight(elem, {
            startcolor: opts.highlightcolor,
            endcolor: opts.highlightendcolor,
            restorecolor: opts.highlightendcolor
        });
    }
};


