window.addEvent('load',function(){
    if( $('column1') ){
        var menu = new cyberMenu();
    }
});

var cyberMenu = new Class({
    initialize:function(options){
        this.environment(options);
        this.stack = {};
    },

    environment:function(options){
        $$('div#column1 ul li.MenuLevelOne').each(function(el,i){
            this.bindClick(el,"MenuLevelOne");
        }.bind(this));

        $$('div#column1 ul li ul li').each(function(elBtm,j){
            $(elBtm).style.display = 'none'; //removed onmouse over of second level
            /*	$(elBtm).addEvent('mouseover', this.checkLi.pass([elBtm],this) );
            $(elBtm).addEvent('mouseout', this.checkLi.pass([elBtm],this) );   */
        }.bind(this));

        $$('.MenuLevelOne').each(function(mItem,k){
            mItem.addClass(k);
            if(Cookie.get("cxcmscoreadminmenu") == k ) {
                this.checkLi(mItem);
                this.found = true;
            }
        }.bind(this));

        if(!this.found ) this.checkLi($$('.0')[0])
    },

    bindClick:function(el,level){
        $(el).style.cursor='pointer';
        $(el).addEvent('click', function(e){
            e = new Event(e);
            try{ // surpress clicking of ahref link
                if (e.target.hasClass(level)){
                    this.checkLi(el);
                }
            }catch(e){};
        }.bind(this));
    },

    checkLi:function(el){
        $(el).getChildren().each(function(obj){
            if($(obj).getChildren()){
                $(obj).getChildren().each(function(li){
                    this.state = ( $(li).style.display == 'none' ) ? this.openLi(li) : this.closeLi(li);
                }.bind(this));
            }
        }.bind(this));
    },

    openLi:function(el){
        Cookie.set("cxcmscoreadminmenu", el.getParent().getParent().className.split(' ')[1], {path: "/"});
        $(el).style.display = 'block';
    },
    closeLi:function(el){
        Cookie.set("cxcmscoreadminmenu", 0, {path: "/"});
        $(el).style.display = 'none';
    }
});
