Event.observe(window, 'load', function() {
    //   if (!window.XMLHttpRequest) {
    // IE6, older browsers       //new HoverBehavior('tr');
    $$('ul.menu > li').each(function(e) {
        Event.observe(e, 'mouseover', function() {
            Element.addClassName(e, 'hover');
        });
        Event.observe(e, 'mouseout', function() {
            Element.removeClassName(e, 'hover');
        });
    });
    //   }
});

if (!window.BauBoden) var BauBoden = {

    openWindowScrolled: function(link, width, height) {
        window.open(link.href, "Immogelb", "width=" + width + ",height=" + height + ",scrollbars=1,status=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,noresize,resizable=0");
        return false;
    },

    openWindow: function(link, width, height) {
        window.open(link.href, "Immogelb", "width=" + width + ",height=" + height + ",scrollbars=0,status=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,noresize,resizable=0");
        return false;
    },

    closeWindow: function() {
        self.close();
        return false;
    },

    togglePopup: function(popup) {
        $(popup).toggle();
    },

    showBox: function(box) {
        if (!$(box).visible()) {
            $(box).previousSiblings()[0].removeClassName('collapsed');
            $(box).show();
//            Effect.BlindDown(box, { duration: 0.5 });
        }
    },

    toggleBox: function(box) {
        if ($(box).visible()) {
             $(box).previousSiblings()[0].addClassName('collapsed');
             Effect.BlindUp(box, { duration: 0.5 });
        } else {
            $(box).previousSiblings()[0].removeClassName('collapsed');
            Effect.BlindDown(box, { duration: 0.5 });
        }
    }
};

BauBoden.Accordion = Class.create({

    initialize: function(selector) {
        $$(selector).each(function(item) {
            item.observe('click', this.onClick);
        }.bind(this));
    },

    onClick: function(event) {
        var li = $(event.target.parentNode);
        var content = li.select(".content")[0];
        if (li.hasClassName('active')) {
            Effect.BlindUp(content, { duration: 0.5 });
        } else {
            Effect.BlindDown(content, { duration: 0.5 });
        }
        li.toggleClassName('active');
    }

});

BauBoden.NumObj = Class.create({
    SEPARATOR: '/',

    initialize: function(elem) {
        this.firstPart = $(elem + '1');
        this.secondPart = $(elem + '2');
        if (!this.firstPart || !this.secondPart) {
            alert("Couldn't initialize input fields for " + elem);
            alert(this.firstPart + ", " + this.secondPart);
        }
        Event.observe($('submit-link'), 'click', this.submit.bindAsEventListener(this));
        Event.observe(this.firstPart, 'keypress', this.filter.bindAsEventListener(this));
        Event.observe(this.secondPart, 'keypress', this.filter.bindAsEventListener(this));
        Event.observe(this.firstPart, 'keyup', this.notifyListeners.bindAsEventListener(this));
        Event.observe(this.secondPart, 'keyup', this.notifyListeners.bindAsEventListener(this));
    },

    callbacks: {
        onActive: function() {
        },

        onInactive: function() {
        }
    },

    notifyListeners: function(event) {
        if ($F(this.firstPart).length == this.firstPart.maxLength) {
            this.secondPart.focus();
            }
        if ($F(this.firstPart).length + $F(this.secondPart).length > this.firstPart.maxLength) {
            this.callbacks.onActive();
        } else {
            this.callbacks.onInactive();
        }
    },

    filter: function(event) {
        var ch = String.fromCharCode(event.charCode ? event.charCode : event.keyCode);
        if (/\r/.test(ch)) {
            Event.stop(event);
            this.submit();
        }
        if(/\w/.test(ch) && !/\d/.test(ch)) {
            Event.stop(event);
        };
    },

    submit: function(event) {
        var value = $F(this.firstPart) + this.SEPARATOR + $F(this.secondPart);
        document.location.href = $('numHref').href + "&" + $('numHref').name + "=" + escape(value);
    }
});



