menu = function(inittheme, initsubtheme) {

    this.themes=new Array;
    this.themes[8]=new starttheme(8);
    //this.themes[8].off();

    for (var i=0;i<8;i++) {
        this.themes[i]=new theme(i);
    }

    this.aktivetheme=this.themes[inittheme];
    this.aktivetheme.on(initsubtheme);
    
    document.getElementById("des_content").onmouseover=switchchildoff;
    document.getElementById("des_balken").onmouseover=switchchildoff;
};

menu.prototype = {
    __class__: menu,

    showtheme: function(index, subindex) {
        this.aktivetheme.off();
        if ((typeof(index) == 'undefined') && (typeof(subindex)=='undefined')){
            this.aktivetheme=this.themes[8];
            subindex=0;
        } else {
            this.aktivetheme=this.themes[index];
        }
        this.aktivetheme.on(subindex);
    }
};


function theme(index) {
    var url;

    this.index=index;
    this.tempchild="empty";
    this.aktivechild="empty";

    this.aktiveblock=document.getElementById("des_menu1box_"+index+"_a");
    this.passiveblock=document.getElementById("des_menu1box_"+index+"_p");
    this.passiveblock.style.display="block";

    //Subtheme
    this.childblock=document.getElementById("menu2box_"+index);
    this.childnumber=this.childblock.getElementsByTagName("div").length;
    this.childs=new Array;

    for (var i=0;i<this.childnumber;i++) {
        this.childs[i]=new subtheme(this.index, i);
    }

    //Links korrigieren
    url=this.aktiveblock.getElementsByTagName("a")[0].href+'/ahah';
    url="javascript:load_content(\"" + url + "\", "+ this.index +"\)";

    this.aktiveblock.getElementsByTagName("a")[0].href=url;
    this.passiveblock.getElementsByTagName("a")[0].href=url;

    this.aktiveblock.onmouseover=switchchildoff;
    this.passiveblock.onmouseover=switchchildoff;
    //EO Creator
};

theme.prototype = {
    __class__: theme,

    //Aktiviert dieses Theme
    on: function(subindex) {
        this.passiveblock.style.display="none";
        this.aktiveblock.style.display="block";
        this.childblock.style.display="block";
        this.tempchild="empty";

        for (i=0;i<this.childnumber;i++) {
            this.childs[i].on("passiv");
        }
        if (typeof(subindex)!="undefined") {
            this.aktivechild=this.childs[subindex];
            this.aktivechild.on("aktiv");
        } else {
            this.aktivechild="empty";
        }
        for (i=this.childnumber;i<8;i++) {
            document.getElementById("menu2_subpic_"+i).src="/_static/desimg/submenu.jpg";
            document.getElementById("menu2_subpic_"+i).onmouseover=switchchildoff;
        }
    },

    //Deaktiviert dieses Theme
    off: function() {
        this.aktiveblock.style.display="none";
        this.passiveblock.style.display="block";
        this.childblock.style.display="none";
    },

    //Switch des Subthemes
    switchsub: function(subindex) {

        //ac kann leer sein, dieser zustand muss bis zum switchsuboff erhalten bleiben
        //ac kann gef?llt sein, muss auch erhalten bleiben welches
        if (this.aktivechild != "empty") {

            if (this.tempchild == "empty") {
                this.aktivechild.off();
                this.tempchild=this.aktivechild;
                this.aktivechild=this.childs[subindex];
                this.aktivechild.on("aktiv");
            } else {

                if (this.tempchild == "temp") {
                    this.aktivechild.off();
                    this.aktivechild=this.childs[subindex];
                    this.aktivechild.on("aktiv");
                } else {
                    this.aktivechild.off();
                    this.aktivechild=this.childs[subindex];
                    this.aktivechild.on("aktiv");
                }
            }
        } else {
            this.aktivechild=this.childs[subindex];
            this.aktivechild.on("aktiv");
            this.tempchild="temp";
        }
    },

    //Switchoff des Subthemes
    switchsuboff: function() {
        if (this.tempchild != "empty") {

            if (this.tempchild == "temp") {
                this.aktivechild.off();
                this.tempchild="empty";
                this.aktivechild="empty";
            } else {
                this.aktivechild.off()
                this.aktivechild=this.tempchild;
                this.aktivechild.on("aktiv");
                this.tempchild="empty";
            }
        }
    }
};


