var BookmarkMenu = Class.create();
BookmarkMenu.prototype = {
    last:null,
    menu:null,
    start:true,
    initialize: function(menuID) {
        this.menu=$(menuID);
        if (this.menu==null) return;
        var col=$$("#"+menuID+" a"),h=-1;
        for (i=0;i<col.length;i++) {
            col[i].hashID = col[i].href.substr(col[i].href.indexOf("#")+1);
            col[i].cont=$(col[i].hashID+"-cont");
            if (col[i].cont==null) continue;
            col[i].cont.setStyle({display:"none", opacity:0});
            if ((location.hash=="" && i==0) || (location.hash=="#"+col[i].hashID))
                this.setActive(col[i]);
            col[i].observe("click", (function(event) { this.switchIt(event) }).bind(this));
            if (col[i].cont.getHeight()>h) h=col[i].cont.getHeight();
        }
        if (this.last==null)
            this.setActive(col[0]);
        else if (location.hash!="")
            new Effect.ScrollTo(menuID, {duration: 0,queue:"end"});
        h = h-this.last.cont.getHeight();
        if (navigator.userAgent.indexOf("MSIE 6.0")!=-1 && h>0) {
            var c=$("content"); c.setStyle({height:(c.getHeight() + h)+"px"});
            $("footerbanner").setStyle({bottom:"0px"});
        }
    },
    switchIt:function(e) {
        var a=Event.element(e);
        e.stop();
        if (this.last!=a)
            this.setActive(a);
        else
            a.blur();
    },
    setActive:function(a) {
        if (this.start) {
            a.parentNode.className="active";
            a.cont.setStyle({display: "block", opacity:1});
            this.start=false;
        }
        else {
            var l=this.last;
            new Effect.Fade(l.cont, {duration: 0.3, from: 1, to: 0, queue: { position: "end", scope: "bookmark" },
                                        afterFinish: function() { a.cont.setStyle({display:"block", opacity:0}); l.parentNode.className=""; a.parentNode.className="active"; a.blur(); }
                                    });
            new Effect.Fade(a.cont, {duration: 0.3, from: 0, to: 1, queue: { position: "end", scope: "bookmark" } });
            location.hash = a.hashID;
        }
        this.last=a;
    }
}
