//recuipero centro
var x=20;
var y=20;
function centra(IDpopup) {
			obj = document.getElementById(IDpopup);						
			var browser_A = getWindowHeight();
			var browser_L = window.document.body.clientWidth;
			x=(browser_L-obj.offsetWidth)/2;
			y=((browser_A-obj.offsetHeight)/2);			
}		

function getWindowHeight() {
 var windowHeight = 0;
 if (typeof(window.innerHeight) == 'number') {
  windowHeight = window.innerHeight;
 }
 else {
  if (document.documentElement && document.documentElement.clientHeight) {
   windowHeight = document.documentElement.clientHeight;
  }
  else {
   if (document.body && document.body.clientHeight) {
    windowHeight = document.body.clientHeight;
   }
  }
 }
 return windowHeight;
}
// Browser safe opacity handling function

function setOpacity(IDpopup, value ) {
 document.getElementById(IDpopup).style.opacity = value / 10;
 document.getElementById(IDpopup).style.filter = 'alpha(opacity=' + value * 10 + ')';
 
}

function fadeInMyPopup(IDpopup,inizio,fine) {
	
 for( var i = inizio ; i <= fine ; i++ )
   setTimeout( 'setOpacity("'+IDpopup+'",' + (i / 10) + ')' , 8 * i );
   
}

function fadeOutMyPopup(IDpopup,inizio,limite) {
 for( var i = inizio ; i <= limite ; i++ ) {
  setTimeout('setOpacity("'+IDpopup+'",' + (10 - i / 10) + ')' , 8 * i );
 } 

if (limite==100) setTimeout('closeMyPopup("'+IDpopup+'")', 800 );
	
}

function closeMyPopup(IDpopup) {
 document.getElementById(IDpopup).style.display = "none"
}

function apri_popup(IDpopup) {
		
	
	
	if	(document.getElementById(IDpopup).style.display=="block") {	//chiudi
	//			fadeInMyPopup("esterno",50);
				
				fadeOutMyPopup(IDpopup,0,100);						 
				fadeOutMyPopup("fade",0,60);
				document.getElementById("hideshow").style.visibility="hidden";
	}
	else //apri
	{
	//		fadeOutMyPopup("esterno",50);						
			
			
			
			document.getElementById("hideshow").style.visibility="visible";
			fadeInMyPopup("fade",0,60);
			
			setOpacity(IDpopup, 0 );
			 
			 document.getElementById(IDpopup).style.display = "block";
			 
			 fadeInMyPopup(IDpopup,0,100);
			 
			 centra(IDpopup);
			 
			 placeIt(IDpopup);
			 

			 
	}		 
 
}

function placeIt(IDpopup)
{
	obj = document.getElementById(IDpopup);
	if (document.documentElement)
	{
		theLeft = document.documentElement.scrollLeft;
		theTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		theLeft = document.body.scrollLeft;
		theTop = document.body.scrollTop;
	}
	theLeft += x;
	theTop += y;
	obj.style.left = theLeft + 'px' ;
	obj.style.top = theTop + 'px' ;
		
	setTimeout('placeIt("'+IDpopup+'")', 500 );
}