
// ============================================================
//      ========== Hierarchical SPAN Menu =============
// SCRIPT by Gerard Ferrandez - Ge-1-doot - APRIL 2005
// http://www.dhteumeuleu.com
// ============================================================
window.onerror = new Function("return true");

// ===== global var ======
var m,menuSpan,textSpan,textPath,W,H;
var dxm = [2,1,2,1,0,0,-1];
var dym = [2,2,1,1,2,1,-1];
var cancelBub = false;
var zB = 0;
var xB = -.5;
var yB = -.5;
var zP = 0;
var xP = 0;
var yP = 0;

// ===== reset this.spa =====
function resetSpa(o){
        if(o.spa){
                o.spa="";
                for(i in o.m)resetSpa(o.m[i]);
        }
}


// ===== insert HTML elements =====
function createHTML(o){
        o.spa                  = document.createElement("span");
        o.spa.style.position   = "absolute";
        o.spa.style.background = o.bkg;
        o.spa.style.cursor     = o.parent==""?"default":"pointer";
        o.spa.onmousedown      = new Function("return false;");
        o.spa.onselectstart    = new Function("return false");
        o.lab                  = document.createElement("span");
        o.lab.className        = "labSpan";
        o.lab.innerHTML        = o.label;
        parentSPAN             = o.parent==""?menuSpan:o.parent.spa;
        o.spa.obj              = o;
        o.spa.onclick          = o.click;
        o.spa.appendChild(o.lab);
        parentSPAN.appendChild(o.spa);
}


function animHTML(o,x,y,w,h){
        // ==== create HTML tags
        if(!o.spa)createHTML(o);
        // ==== SPAN position & size
        if(w<3*W){
                // ==== span size
                o.spa.style.width  = Math.floor(w);
                o.spa.style.height = Math.floor(h);
                // ==== font size
                fs = w/8;
                if(fs>4 && fs<128){
                        o.lab.style.visibility = "visible";
                        o.lab.style.fontSize   = Math.round(fs)+"px";
                } else o.lab.style.visibility = "hidden";
        }
        // ==== span position
        x += o.oX;
        if(x<-W){
                for(i in o.m)o.m[i].oX=x+W;
                x=-W;
        } else for(i in o.m)o.m[i].oX=0;
        y += o.oY;
        if(y<-W){
                for(i in o.m)o.m[i].oY=y+W;
                y=-W;
        } else for(i in o.m)o.m[i].oY=0;
        o.spa.style.left = Math.round(x);
        o.spa.style.top  = Math.round(y);
}


// ==== recursive call
function animateChildren(o,w,h){
        if(w<W/28 || (-W*xB)+(o.px*W*zB)>W-2 || (-W*xB)+(o.px*W*zB)+w<W/6 || (-H*yB)+(o.py*H*zB)>H-2 || (-H*yB)+(o.py*H*zB)+h<H/6){
                // ===== remove invisible spans
                if(o.spa){
                        o.parent.spa.removeChild(o.spa);
                        resetSpa(o);
                }
        } else {
                // ===== anim visible objects
                animHTML(o,o.dx*w,o.dy*h,w,h);
                for(i in o.m) animateChildren(o.m[i],w/3,h/3);
        }
}

function doZoom(x, y, z){
        // ==== increment
        zB += zP;
        xB += xP;
        yB += yP;
        // ==== end zoom
        if(Math.round(z * 1000) == Math.round(zB * 1000)){
                zB = z;
                yB = y;
                xB = x;
                cancelBub = false;
        }
        // ==== loop
        else setTimeout("doZoom("+x+","+y+","+z+");",16);
        // ==== animHTML
        animHTML(m, -W*xB, -H*yB, W*3*zB, H*3*zB);
        for(i in m.m) animateChildren(m.m[i], W*zB, H*zB);
}

