//Zoom Immagine
/*
###########################################
# variabili globali (CONFIGURABILI) 	  #
###########################################
*/

// La larghezza della div con lo zoom
var larghezzaDiv = 350;
// La larghezza dello schermo
var larghezzaSchermo; 
// Intervallo in millisecondi per l'effetto fade
var intervalloFade = 100
// Trasparenza iniziale della div
var divOpacity = 20
// Step di incremento della trasparenza
var incrementoOpacity = 5
//altezza dello scroll dell'elemento
var scrOfY = 0;


function high(which2) {
	theobject=which2
	highlighting=setInterval("highlightit(theobject)",intervalloFade)
}

function low(which2) {
	clearInterval(highlighting)
	which2.filters.alpha.opacity = divOpacity //deve essere uguale al valore in #immaginePopup del css
}

function highlightit(cur2) {
		if (cur2.filters.alpha.opacity<100)
			cur2.filters.alpha.opacity+=incrementoOpacity
		else if (window.highlighting)
		clearInterval(highlighting)
}

function impostaPosizione(){
	if (window.innerWidth){ 
		larghezzaSchermo = window.innerWidth; 
	} 
	if (document.body.clientWidth){ 
		larghezzaSchermo = document.body.clientWidth; 
	}
	if	(document.all)//IE
	{
		document.all.divImmaginePopup.style.left =  (larghezzaSchermo-larghezzaDiv)/2 + 'px';	
		divImmaginePopup.style.top = getScrollXY() + 70 + 'px';
		
	}
	else if (document.getElementById)//NS
	{
		temp = document.getElementById('divImmaginePopup');
		temp.style.left =  (larghezzaSchermo-larghezzaDiv)/2 + 'px';
		temp.style.top = getScrollXY() + 70 + 'px';
	}
}

function mostraImmagine(immagine) {
	if	(document.all)//IE
	{
		document.all.immaginePopup.src = '../img_zoom/' + immagine;
		document.all.divImmaginePopup.style.visibility = 'visible';
	}
	else if (document.getElementById)//NS
	{
		temp1 = document.getElementById('immaginePopup');
		temp1.src = '../img_zoom/' + immagine;
		temp1 = "";
		
		temp2 = document.getElementById('divImmaginePopup');
		temp2.style.visibility = 'visible';
		temp2 = "";
	}
}

function openPopup(immagine){
	try
	{
		high(immaginePopup);
		chiudiPopup();
	}
	catch(er){}
	
	impostaPosizione();
	mostraImmagine(immagine);
		
	try
	{
		high(immaginePopup);
	}
	catch(er){}
}

function chiudiPopup(){
	if	(document.all)//IE
	{
		try
		{
			low(immaginePopup);
		}
		catch(er){}
		
		document.all.divImmaginePopup.style.visibility = 'hidden';
	}
	else if (document.getElementById)//NS
	{
		temp = document.getElementById('divImmaginePopup');
		temp.style.visibility = 'hidden';
		temp = "";
	}
}

function getScrollXY() {
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}


//
window.onresize = function() {
	impostaPosizione();
};
