// Funzioni generiche 

function getElement(_element,f)
{	
	er="Div not found: "+_element+". Check style sheet";
	if(useLayers)
	{
		f=(f)?f:self;
		objVector=f.document.layers;
		if(objVector[_element])
			return objVector[_element];
		for(i=0;i<objVector.length;i++)
			return(getElement(_element,objVector[i]));
	
		//alert(er);
		return false;
	}
		
	if(objDoc.all)
		return objDoc.all[_element]||alert(er);		
	
	return objDoc.getElementById(_element); //||alert(er);
}

function showElement(_obj)
{
	obj = getElement(_obj);
	if(useLayers)
		obj.visibility='show';
	else
		obj.style.visibility='visible';
	
	obj.v=true;
}

function srcElement(_obj,_sSrc)
{
	obj = getElement(_obj);
	
	
	if(useLayers)
		obj.src=_sSrc;
	else
		obj.style.src=_sSrc;
	obj.v=true;
}

function innHTML(_obj,_sSrc)
{
	obj = getElement(_obj);
	
	obj.innerHTML =_sSrc;

}

function hideElement(_obj)
{
	obj = getElement(_obj);
	if(useLayers)
		obj.visibility='hidden';
	else
		obj.style.visibility='hidden';
	
	obj.v=false;
}

function setObjectX(_obj,_x)
{
	obj = getElement(_obj);
	if(useLayers)
		obj.left=_x;
	else 
		if(isOpera)
			obj.style.pixelLeft=_x;
		else 
			obj.style.left=_x+'px';			
}

function setObjectY(_obj,_y)
{
	obj = getElement(_obj);
	if(useLayers)
		obj.top=_y;
	else 
		if(isOpera)
			obj.style.pixelTop=_y;
		else 
			obj.style.top=_y+'px';
}

function setX(_element,_x)
{
	if(useLayers)
		_element.left=_x;
	else 
		if(isOpera)
			_element.style.pixelLeft=_x;
		else 
			_element.style.left=_x+'px';
}
function setY(_element,_y)
{
	if(useLayers)
		_element.top=_y;
	else 
		if(isOpera)
			_element.style.pixelTop=_y;
		else 
			_element.style.top=_y+'px';
}

function getObjectX(_obj)
{
	obj = getElement(_obj);
	var X = "0";
	if(useLayers)
		X = obj.left;
	else 
		if(isOpera)
			X = obj.style.pixelLeft;
		else 
			X = obj.style.left+'px';
			
	if (X="px") X="0";
	if (X="") X="0";
	return X;
}

function getObjectY(_obj)
{
	obj = getElement(_obj);
	var Y = "0";
	if(useLayers)
		Y = obj.top;
	else 
		if(isOpera)
			Y = obj.style.pixelTop;
		else 
			Y = obj.style.top+'px';
	if (Y="px") Y="0";
	if (Y="") Y="0";
	return Y;
}

function setPos(_element,_x,_y)
{
	obj = getElement(_element);
	setX(obj,_x);
	setY(obj,_y);
}

function setColor(_element,_color)
{
	obj = getElement(_element);
	if(useLayers)
		obj.color=_color;
	else 
		obj.style.color=_color;
		
}

function setBgColor(_element,_color)
{
	obj = getElement(_element);
	if(useLayers)
		obj.bgcolor=_color;
	else 
		obj.style.bgcolor=_color;
}


function showDiv(_sDiv)
{		
	objDiv=getElement(_sDiv);
	objDiv.visibility="visible";
}			

// Messaggio sulla Status Bar
var StatusBarMsg="“… la gioia e il benessere sono beni che ogni persona ha il diritto di ricercare e preservare…“";
var iPlace=1;
function scrollStatusBarIn()
{
	window.status=StatusBarMsg.substring(0, iPlace);
	if (iPlace >= StatusBarMsg.length)
	{
		iPlace=1;
		window.setTimeout("scrollStatusBarOut()",300); 
	} else {
		iPlace++;
		window.setTimeout("scrollStatusBarIn()",50); 
   } 
}

function scrollStatusBarOut()
{	
	window.status=StatusBarMsg.substring(iPlace, StatusBarMsg.length);
	if (iPlace >= StatusBarMsg.length)
	{
		iPlace=1;
		window.setTimeout("scrollStatusBarIn()", 100);
	} else {	
		iPlace++;
		window.setTimeout("scrollStatusBarOut()", 100);
	}
}

function setTitle(_sTitle)
{
	top.window.frames["fraTitle"].divTitle.innerHTML = _sTitle;
}

var Message="“… la gioia e il benessere sono beni che ogni persona ha il diritto di ricercare e preservare…“";
var place=1;
function scrollIn()
{
	innHTML("divMsg", Message.substring(0, place));
	if (place >= Message.length)
	{
		place=1;
		window.setTimeout("scrollOut()",300); 
	} else {
		place++;
		window.setTimeout("scrollIn()",60); 
   } 
}

function scrollOut()
{	
	innHTML("divMsg", Message.substring(place, Message.length));
	if (place >= Message.length)
	{
		place=1;
		window.setTimeout("scrollIn()", 100);		
	} else {	
		place++;
		window.setTimeout("scrollOut()", 100);
	}
}

var Message2="PROSSIMAMENTE SARA' DISPONIBILE UNA CASA ANCHE A MARINA DI MASSA.........";
var place2=1;
function scrollIn2()
{
	innHTML("divMsg2", Message2.substring(0, place2));
	if (place2 >= Message2.length)
	{
		place2=1;
		window.setTimeout("scrollOut2()",300); 
	} else {
		place2++;
		window.setTimeout("scrollIn2()",60); 
   } 
}

