var DOM = (document.getElementById)?	true	:	false;
var IE4 = (document.all && !DOM)?	true	:	false;
var NN4 = (document.layers)?	true	:	false;
var ContainerPagina = false;
var pippo = pluto = false;

/* --- Funzione costruttore dell'oggetto Contenitore che contiene l'intera pagina --- */
function Contenitore(Oggetto){
	this.Obj = (DOM)?	document.getElementById(Oggetto)	:	(IE4)?	document.all[Oggetto]	:	document.layers[Oggetto];
	this.Larghezza = (NN4)?	this.Obj.document.width	:	this.Obj.offsetWidth;
	this.Style = (NN4)?	this.Obj	:	this.Obj.style;
	this.Muovi = Muovi;
	return this;
}
/* --- Metodo per il movimento dell'oggetto Costruttore --- */
function Muovi(x){this.Style.left = x+"px";}

/* --- Funzione che centra i contenuti all'interno della finestra --- */
function Centra(ObjDocument){

	var Opera = (navigator.userAgent.toLowerCase().indexOf("opera")!= -1)?	true	:	false;
	var PagWidth = (document.all&&!Opera)?	document.body.offsetWidth	:	window.innerWidth;
	var X = (parseInt((PagWidth-ObjDocument.Larghezza)/2)>=0)?	parseInt((PagWidth-ObjDocument.Larghezza)/2)	:	0;
	ObjDocument.Muovi(X);
	return false;

}

/* --- Funzioni e variabili per il funzionamento del menu principale --- */
function AzionaMenu(Obj,Action){
	if(Action){
		document.getElementById("Tendina"+Obj).style.display = "block";
		}
	else {
		document.getElementById("Tendina"+Obj).style.display = "none";
	}
}

/* --- Funzioni e variabili per il funzionamento del menu di sinistra --- */
function Attiva(Obj){
	if(document.getElementById("Sottovoce"+Obj).style.display == "block")
		document.getElementById("Sottovoce"+Obj).style.display = "none";
	else
		document.getElementById("Sottovoce"+Obj).style.display = "block";
}

/* --- Funzione lanciata al completo caricamento di ogni pagina --- */
function Init(){
	ContainerPagina = new Contenitore('Container');
	Centra(ContainerPagina);
	if(pippo && pluto){
		MostraDettaglio(pippo, pluto);	
	}
	return false;
}

/* Giochini */
function getAnchorPosition(anchorname){
	var coordinates = new Object();
	var x=0, y=0;
	var use_gebi=false, use_css=false, use_layers=false;
	if(document.getElementById){
		use_gebi=true;
	}
	else if(document.all){
		use_css=true;
	}
	else if(document.layers){
		use_layers=true;
	}
	if(use_gebi && document.all){
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	}
	else if(use_gebi){
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
	}
	else if(use_css){
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	}
	else if(use_layers){
		var found=0;
		for(var i=0;i<document.anchors.length;i++){
			if(document.anchors[i].name == anchorname){
				found = 1;
				break;
			}
		}
		if(found==0){
			coordinates.x=0;coordinates.y=0;
			return coordinates;
		}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
	}
	else{
		coordinates.x=0;
		coordinates.y=0;
		return coordinates;
	}
	coordinates.x=x;coordinates.y=y;
	return coordinates;
}

function AnchorPosition_getPageOffsetLeft(el){
	var ol=el.offsetLeft;
	while((el=el.offsetParent) != null){
		ol += el.offsetLeft;
	}
	return ol;
}

function AnchorPosition_getPageOffsetTop(el){
	var ot = el.offsetTop;
	while((el = el.offsetParent) != null){
		ot += el.offsetTop;
	}
	return ot;
}
/*
function MostraDettaglio(Obj){
	document.getElementById("DettaglioCamera"+Obj).style.display = "block";
}
*/
function MostraDettaglio(name1, name2){
	var c = getAnchorPosition(name1);
	var d = getAnchorPosition(name2);
	//alert("navigator.appName = "+navigator.appName+"\n\nnavigator.userAgent: "+navigator.userAgent+"\n\nnavigator.appVersion: "+navigator.appVersion);
	//alert("X: "+c.x+" Y: "+c.y);
	var Dif = d.y - c.y;
	document.getElementById("Braccino").style.height = Dif;
	document.getElementById("Manina").style.top = c.y+Dif;
	document.getElementById("Braccino").style.top = c.y;
/*
	if (navigator.userAgent.indexOf("Mozilla/5.0") != -1 && navigator.appName == "Microsoft Internet Explorer") {
		document.getElementById("Braccino").style.left = c.x - 4;
		document.getElementById("Manina").style.left = c.x - 4;
	} else if (navigator.userAgent.indexOf("Mozilla/4.0") != -1 && (navigator.userAgent.indexOf("MSIE 5.5") != -1 || navigator.userAgent.indexOf("MSIE 6.0") != -1)) {
		document.getElementById("Braccino").style.left = c.x - 4;
		document.getElementById("Manina").style.left = c.x - 4;
	} else {
*/
		if (pippo && pluto) {
			document.getElementById("Braccino").style.left = c.x;
			document.getElementById("Manina").style.left = c.x;
		}
		else {
			document.getElementById("Braccino").style.left = c.x -2;
			document.getElementById("Manina").style.left = c.x -2;
		}
//	}
	document.getElementById("Manina").style.display = "block";
	document.getElementById("Braccino").style.display = "block";
}

function ResetDettaglio() {
	document.getElementById("Manina").style.display = "none";
	document.getElementById("Braccino").style.display = "none";
}

var MouseX =0;
var MouseY =0;

function CatturaCoor(e){
	if(document.all){
		MouseX = event.clientX;
		MouseY = event.clientY + document.body.scrollTop;
		}
	else{
		MouseX = e.clientX;
		MouseY = e.clientY + document.body.scrollTop;
	}
}

function MostraAlter(testo) {
	//alert("Eccalla: "+document.body.scrollTop);
	d = document.getElementById("Alter");
	d.innerHTML = testo;
	d.style.top = MouseY + 5;
	d.style.left = MouseX + 15;
	d.style.display = "block";
}
if(!document.all) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = CatturaCoor

function NascondiAlter() {
	document.getElementById("Alter").style.display = "none";
}

function popUp(pathfile, altezza) {
	window.open('Include/'+pathfile+'.asp','popup','width=350, height='+altezza+', scrollbars=no, resize=no');
}

window.onload = Init;
window.onresize = Init;


