var churchmoomenu = new Class({
    Implements: [Options],
    options: {
        bgiframe: false,
        hoverClass: 'sfHover',
        delay: 1000,
        animate: {
            link:'cancel',
            duration: 1000,
            transition: Fx.Transitions.Elastic.easeOut
        }
    },
    initialize: function (b, c) {
        if (b) {
            this.setOptions(c);
            //if (Browser.Engine.trident4) this.options.delay = 50;
            this.element = $(b);
            this.element.getElements('li').each(function (a) {
                if (a.hasClass('parent')) {
                    var img = 'd';
                    if (a.getParent().getParent().hasClass('parent')) {
                        img = 'r';
                    }
                    var span = a.getElement('a').getElement('span');
                    var arrow = new Element('div', {
                        'styles': {
                            'padding-right':'12px',
                            'background-image': 'url(../images/arrow_' + img + '.gif)',
                            'background-repeat':'no-repeat',
                            'background-position':'100% 50%'
                        }
                    });
                    if (span) {
                        arrow.wraps(span);
                    }
                }
                a.addEvents({
                    'mouseover': this.over.bind(this, a),
                    'mouseout': this.out.bind(this, a)
                })
            },
            this)
        }
    },
    over: function (b) {
        $clear(b.sfTimer);
        if (!b.hasClass(this.options.hoverClass)) {
            
            b.addClass(this.options.hoverClass);
            var f = b.getElement('ul');
            if (f) {
                //fix some nasty line that shows at bottom of menu
                f.setStyle('overflow', 'hidden');
                f.getParents('ul').each(function (a1) {
                    a1.setStyle('overflow', 'visible')
                });
                f.set('tween', this.options.animate).tween('height',f.getHeight()/2,f.getHeight());
            }
            b.getSiblings().each(function (a) {
                a.removeClass(this.options.hoverClass)
            },
            this)
        }
    },
    out: function (e) {
        var f = this.options.hoverClass;
        e.sfTimer = (function () {
            
            e.removeClass(f);
        }).delay(this.options.delay, this)
    }
});
churchmoomenu.implement(new Options);
