window.addEvent("domready", function (ev) {new menuClass();});
var menuClass = new Class({
    initialize:function () {
        this.currentsub = false;
        this.currentsubsub = false;
        this.currentsubsubsub = false;
        $$("li").addClass("submenu");
        $("treemenu2").getElements("li a.menuItem").each(function(el, ind) {
                if(!$chk(el.getParent("li").getElement("ul"))) return;
                el.addEvent("click", this.openSubMenu.bindWithEvent(this, el.getParent("li")));
                this.closeSubMenu(el.getParent("li"));
        }, this);
    },
    openSubMenu : function (e, thesubmenu){
        e.stopPropagation().stop();
        var isclosed = thesubmenu.getElement("ul").getStyle("display") == "none";
        this.closeSubMenu(this.currentsub, thesubmenu);
        if(this.currentsub == thesubmenu && !isclosed) return true;
        this.currentsub = thesubmenu;
        thesubmenu.getElement("ul").setStyle("display","block");
        return true;
    },
    closeSubMenu : function (thesubmenu, newsubmenu) {
        if(!$chk(thesubmenu)) return false;
        if(thesubmenu.hasChild(newsubmenu)) return false;
        var currentToClose = thesubmenu;
        var iter = 1;
        while((!currentToClose.hasChild(newsubmenu) || newsubmenu == currentToClose) && iter < 10){
              currentToClose.getElement("ul").setStyle("display","none");
              currentToClose = currentToClose.getParent("li");
              if(!$chk(currentToClose)) break;
              iter +=1;
        }
        return true;
    }
});
var OLDID = 1;
function show(id, bg) 
{
    unshow();
    $("div"+id).setStyle("display","block");
	OLDID=id;
    if(bg == 1) document.body.style.backgroundImage="url('IMAGES/textBG.png')";
    else document.body.style.backgroundImage="url('IMAGES/videoBG.png')";
}
function unshow()
{
    if(!$("div"+OLDID)) return;
    else $("div"+OLDID).setStyle("display","none");
}