// check browser type
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var ns7 = (document.getElementById)?true:false;

var pageloaded=false;

function onloadhandler()
{
  pageloaded=true;
}


// *** mousemove handler ***
function movehandler(e) // works on IE6,FF,Moz,Opera7 
{ 
  if (!pageloaded)
    return;

  if (!e) 
    e = window.event; // works on IE, but not NS (we rely on NS passing us the event) 

  if (e) { 
    if (e.pageX || e.pageY) { // this doesn't work on IE6!! (works on FF,Moz,Opera7) 
      lefttmp = e.pageX+4;
      toptmp = e.pageY+9;
    } 
    else if (e.clientX || e.clientY) { // works on IE6,FF,Moz,Opera7 
      lefttmp = e.clientX + document.body.scrollLeft + 7;
      toptmp = e.clientY + document.body.scrollTop + 7;
    } 
    movelayerxy('mousediv',lefttmp,toptmp);
  } 
} 


function movelayerxy(objname,x,y)
{
  if (ns7) {	
    var objp = eval("document.getElementById('" + objname + "').style");
    objp.left = x + 'px';
    objp.top = y + 'px';      
  }
  else if (ie4) {
    var objp=eval("document.all['"+objname+"'].style");
    objp.left = x + 'px';
    objp.top = y + 'px';      
  }
  else if (ns4) {
    var objp=eval("document.layers['"+objname+"']");
    objp.left = x;
    objp.top = y;
  }
}


function rollover(imagename,newimageobj)
{
  if (ns7)
    var oldimageobj = eval("document.getElementById('" + imagename + "')");
  else
    var oldimageobj=eval("document."+imagename);
  var img=eval(newimageobj);
  oldimageobj.src=img.src;
}















// ritorna la proprietà di un layer
// @objname id del layer
// @propstr proprietà da analizzare
// @return il valore della proprietà richiesta
function getlayerproperty(objname,propstr)
{
	if (ie4)
	{
		var objp=eval("document.all['"+objname+"']");
		if (propstr == 'width') return objp.scrollWidth;
		else if (propstr == 'height') return objp.scrollHeight;
		else if (propstr == 'left') return objp.style.pixelLeft;
		else if (propstr == 'top') return objp.style.pixelTop;
		else if (propstr == 'visibility') return (objp.style.visibility=="visible");
		else if (propstr == 'HTML') return objp.innerHTML;
		else if (propstr == 'backgroundcolor') objp.style.backgroundColor;
		else if (propstr == 'clip') return objp.style.clip;
		else if (propstr == 'clipleft') 
		{
			var clipv = objp.style.clip.split("rect(")[1].split(")")[0].split("px");
			return parseInt(clipv[3]);
		}
		else if (propstr == 'cliptop') 
		{
			var clipv = objp.style.clip.split("rect(")[1].split(")")[0].split("px");
			return parseInt(clipv[0]);
		}
		else if (propstr == 'clipbottom') 
		{
			var clipv = objp.style.clip.split("rect(")[1].split(")")[0].split("px");
			return parseInt(clipv[2]);
		}
		else if (propstr == 'clipright') 
		{
			var clipv = objp.style.clip.split("rect(")[1].split(")")[0].split("px");
			return parseInt(clipv[1]);
		}
	}	
	else
	{
		var objp=eval("document.layers['"+objname+"']");
		if (propstr == 'width') return objp.document.width;
		else if (propstr == 'height') return objp.document.height;
		else if (propstr == 'left') return objp.left;
		else if (propstr == 'top') return objp.top;
		else if (propstr == 'visibility') return (objp.visibility=="show");
		else if (propstr == 'backgroundcolor') return objp.bgColor;
		else if (propstr == 'clipleft') return objp.clip.left;
		else if (propstr == 'cliptop') return objp.clip.top;
		else if (propstr == 'clipbottom') return objp.clip.bottom;
		else if (propstr == 'clipright') return objp.clip.right;
	}	
}