// ===== create menu element =====
function createMenu(label, bkg, parent, hlink) {
        // ==== attributes
        this.dx      = parent==""?0:dxm[parent.m.length];
        this.dy      = parent==""?0:dym[parent.m.length];
        this.px      = 0;
        this.py      = 0;
        this.lev     = 0;
        this.parent  = parent;
        this.m       = new Array();
        this.label   = label;
        this.hlink   = hlink;
        this.path    = "";
        this.zoomed  = false;
        this.spa     = "";
        this.lab     = "";
        this.spa.obj = "";
        this.bkg     = bkg;
        this.oX      = 0;
        this.oY      = 0;

        // ===== create nodes - calculate position ====
        this.createNode = function(c,b,h) {
                this.m[this.m.length] = newItem = new createMenu(c, b, this, h);
                newItem.lev = this.lev + 1;
                p = newItem;
                do {
                        n = Math.pow(3,p.lev-1);
                        newItem.px += p.dx/n;
                        newItem.py += p.dy/n;
                        newItem.path = p.label.replace(/ /,"")+"."+newItem.path;
                        p = p.parent;
                }
                while(p!="");
                return newItem;
        }

        // ===== node onclick event =====
        this.click = function() {
                if(!cancelBub){
                        if(this.obj.zoomed && this.obj.lev>0){
                                // ===== zoom out
                                this.obj.zoomed = false;
                                this.obj.parent.zoomed = false;
                                this.obj.parent.spa.onclick();
                        } else {
                                // ===== zoom in
                                cancelBub = true;
                                this.obj.zoomed = true;
                                // ===== insert right panel HTML, display path
                                if(document.getElementById(this.obj.label)!=null){
                                        textSpan.innerHTML = "<div style='margin:0px'>"+document.getElementById(this.obj.label).innerHTML+"</div>";
                                } else textSpan.innerHTML = document.getElementById("default").innerHTML;
                                textPath.innerHTML = this.obj.path;
                                // ===== run zoom
                                z  = Math.pow(3, this.obj.lev-1);
                                zP = (z-zB)/10;
                                xP = ((z*this.obj.px)-xB)/10;
                                yP = ((z*this.obj.py)-yB)/10;
                                doZoom(z*this.obj.px, z*this.obj.py, z);
                                if(this.obj.hlink){
                                        // ==== open hyperlink window
                                        window.open(this.obj.hlink,"_blank");
                                }
                        }
                }
// TODO
//startScrolling();
//startSlideShow();
if (this.obj.label == 'bilder') {
  dom_onload();
  // ===== window resize event =====
  window.onresize = diapo.resize;
}

                return false;
        }
}

// ===== resize window ====
function resize(){
        nx = document.body.offsetWidth;
        ny = document.body.offsetHeight;
        W  = Math.round(nx * .4);
        H  = Math.round(ny * .8);
        if (H > W) H = W;
        if (W > H) W = H;
        with(textSpan.style){
                width    = W;
                height   = H;
                left     = 0;
                top      = -H/2;
                fontSize = W/24+"px";
        }
        with(menuSpan.style){
                width    = W;
                height   = H;
                left     = -W;
                top      = -H/2;
        }
        with(textPath.style){
                width    = W*2;
                height   = 18;
                left     = -W;
                top      = H/2;
                fontSize = W/24+"px";
        }
        animHTML(m, -W*xB, -H*yB, W*3*zB, H*3*zB);
        for(var i in m.m) animateChildren(m.m[i], W*zB, H*zB);
}
onresize = resize;


