// JavaScript Document 
var menu = function () { 
	/* ---- private vars ---- */ 
	var m, scr, menuSpan, textSpan, textPath, W, H, nx, ny; 
	var textZoom = 8; 
	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; 
 
	// ===== resize window ==== 
	var resize = function () { 
		nx = scr.offsetWidth; 
		ny = scr.offsetHeight; 
		W  = Math.round(nx); 
		H  = Math.round(ny); 
		if (H > W) H = W; 
		if (W > H) W = H; 
		var css = textSpan.style; 
		css.width    = Math.round(W)+"px"; 
		css.height   = Math.round(H)+"px"; 
		css.left     = Math.round(0)+"px"; 
		css.top      = Math.round(-H/2)+"px"; 
		css.fontSize = W/24+"px"; 
		css = menuSpan.style; 
		css.width    = Math.round(W)+"px"; 
		css.height   = Math.round(H)+"px"; 
		css.left     = Math.round(-W)+"px"; 
		css.top      = Math.round(-H/2)+"px"; 
		css = textPath.style; 
		css.width    = Math.round(W*2)+"px"; 
		css.height   = Math.round(18)+"px"; 
		css.left     = Math.round(-W)+"px"; 
		css.top      = Math.round(H/2)+"px"; 
		css.fontSize = W / 34 + "px"; 
		animHTML(m, -W * xB, -H * yB, W * 3 * zB, H * 3 * zB); 
		var i = 0, p; 
		while (p = m.m[i++]) 
			animateChildren(p, W * zB, H * zB); 
	} 
 
	// ===== reset this.spa ===== 
	var resetSpa = function (o) { 
		if (o.spa) { 
			o.spa = ""; 
			var i = 0, p; 
			while (p = o.m[i++]) 
				resetSpa(p); 
		} 
	} 
 
	// ===== insert HTML elements ===== 
	var createHTML = function (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; 
		var 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); 
	} 
 
	var animHTML = function (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) + "px"; 
			o.spa.style.height = Math.floor(h) + "px"; 
			// ==== font size 
			var fs = w / textZoom; 
			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) { 
			var i = 0, p; 
			while (p = o.m[i++]) 
				p.oX = x + W; 
			x = -W; 
		} else { 
			var i = 0, p; 
			while (p = o.m[i++]) 
				p.oX = 0; 
		} 
		y += o.oY; 
		if(y < -W) { 
			var i = 0, p; 
			while (p = o.m[i++]) 
				p.oY = y + W; 
			y=-W; 
		} else { 
			var i = 0, p; 
			while (p = o.m[i++]) 
				p.oY = 0; 
		} 
		o.spa.style.left = Math.round(x) + "px"; 
		o.spa.style.top  = Math.round(y) + "px"; 
	} 
 
 
	// ==== recursive call 
	var animateChildren = function (o, w, h) { 
		if (w < W/38 || (-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); 

			var i = 0, p; 
			while (p = o.m[i++]) 
				animateChildren(p, w/3, h/3); 
		} 
	} 
 
	var doZoom = function (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(function() { 
			doZoom(x, y, z); 
		}, 16); 
		// ==== animHTML 
		animHTML(m, -W*xB, -H*yB, W*3*zB, H*3*zB); 
		var i = 0, p; 
		while (p = m.m[i++]) 
			animateChildren(p, W * zB, H * zB); 
	} 
 
	// ===== create menu element ===== 
	var createMenu = function (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 ==== 
	createMenu.prototype.createNode = function(c, b, h) { 
		var newItem = this.m[this.m.length] = 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 ===== 
	createMenu.prototype.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:5px'>" + 
					                     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) / 15; 
				xP = ((z * this.obj.px) - xB) / 15; 
				yP = ((z * this.obj.py) - yB) / 15; 
				doZoom(z * this.obj.px, z * this.obj.py, z); 
				if(this.obj.hlink){ 
					// ==== open hyperlink window 
					window.open(this.obj.hlink, "_blank"); 
				} 
			} 
		} 
		return false; 
	} 
 
	//////////////////////////////////////////////////////////////////////////// 

	var init = function () { 
 
		onresize = resize; 
		scr      = document.getElementById("screen"); 
		menuSpan = document.getElementById("menu"); 
		textSpan = document.getElementById("text"); 
		textPath = document.getElementById("path"); 
 
		// ===== create menu ====== 
		m = new createMenu("LSdomotica","#CC5200",""); 
 
		m.createNode("Servizi","#CC9600"); 
		m.m[0].createNode("Impianti","#805E00"); 
		m.m[0].m[0].createNode("Fotovoltaici","#805E00"); 
		m.m[0].m[0].m[0].createNode("have","#CC9600"); 
		m.m[0].m[0].m[0].createNode("can","#7F3300"); 
		m.m[0].m[0].m[0].m[1].createNode("never","#805E00"); 
		m.m[0].m[0].m[0].m[1].createNode("believe","#CC9600"); 
 
		m.m[0].m[0].createNode("Satellitari","#CC9600"); 
		m.m[0].m[0].m[1].createNode("domotica","#805E00"); 
		m.m[0].m[0].m[1].createNode("enforcement","#CC5200"); 
 
		m.m[0].m[0].createNode("Elettrici ","#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("operiamo","#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("Depurazione acque","#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("Finanziari","#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].createNode("Altri","#805E00"); 
		m.m[0].m[3].createNode("Termoidraulica","#CC9600");
		m.m[0].m[3].createNode("Imbiancatura","#7F3300"); 

		m.m[0].m[3].m[0].createNode("have","#CC9600"); 
		m.m[0].m[3].m[0].createNode("can","#7F3300"); 
		m.m[0].m[3].m[0].m[1].createNode("never","#805E00"); 
		m.m[0].m[3].m[0].m[1].createNode("believe","#CC9600"); 
 
 
 
		m.m[0].m[2].createNode("Incentivi statali","#CC5200"); 
		m.m[0].m[2].m[1].createNode("Certificazione!","#805E00"); 
		m.m[0].m[2].m[1].createNode("Risparmio energetico","#CC9600"); 
 
		m.m[0].m[2].createNode("Pagamenti personalizzati ","#805E00"); 
		m.m[0].m[2].m[2].createNode("for ","#CC5200"); 
		m.m[0].m[2].m[2].createNode("and","#7F3300"); 
 
		m.createNode("Domotica","#8456BF"); 
		m.m[1].createNode("Nautica","#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("Applicata","#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("domestica","#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("Sicurezza","#CC5200"); 
		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("Azienda","#859E68"); 
		m.m[2].createNode("Storia","#524C36"); 
		
		m.m[2].createNode("Dove","#524C36"); 
		m.m[2].m[1].createNode("operiamo","#859E68"); 
		m.m[2].m[1].createNode("Siamo","#9E9368"); 

		m.m[2].createNode("Contatti","#455236"); 
		m.m[2].m[2].createNode("E-mail","#859E68"); 


 
 
        m.createNode("Edilizia","#8456BF"); 
		m.m[3].createNode("Bioedilizia","#4E3372"); 
		m.m[3].m[0].createNode("down ","#BFBFBF"); 
		m.m[3].m[0].m[0].createNode("the","#737373"); 
		m.m[3].m[0].m[0].createNode("your ","#4E3372"); 
		m.m[3].m[0].m[0].createNode("any","#8456BF"); 
		
        m.m[3].createNode("Ristrutturazioni","#737373"); 
		m.m[3].m[1].createNode("Preventivo","#BFBFBF");
		m.m[3].m[1].createNode("Costi","#8456BF");
		m.m[3].m[1].createNode("Locali","#BFBFBF");

		m.m[3].m[1].m[0].createNode("primo","#4E3372");
		m.m[3].m[1].m[1].createNode("secondo","#737373"); 
		m.m[3].m[1].m[2].createNode("terzo","#8456BF"); 

		
		
		m.m[3].m[1].m[0].m[0].createNode("in","#8456BF"); 
		m.m[3].m[1].m[0].m[0].createNode("that","#BFBFBF"); 
		m.m[3].m[1].m[0].m[0].createNode("before","#BFBFBF"); 
		m.m[3].m[1].m[0].m[0].createNode("twice","#737373"); 
		
		m.m[3].m[1].m[0].m[0].m[3].createNode("about","#8456BF"); 
		m.m[3].m[1].m[0].m[0].m[3].createNode("next","#4E3372"); 
		m.m[3].m[1].m[0].m[0].m[3].createNode("before","#4E3372");
 
		// ===== 
		resize(); 
		m.spa.onclick(); 
	} 
	//////////////////////////////////////////////////////////////////////////// 
	return { 
		init : init 
	} 
}(); 
 