function starttheme(index) {
    var url;

    this.index=index;
    this.aktivechild="empty";
    var children = document.getElementById("news_text").getElementsByTagName("a");
    var child = children.length;
    
    for (var i=0;i<child;i++) {
            url=children[i].href;
            url='javascript:load_content("'+url+'/ahah", '+index+', 0);';
            children[i].href=url;
    }

}

starttheme.prototype = {
    __class__: starttheme,

    //Aktiviert dieses Theme
    on: function() {
        for (var i=0;i<8;i++) {
            document.getElementById("menu2_subpic_"+i).style.display="none";
        }
        document.getElementById("des_banner").src="/_static/desimg/banner_-1.jpg";
        document.getElementById("menu2_news").style.display="block";
    },

    //Deaktiviert dieses Theme
    off: function() {
        document.getElementById("menu2_news").style.display="none";
        document.getElementById("des_banner").src="/_static/desimg/banner_bg.png";
    },

    //Switch des Subthemes
    switchsub: function(subindex) {
        true;
    },

    //Switchoff des Subthemes
    switchsuboff: function() {
        true;
    }
};


function subtheme(index, subindex) {
    var url;

    this.index=index;
    this.subindex=subindex;

    this.block=document.getElementById("menu2box_"+this.index).getElementsByTagName("div")[subindex];
    this.block.className="menu2_passiv";
    this.block.id="menu2_subblock_"+this.index+"_"+this.subindex;
    this.block.onmouseover=switchchild;

    this.aktiveimage=new Image;
    this.aktiveimage.src="/_static/desimg/menu_sub_"+this.index+"_"+this.subindex+"_a.jpg";
    this.passiveimage=new Image;
    this.passiveimage.src="/_static/desimg/menu_sub_"+this.index+"_"+this.subindex+"_p.jpg";

    //Links korrigieren
    url=this.block.getElementsByTagName("a")[0].href+'/ahah';
    url='javascript:load_content("'+url+'", '+ this.index +', '+ this.subindex +');';
    this.block.getElementsByTagName("a")[0].href=url;
};

subtheme.prototype = {
    __class__: subtheme,

    //Aktiviert dieses Subtheme
    on: function(apswitch) {

        if (apswitch == "aktiv") {
            document.getElementById("menu2_subpic_"+this.subindex).src=this.aktiveimage.src;
            this.block.className="menu2_aktiv";
        } else {
            document.getElementById("menu2_subpic_"+this.subindex).src=this.passiveimage.src;
            this.block.className="menu2_passiv";
        }
        document.getElementById("menu2_subpic_"+this.subindex).style.display="block";
        document.getElementById("menu2_subpic_"+this.subindex).parentNode.style.display="block";
        document.getElementById("menu2_subpic_"+this.subindex).onmouseover=switchchild;
    },

    //Deaktiviert dieses Subtheme
    off: function() {
        document.getElementById("menu2_subpic_"+this.subindex).src=this.passiveimage.src;
        document.getElementById("menu2_subpic_"+this.subindex).onmouseover=switchchild;
        this.block.className="menu2_passiv";
    }
}



//Direkt gefeuerte Menu-Events
//On
function switchchild() {
    if (document.menu) {
        var child=this.id.replace(/.*_/,"");
        document.menu.aktivetheme.switchsub(child);
    }

}
//Off
function switchchildoff() {
    if (document.menu) {
        document.menu.aktivetheme.switchsuboff();
    }
}