// ===== yo! zyva ! =====
onload = function() {

        menuSpan = document.getElementById("menu");
        textSpan = document.getElementById("text");
        textPath = document.getElementById("path");

        // ===== create menu ======
        m = new createMenu("Mannekings","#000000","");

        // willkommen
        // alben
        m.createNode("alben","#33C111");


  // impressum
        m.createNode("kontakt","#CC4300");
        m.m[1].createNode("haftung","#CC4300");
        m.m[1].createNode("impressum","#FC4300");
        m.m[1].createNode("links","#AC4300");

        // termine
        //   2008
        m.createNode("termine","#116088");


        // bilder
        //   2008
        m.createNode("multimedia","#FB9911");
        m.m[3].createNode("lieder","#003002");
        m.m[3].m[0].createNode("luagabeidl","#116088");
        m.m[3].m[0].createNode("küblböck-song","#5C9185");
        m.m[3].m[0].createNode("du bist mein sonnenschein","#0F5959");
        m.m[3].m[0].createNode("sonstige lieder","#1F4099");
        m.m[3].createNode("bilder","#FC4200");
        m.m[3].m[1].createNode("auftritte","#765666");
        m.m[3].m[1].createNode("pics","#7F3399");
        m.m[3].m[1].createNode("maxi-cover","#7F3355");
        m.m[3].createNode ("texte","#CA0532");


        m.createNode("feedback","#003055");

        m.createNode("facebook","#000000");

/*        m.m[0].m[0].createNode("code","#CC9600");
        m.m[0].m[0].m[1].createNode("reuse","#805E00");
        m.m[0].m[0].m[1].createNode("enforcement","#CC5200");

        m.m[0].m[0].createNode("I ","#7F3300");
        m.m[0].m[0].m[2].createNode("had","#CC9600");
        m.m[0].m[0].m[2].m[0].createNode("planned","#805E00");
        m.m[0].m[0].m[2].m[0].createNode("to","#CC5200");
        m.m[0].m[0].m[2].m[0].m[1].createNode("put","#7F3300");
        m.m[0].m[0].m[2].m[0].m[1].createNode("do","#805E00");
        m.m[0].m[0].m[2].m[0].m[1].createNode("create","#CC9600");
        m.m[0].m[0].m[2].m[0].createNode("decided","#7F3300");
        m.m[0].m[0].m[2].m[0].m[2].createNode("to.join","#CC5200");
        m.m[0].m[0].m[2].m[0].m[2].createNode("to.fight","#CC9600");

        m.m[0].m[0].m[2].createNode("detest","#CC5200");
        m.m[0].m[0].m[2].createNode("love","#805E00");

        m.m[0].createNode("your","#CC5200");
        m.m[0].m[1].createNode("brain","#7F3300");
        m.m[0].m[1].m[0].createNode("after","#CC9600");
        m.m[0].m[1].m[0].createNode("on","#805E00");

        m.m[0].m[1].createNode("home","#805E00","http://www.dhteumeuleu.com");

        m.m[0].createNode("a","#7F3300");
        m.m[0].m[2].createNode("complex","#CC9600");
        m.m[0].m[2].m[0].createNode("case","#7F3300");
        m.m[0].m[2].m[0].m[0].createNode("with","#CC5200");
        m.m[0].m[2].m[0].m[0].createNode("where","#805E00");

        m.m[0].m[2].createNode("cool","#CC5200");
        m.m[0].m[2].m[1].createNode("idea!","#805E00");
        m.m[0].m[2].m[1].createNode("DHTML","#CC9600");

        m.m[0].m[2].createNode("cry ","#805E00");
        m.m[0].m[2].m[2].createNode("for ","#CC5200");
        m.m[0].m[2].m[2].createNode("and","#7F3300");

        m.createNode("will","#8456BF");
        m.m[1].createNode("shut","#4E3372");
        m.m[1].m[0].createNode("down ","#BFBFBF");
        m.m[1].m[0].m[0].createNode("the","#737373");
        m.m[1].m[0].m[0].createNode("your ","#4E3372");
        m.m[1].m[0].m[0].createNode("any","#8456BF");

        m.m[1].m[0].createNode("the ","#737373");
        m.m[1].m[0].m[1].createNode("Firefox","#4E3372");
        m.m[1].m[0].m[1].createNode("gate","#BFBFBF");
        m.m[1].m[0].m[1].createNode("program","#8456BF");

        m.m[1].createNode("make","#737373");
        m.m[1].m[1].createNode("you","#BFBFBF");
        m.m[1].m[1].m[0].createNode("think","#4E3372");
        m.m[1].m[1].m[0].m[0].createNode("in","#8456BF");
        m.m[1].m[1].m[0].m[0].createNode("that","#BFBFBF");
        m.m[1].m[1].m[0].m[0].createNode("before","#BFBFBF");
        m.m[1].m[1].m[0].m[0].createNode("twice","#737373");
        m.m[1].m[1].m[0].m[0].m[3].createNode("about","#8456BF");
        m.m[1].m[1].m[0].m[0].m[3].createNode("next","#4E3372");
        m.m[1].m[1].m[0].m[0].m[3].createNode("before","#4E3372");

        m.m[1].m[1].m[0].createNode("cry","#8456BF");
        m.m[1].m[1].m[0].createNode("feel","#737373");

        m.m[1].m[1].createNode("everyone","#4E3372");
        m.m[1].m[1].m[1].createNode("smile","#8456BF");
        m.m[1].m[1].m[1].createNode("think.of","#BFBFBF");

        m.m[1].createNode("blow","#BFBFBF");
        m.m[1].m[2].createNode("your","#737373");
        m.m[1].m[2].m[0].createNode("mind","#8456BF");

        m.m[1].m[2].createNode("you","#8456BF");
        m.m[1].m[2].m[1].createNode("down","#BFBFBF");
        m.m[1].m[2].m[1].createNode("away","#737373");

        m.createNode("was ","#859E68");
        m.m[2].createNode("not","#524C36");
        m.m[2].m[0].createNode("the ","#455236");
        m.m[2].m[0].m[0].createNode("apology","#859E68");
        m.m[2].m[0].m[0].createNode("first","#524C36");
        m.m[2].m[0].m[0].createNode("correct","#9E9368");

        m.m[2].m[0].createNode("an","#859E68");
        m.m[2].m[0].m[1].createNode("intelligent","#524C36");
        m.m[2].m[0].m[1].createNode("error","#9E9368");

        m.m[2].m[0].createNode("something","#9E9368");
        m.m[2].m[0].m[2].createNode("for","#524C36");
        m.m[2].m[0].m[2].m[0].createNode("which","#455236");
        m.m[2].m[0].m[2].m[0].m[0].createNode("she","#859E68");
        m.m[2].m[0].m[2].m[0].m[0].createNode("I","#524C36");

        m.m[2].m[0].m[2].m[0].createNode("her","#859E68");
        m.m[2].m[0].m[2].m[0].createNode("me","#9E9368");

        m.m[2].m[0].m[2].createNode("that","#859E68");
        m.m[2].m[0].m[2].m[1].createNode("had ","#455236");
        m.m[2].m[0].m[2].m[1].createNode("could","#524C36");

        m.m[2].m[0].m[2].createNode("I ","#455236");
        m.m[2].m[0].m[2].m[2].createNode("could ","#859E68");
        m.m[2].m[0].m[2].m[2].m[0].createNode("really","#455236");
        m.m[2].m[0].m[2].m[2].createNode("was","#9E9368");
        m.m[2].m[0].m[2].m[2].m[0].createNode("worried","#9E9368");
        m.m[2].m[0].m[2].m[2].createNode("liked","#524C36");

        m.m[2].createNode("going","#455236");
        m.m[2].m[1].createNode("to","#859E68");
        m.m[2].m[1].m[0].createNode("happen","#455236");
        m.m[2].m[1].m[0].createNode("take","#524C36");
        m.m[2].m[1].m[0].m[1].createNode("more","#9E9368");
        m.m[2].m[1].m[0].m[1].createNode("some","#455236");
        m.m[2].m[1].m[0].m[1].createNode("longer","#859E68");

        m.m[2].m[1].createNode("so","#9E9368");
        m.m[2].m[1].m[1].createNode("much","#524C36");
        m.m[2].m[1].m[1].createNode("well","#455236");*/

        // =====
        resize();
        m.spa.onclick();
}
