
var oPopup = null;
var oObjPar = null;
var oImg = null;
var nRad = 0;
var oTmr = null;
var sImg = null;
var sTxt = null;


function OnBlur()
{
	if( oImg  &&  nRad )
	{
		nRad--;
		oImg.filters.item(0).PixelRadius = nRad;
	}
	else
		if( oTmr )
		{
			clearInterval( oTmr );
			oTmr = null;
		}
}

function DoFotoPreview( filename, testo )
{
	if( oPopup )
	{
		ClosePreview();
		return;
	}
	oObjPar = window.event.srcElement;	//	toElement solo con onmouseover onmouseout
	sImg = filename;
	sTxt = testo;
	oPopup = window.createPopup();
	oPopup.document.body.innerHTML = "<IMG name='theImg' src=\"/public/"+filename+"\">";
	oImg = oPopup.document.all.item("theImg");
	oImg.attachEvent( "onload", OnLoad );
	oPopup.show( 1,1,1,1 );
}

function OnLoad()
{
	var nWImg = oImg.width;
	var nHImg = oImg.height;
	oPopup.hide();

	if( nWImg > 450 )
	{
		ratio = nHImg / nWImg;
		nWImg = 450;
		nHImg = nWImg * ratio;
	}
	else if( nHImg > 300 )
	{
		ratio = nWImg / nHImg;
		nHImg = 300;
		nWImg = nHImg * ratio;
	}

//alert("nWImg="+nWImg+" nHImg="+nHImg);
	oPopup = window.createPopup();
	oPopup.document.body.innerHTML = "<DIV ID='theDiv' style='font-family:verdana; font-size:10px; text-align:center; width:"+nWImg+"'>"+sTxt+"</DIV>";
	oPopup.show( 1,1,1,1 );
	var oObjDiv = oPopup.document.all.item("theDiv");
	var nHDiv = oObjDiv.clientHeight;
	oPopup.hide();

	nRad = 10;
	oPopup = window.createPopup();
	oPopup.document.body.innerHTML = "<IMG ID='theImg' style=\"filter:progid:DXImageTransform.Microsoft.blur(PixelRadius="+nRad+",MakeShadow=false,ShadowOpacity=1.00)\" border=0 title=\""+sTxt+"\" src=\"/public/"+sImg+"\" width="+nWImg+" height="+nHImg+">";
	oPopup.document.body.innerHTML += "<DIV style='font-family:verdana; font-size:10px; text-align:center; background-color:#FFFFEC; position:absolute; left:0; top:"+nHImg+"; width:"+nWImg+"; height:"+nHDiv+"' border='0'>"+sTxt+"</DIV>";

	var wP = oObjPar.offsetWidth;
	var hP = oObjPar.offsetHeight;
	oPopup.show( wP,hP/2, nWImg,nHImg+nHDiv, oObjPar );
	oImg = oPopup.document.all.item("theImg");
//	oImg.attachEvent( "onmouseout", CloseFotoPreview );
	oObjPar.attachEvent( "onmouseout", CloseFotoPreview );
	oTmr = setInterval( OnBlur, 10 );
	oImg.setCapture();
	return;
}


function ClosePreview()
{
	if( oTmr )
	{
		clearInterval( oTmr );
		oTmr = null;
	}
	if( oPopup )
	{
		oPopup.hide();
		oPopup = null;
	}
	document.releaseCapture();
	oObjPar = null;
	oImg = null;
}


function CloseFotoPreview()
{
//	var oObj = window.event.srcElement;
//	if( window.event.toElement != oObjPar  &&  window.event.toElement != oImg )
		ClosePreview();
}