// modifica la proprietà di un layer
// @objname id del layer
// @propstr proprietà da modificare
// NOTA: nel caso in cui propstr='visibility' newvalue=valore booleano (=true,false)
function setlayerproperty(objname,propstr,newvalue)
{
	if (ie4)
	{
		var objp=eval("document.all['"+objname+"']");
		if (propstr == 'width') objp.style.width=newvalue;
		else if (propstr == 'height') objp.style.height=newvalue;
		else if (propstr == 'left') objp.style.left=newvalue+"px";
		else if (propstr == 'top') objp.style.top=newvalue+"px";
		else if (propstr == 'onmousemove') eval("objp.onmousemove="+newvalue);
		else if (propstr == 'onmouseover') eval("objp.onmouseover="+newvalue);
		else if (propstr == 'onmouseout') eval("objp.onmouseout="+newvalue);
		else if (propstr == 'visibility') 
			if (newvalue == true)
				objp.style.visibility="visible";
			else
				objp.style.visibility="hidden";
		else if (propstr == 'HTML') objp.innerHTML=newvalue;
		else if (propstr == 'backgroundcolor') objp.style.backgroundColor=newvalue;
		else if (propstr == 'clip') 
			objp.style.clip=newvalue;
		else if (propstr == 'clipright') 
		{
			var clipv = objp.style.clip.split("rect(")[1].split(")")[0].split("px");
			tt=parseInt(clipv[0]);
			rr=parseInt(clipv[1]);
			bb=parseInt(clipv[2]);
			ll=parseInt(clipv[3]);
			objp.style.clip="rect("+tt+"px "+newvalue+"px "+bb+"px "+ll+"px)";
		}
		else if (propstr == 'clipleft') 
		{
			var clipv = objp.style.clip.split("rect(")[1].split(")")[0].split("px");
			tt=parseInt(clipv[0]);
			rr=parseInt(clipv[1]);
			bb=parseInt(clipv[2]);
			ll=parseInt(clipv[3]);
			objp.style.clip="rect("+tt+"px "+rr+"px "+bb+"px "+newvalue+"px)";
		}
		else if (propstr == 'clipbottom') 
		{
			var clipv = objp.style.clip.split("rect(")[1].split(")")[0].split("px");
			tt=parseInt(clipv[0]);
			rr=parseInt(clipv[1]);
			bb=parseInt(clipv[2]);
			ll=parseInt(clipv[3]);
			objp.style.clip="rect("+tt+"px "+rr+"px "+newvalue+"px "+ll+"px)";
		}
		else if (propstr == 'cliptop') 
		{
			var clipv = objp.style.clip.split("rect(")[1].split(")")[0].split("px");
			tt=parseInt(clipv[0]);
			rr=parseInt(clipv[1]);
			bb=parseInt(clipv[2]);
			ll=parseInt(clipv[3]);
			objp.style.clip="rect("+newvalue+"px "+rr+"px "+bb+"px "+ll+"px)";
		}
		else // aggiunge una nuova proprietà 
			eval("document.all['"+objname+"']."+propstr+"="+newvalue);
	}	
	else
	{
		var objp=eval("document.layers['"+objname+"']");
		if (propstr == 'width') objp.height=newvalue;
		else if (propstr == 'height') objp.width=newvalue;
		else if (propstr == 'left') objp.left=newvalue;
		else if (propstr == 'top') objp.top=newvalue;
		else if (propstr == 'onmousemove') eval("objp.onmousemove="+newvalue);
		else if (propstr == 'onmouseover') eval("objp.onmouseover="+newvalue);
		else if (propstr == 'onmouseout') eval("objp.onmouseout="+newvalue);
		else if (propstr == 'visibility')
			if (newvalue == true)
				objp.visibility="show";
			else
				objp.visibility="hide";
		else if (propstr == 'HTML') 
		{			
			objp.document.open();
			objp.document.write(newvalue);
			objp.document.close();
		}
		else if (propstr == 'backgroundcolor') objp.bgColor=newvalue;
		else if (propstr == 'clipright') 
			objp.clip.right=newvalue;
		else if (propstr == 'clipleft') 
			objp.clip.left=newvalue;
		else if (propstr == 'clipbottom') 
			objp.clip.bottom=newvalue;
		else if (propstr == 'cliptop') 
			objp.clip.top=newvalue;
		else // aggiunge una nuova proprietà 
			eval("document.layers['"+objname+"']."+propstr+"="+newvalue);
	}	
}

var newWin;

function openWin(imgName,w,h)
{
  if (newWin)
    if(!newWin.closed)
      newWin.close();
  newWin=window.open('../ingrandimento.htm?img='+imgName,'newWin','width='+w+',height='+h+',toolbar=no,status=no,menubar=no');
}