function scrollOut2()
{	
	innHTML("divMsg2", Message2.substring(place2, Message2.length));
	if (place2 >= Message2.length)
	{
		place2=1;
		window.setTimeout("scrollIn2()", 100);		
	} else {	
		place2++;
		window.setTimeout("scrollOut2()", 100);
	}
}

var iHeightLogo = 286;
var iWidthLogo = 379;

var iHeightSottoT = 90;
var iWidthSottoT = 460;

var iYzero = 0;
var iXzero = 0;
var iXzeroMessaggio = 0;
var iXzeroScroll = 0;
var iXzeroClick = 0;

function calcZeroX(_iWidth)
{
	return (top.document.body.clientWidth - (_iWidth)) / 2;
}
function calcZeroY(_iHeight)
{
	return ((top.document.body.clientHeight - (_iHeight)) / 2);
}

function centerDiv(_sLogo, _sSottoT)
{

	var iLogoY = calcZeroY(iHeightLogo);
	setObjectY(_sLogo, iLogoY);
	setObjectX(_sLogo, calcZeroX(iWidthLogo));

	setObjectY(_sSottoT, iLogoY - 100);
	setObjectX(_sSottoT, calcZeroX(iWidthSottoT));

}

function scambiaDiv(_sLogo, _sLogo2)
{

	var iLogoY = calcZeroY(iHeightLogo);
	var iLogoX = calcZeroX(iWidthLogo);
	
	setObjectY(_sLogo, -1000);
	setObjectX(_sLogo, -1000);

	setObjectY(_sLogo2, iLogoY);
	setObjectX(_sLogo2, iLogoX);
	
}

var iNumScramble = 1;

function scrambleDiv(_sCTI, _sLogo, _sLissone, _sScroll, _sClick)
{
	calcZeroX();
	
	if (iNumScramble == 1)
	{
		setObjectX(_sLogo, iXzero);
		setObjectX(_sCTI, iXzero + iWidthLogo - 1);
		var objDiv = getElement(_sClick);
		objDiv.innerHTML = "Riprova.....";
		setColor(_sClick, "#FF0000")

	}
	if (iNumScramble == 2)
	{
		setObjectX(_sLissone, iXzero);
		setObjectX(_sCTI, iXzero + iWidthLissone);
		setObjectX(_sLogo, iXzero + iWidthCTI + iWidthLissone + 1);
		var objDiv = getElement(_sClick);
		objDiv.innerHTML = "Ce la puoi fare...";
		setColor(_sClick, "#00FFFF")

	}
	if (iNumScramble == 3)
	{
		setObjectX(_sLissone, iXzero);
		setObjectX(_sLogo, iXzero + iWidthLissone + 1);
		setObjectX(_sCTI, iXzero + iWidthLissone + iWidthLogo + 1);
		var objDiv = getElement(_sClick);
		objDiv.innerHTML = "Un'ultima volta...";
		setColor(_sClick, "#40FF40")
		
	}
	if (iNumScramble >= 4) 
	{
		centerDiv(_sCTI, _sLogo, _sLissone, "", "");
		var objDiv = getElement(_sClick);
		objDiv.innerHTML = "opsss...";
		setColor(_sClick, "#FFFFFF")
		setObjectX(_sClick, ((top.document.body.clientWidth - (iWidthScroll)) / 2) );
		centerScroll(_sScroll);
		iNumScramble=4;
	}
	else
	{
		iNumScramble++;
	}
}

function centerScroll(_sScroll)
{
	calcZeroY();
	var iTopMessaggio = iYzero + iHeightImages + 15;
	setObjectY(_sScroll, iTopMessaggio + 70);
	iXzeroScroll = (top.document.body.clientWidth - (iWidthScroll)) / 2;
	setObjectX(_sScroll, iXzeroScroll);
}

var sScrollDiv="";
var iPos = 0;

function scrollDiv(_sDiv)
{
	var objDiv = getElement(_sDiv);
	
	
	var sMsg = objDiv.innerHTML;
	var sShow = "";
	var iLen = sMsg.length;
	
	//alert(sMsg.toUpperCase());
	for(i=0;i<iLen;i++)
	{
		objDiv.innerHTML = sMsg.substring(0, i) + sMsg.substring(i, i + 1).toUpperCase() + sMsg.substring(i + 1);
	}
	
	objDiv.innerHTML = sMsg.toLowerCase();
		
}

function centerLogo(_sLogo1, _sLogo2, iWidthLogo)
{
	x = calcZeroX(iWidthLogo);
	setObjectX(_sLogo1, x);
	setObjectX(_sLogo2, x);

}

function openZoom(_Img,_Tit)
{
	iLeft = (screen.width - parseInt('700')) / 2;
	iTop = (screen.height - parseInt('600')) / 2;
	featured = 'width=700,height=600,left='+iLeft+',top='+iTop+',scrollbars=yes,resizable=yes,status=no,url=no';
	window.open("zoomfoto.asp?img="+_Img+'&tit='+_Tit, "Foto_"+_Tit, featured);
}

function UnCryptMailto(s, shift) {
	var n=0;
	var r="";
	for(var i=0;i<s.length;i++) { 
		n=s.charCodeAt(i); 
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(shift)); 
	}
	return r;
}
function linkTo_UnCryptMailto(s, shift)	{
	location.href=UnCryptMailto(s, shift);
}

