	var mouseX1;
	var mouseY1;
	
	var mouseX;
	var mouseY;
	
	var PosX0;
	var PosY0;
	var nascondi=false;
	var idUltimo=-1;
	var IdCurrent="";
	
	
	function AggiornaPosMouse1(id,event)
	{
		
		mouseX1=document.body.scrollLeft+event.clientX;
		mouseY1=document.body.scrollTop+event.clientY;
		
		var ob=window.document.getElementById(id);
		if(ob)
		{
			PosX0=parseInt(ob.style.left);
			PosY0=parseInt(ob.style.top);
			
		}
		
	}
	
	function AggiornaPosMouse(event)
	{
		mouseX=document.body.scrollLeft+event.clientX;
		mouseY=document.body.scrollTop+event.clientY;
		
		
		window.status = "X=" +mouseX +" Y=" +mouseY;
		
			
		
	}
	var statoDrag=0;
	
	
	function AttivaDrag(event)
	{
		
		if(statoDrag==0)
			statoDrag=1;
		window.status=statoDrag;
		
		
	}
	
	
	function AttivaDrag2(id,event)
	{
		
		if(statoDrag==1)
		{
			statoDrag=2;
			IdCurrent=id;
			window.status=statoDrag;
			AggiornaPosMouse1(id,event);
		}
		
	}
	
	function DisattivaDrag()
	{
		if(statoDrag==2)
		{
			statoDrag=1;
		}
		else
		{
			statoDrag=0;
		}
		window.status=statoDrag;
	}
	
	function SpostaRelMouse(id,event)
	{
		
		if(statoDrag==2 && IdCurrent!="")
		{
			
			AggiornaPosMouse(event);
			SpostaByIdDi(IdCurrent,mouseX-mouseX1,mouseY-mouseY1);
			AggiornaPosMouse(event);
			statoDrag=2;
		}
	}
	
	//con posizionamento assoluto
	function SpostaById(id,x,y)
	{
		
		var ob=window.document.getElementById(id);
		if(ob)
		{
			ob.style.left=x +"px";
			ob.style.top=y +"px";
		}
	}
	
	var LarghezzaRitaglio=50;
	var step=-2;
	
	
	function SpostaImmagine(id)
	{
		var ob=window.document.getElementById(id);
		
		if(typeof(ob)!="undefined" && ob!=null)
		{
			var xPrima=parseInt(ob.style.left);
			var w=parseInt(ob.style.width);
			var xDopo=xPrima+step;
			if(xDopo <= -(2*w-LarghezzaRitaglio))
			{
				xDopo=LarghezzaRitaglio;
			}
			//alert(ob.style.left);
			ob.style.left=xDopo +"px";
			//alert(ob.style.left);
		}
	}
	
	function SpostaImmagine2(id)
	{
		var ob=window.document.getElementById(id);
		var xPrima=parseInt(ob.style.left);
		var w=parseInt(ob.style.width);
		var xDopo=xPrima+step;
		if(xDopo < -w)
		{
			xDopo=LarghezzaRitaglio;
		}
		//alert(ob.style.left);
		ob.style.left=xDopo +"px";
		//alert(ob.style.left);
	}
	
	
	
	function SpostaByIdDi(id,dx,dy)
	{
		
		var ob=window.document.getElementById(id);
		
		if(ob)
		{
			//ob.style.left=(parseInt(ob.style.left)+dx) +"px";
			//ob.style.top=(parseInt(ob.style.top)+dy) +"px";
			
			if(event.clientX+document.body.scrollLeft< PosX0+dx+1)
			{
				//event.clientX=PosX0+dx+1-document.body.scrollLeft;
				PosX0=event.clientX+document.body.scrollLeft -dx-1;
			}		
			
			ob.style.left=(PosX0+dx) +"px";
			ob.style.top=(PosY0+dy) +"px";
			
			
		}
	}
	
	function Visualizza(id,event)
	{
		
		if(idUltimo!=-1)
			Nascondi(idUltimo,event);
		
		AggiornaPosMouse(event);
		
		var ob=window.document.getElementById(id);
		//var ob2=window.document.getElementById(id +"_BIS");
		
		
		//alert(parseInt(ob.style.width));
		ob.style.left=(mouseX-parseInt(ob.style.width)-20) +"px";
		//ob.style.top=(mouseY+50) +"px";
		
		ob.style.visibility="";
		ob.style.top=mouseY +"px";
		
		idUltimo=id;
		
		var TopW=parseInt(ob.style.top) +parseInt(ob.style.height);
		
		
		var h=document.body.clientHeight -parseInt(ob.style.height)-parseInt(ob.style.top);
		
		
		//window.scrollTo(0,parseInt(ob.style.top));
		if(document.body.clientHeight<parseInt(ob.style.height)-100)
		{
			//document.body.clientHeight=parseInt(ob.style.height);
				
		}
		
		
		
	}
	
	function Visualizza00(id,event)
	{
		
		if(idUltimo!=-1)
			Nascondi(idUltimo,event);
		
		AggiornaPosMouse(event);
		
		var ob=window.document.getElementById(id);
		//var ob2=window.document.getElementById(id +"_BIS");
		
		
		//alert(parseInt(ob.style.width));
		ob.style.left=(mouseX-parseInt(ob.style.width)-20) +"px";
		//ob.style.top=(mouseY+50) +"px";
		
		ob.style.visibility="";
		ob.style.top=mouseY +"px";
		
		idUltimo=id;
		
		var TopW=parseInt(ob.style.top) +parseInt(ob.style.height);
		
		
		var h=document.body.clientHeight -parseInt(ob.style.height)-parseInt(ob.style.top);
		
		
		//window.scrollTo(0,parseInt(ob.style.top));
		if(document.body.clientHeight<parseInt(ob.style.height)-100)
		{
			document.body.clientHeight=parseInt(ob.style.height);
				
		}
		
		//ob2.innerHTML=parseInt(ob.style.height)-10+"-" +document.body.clientHeight;	
		
	}
	function Nascondi(id,event)
	{
		
		
			var ob=window.document.getElementById(id);
			ob.style.visibility="hidden";
			nascondi=false;
			
			

		
		
	}
	
	function VisualizzaAttac(id,event)
	{
		
		if(idUltimo!=-1)
			Nascondi(idUltimo,event);
		
		AggiornaPosMouse(event);
		
		var ob=window.document.getElementById(id);
		
		ob.style.left=(mouseX -parseInt(ob.style.width)+3) +"px";
		
		
		
		ob.style.top=(parseInt(mouseY)-3) +"px";
		ob.style.visibility="";
		
		idUltimo=id;
		
		var TopW=parseInt(ob.style.top) +parseInt(ob.style.height);
		
		
		var h=document.body.clientHeight -parseInt(ob.style.height)-parseInt(ob.style.top);
		
		
		//window.scrollTo(0,parseInt(ob.style.top));
		
		if(document.body.clientHeight<parseInt(ob.style.height)-100)
		{
			document.body.clientHeight=parseInt(ob.style.height);
				
		}
		
			
		
	}
	
	//sull'over dell'oggetto non occorre muoverlo quando è statico
	
	function VisualizzaStatic(id,event)
	{
		
		if(idUltimo!=-1)
			Nascondi(idUltimo,event);
		
		AggiornaPosMouse(event);
		
		var ob=window.document.getElementById(id);
		
		
		ob.style.visibility="";
		
		
		
		idUltimo=id;
		
		var TopW=parseInt(ob.style.top) +parseInt(ob.style.height);
		
		
		var h=document.body.clientHeight -parseInt(ob.style.height)-parseInt(ob.style.top);
		
		
		
		//window.scrollTo(0,parseInt(ob.style.top));
		
		
		if(document.body.clientHeight<parseInt(ob.style.height)-100)
		{
			//document.body.clientHeight=parseInt(ob.style.height);
				
		}
		
		
		
	}
