Object.extend(String.prototype, {
    equal: function(s) {
        return (this == s);   
    }
});


Menu = new Class.create();
Menu.prototype = {
    
    m: null,
    opts: null,
    
    initialize: function(id) {
        this.m = $(id);
        if (!this.m) {
            throw "initialize: Element nenalezen: " + id;
        }
        if (!this.m.tagName.toUpperCase().equal('UL')) {
            throw "initialize: Element neni 'UL'";
        }
        
        lis = $A(this.m.getElementsByTagName('li'));
        for (var i = 0; i < lis.length; i++) {
            
            if (lis[i].parentNode != this.m) {
                lis[i] = null;
            }
            
        }
        
        this.opts = lis.compact();
        
        if (!this.opts.length) {
            throw "initialize: Zadne polozky";
        }
        
        for (var i = 0; i < this.opts.length; i++) {
            this.opts[i].block = $A(this.opts[i].getElementsByTagName('ul')).first();
            if (this.opts[i].block) {
                this.opts[i].block.opt = this.opts[i];
            }
            this.opts[i].menu = this;
        }
    },
    
    start: function() {
        for (var i = 0; i < this.opts.length; i++) {
            (this.opts[i].block) && Element.hide(this.opts[i].block);
            this.opts[i].onmouseover =  function() { 
                (this.block) && Element.show(this.block);    
            }
            this.opts[i].onmouseout =  function() { 
                (this.block) && Element.hide(this.block);    
            }        
            

        }
    }
    
    
    
    
}

