var isNav4, isNav6, isIE
var coll = "";
var styleObj = "";
var preloadFlag = false;

// browser detection
if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) <= 4) {
	if (thePage == 'index.html') {
		location.href = 'pag/redirect.htm';
	} else {
		location.href = '../redirect.htm'
	}
} else {
	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) > 4) {
		isNav6 = true;
		styleObj = ".style";
	} else { 
		isIE = true;
		coll = "all.";
		styleObj = ".style";
	}
}	

// bugfix for Netscape 4
if (isNav4) {
	window.captureEvents(Event.RESIZE);
}
window.onresize = handleResize;

function handleResize() {
	if (isNav4) {
		location.reload();
		return false;
	}
}

// returns valid object reference
function getObject(obj) {
	var theObj;
	if (isNav4) {
		theObj = eval("document." + obj);
	} else {
		if (isNav6) {
			theObj = eval("document.getElementById(" + "\"" + obj + "\"" + ")" + styleObj);
		} else {
			theObj = eval("document." + coll + obj + styleObj);
		}
	}
	return theObj;
}

// Utility function makes layer visible
function layerOn(obj) {
	var theObj = getObject(obj);
	theObj.visibility = "visible";
	window.status="";
}

// Utility function makes layer invisible
function layerOff(obj) {
	var theObj = getObject(obj);
	theObj.visibility = "hidden";
	window.status="";
}

// preload images for buttons
function preLoadButtons(daPage) {
	if (daPage == 'index') {
		var daPathPrefix = 'img/'
	} else {
		var daPathPrefix = '../img/'
	}
	if (daPage == 'port' || daPage == 'clie') {
		var prefix = 'p_';
	} else {
		if (daPage == 'meto') {
			var prefix = 'm_';
		} else {
			var prefix = "";
		}
	}
	imag = new Array();
	imag[0] = prefix + "portfolio_off.gif";
	imag[1] = prefix + "portfolio_on.gif";
	imag[2] = prefix + "clienti_off.gif";
	imag[3] = prefix + "clienti_on.gif";
	imag[4] = prefix + "contatti_off.gif";
	imag[5] = prefix + "contatti_on.gif";
	imag[6] = prefix + "notizie_off.gif";
	imag[7] = prefix + "notizie_on.gif";
	imag[8] = prefix + "persone_off.gif";
	imag[9] = prefix + "persone_on.gif"
	imag[10] = prefix + "metodo_off.gif";
	imag[11] = prefix + "metodo_on.gif";
	imag[12] = prefix + "home_off.gif";
	imag[13] = prefix + "home_on.gif";
	imag[14] = prefix + "marchio_off.gif";
	imag[15] = prefix + "marchio_on.gif";
	
	if (daPage == 'pers') {
		imag[16] = "antonio_off.gif"
		imag[17] = "antonio_on.gif"
		imag[18] = "matteo_off.gif"
		imag[19] = "matteo_on.gif"
	}
	im = new Array();
	for (var i = 0; i < imag.length; i++) {
		im[i] = new Image();
		im[i].src = daPathPrefix + imag[i];
	}
	preloadFlag = true;
}

// image swap
function swap(num,imgname,message) {
	if (preloadFlag) {
		imgname.src = im[num].src;
		window.status = message;
	}
}

var contattiVisible = false;

function setContatti(trueOrFalse) {
	if (trueOrFalse) {
		layerOn('contatti');
	} else {
		layerOff('contatti');
	}
	contattiVisible = trueOrFalse;
}

function bioOn(obj) {
	var theObj = getObject(obj);
	theObj.visibility = "visible";
	window.status="";
	if (contattiVisible) {
		layerOff('contatti');
	}
}

var duration = 35
var begin;
var finish;
var time = 0;
var setScrollStart = true;
var swapLay;

// funzione ricorsivo che produce l'effetto 'a slittamento'
function slideLayers() {
	slde = setTimeout("slideLayers()", 20)
	if (setScrollStart) {
		if (time < duration) {
			change = finish - begin;
			document.all.scrollbox.style.pixelLeft = scrollPos(time, begin, change, duration);
		} else {
			// termina lo slittamento
			document.all.scrollbox.style.pixelLeft = finish
			layerOn(swapLay);
			clearTimeout(slde);
			time = 0;
			setScrollStart = true;
		}
		time++;
	}
}
// genera il coordinamenti per lo scroll, da non toccare
function scrollPos(t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
}

function credOn(lingo) {
	win=window.open("credit/credit.htm","main","toolbar=0,status=0,directories=0,scrollbars=0,location=0,resizable=0 menubar=0,width=300,height=150")
}
