var BookmarkMenu = Class.create();
BookmarkMenu.prototype = {
    last:null,
    start:true,
    initialize: function(menuID) {
        this.menu=$(menuID);
        if (this.menu==null) return;
        this.menuItem=new Array();
        var col=this.menu.getElementsByTagName("a"), nr=1;
        for (i=0;i<col.length;i++) {
            var pID = col[i].href.match(/.*#([a-z-]+)/), p=$(pID[1]);
            if (p==null) continue;
            this.menuItem.push(col[i]);
            col[i].pID=pID[1];
            col[i].nr=this.menuItem.length;
            col[i].panel=p;
            $(col[i]).observe("click", (function(event) { this.setActive(event); }).bind(this))
            if (window.location.hash=="#"+pID[1])
                nr=i+1;
        }
        if (this.menuItem.length>1) {
            $(this.menu).setStyle({visibility:"visible"});
            this.change(nr);
        }
    },
    setActive:function(e){
        var el=Event.element(e);
        this.change(el.nr);
        el.blur();
        e.stop();
        this.last=el.nr;
    },
    change:function(nr){
        var cl="", s="", op=0;
        for (i=0;i<this.menuItem.length;i++) {
            cl=""; s="none", op=0;
            if (i+1==nr) {
                cl="active";
                $(this.menuItem[i].panel).setStyle({display:"block"});
                //if (!this.start)
                    //$(this.menuItem[i].panel).fade({duration: 1, from:0, to:1});
                //window.location.hash=this.menuItem[i].pID;
            }
            else {
                //if (i+1==this.last)
                    //$(this.menuItem[i].panel).fade({duration: 0.8, from:1, to:0});
                $(this.menuItem[i].panel).setStyle({display:s}); //, opacity:op});
            }
            this.menuItem[i].parentNode.className=cl;
        }
        this.start=false;
    }
}
