//
// FUNZIONI PER MENU CANGIANTE
//

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// Carica una lista di immagini passate come argomento con il path assoluto
function MM_preloadImages() {
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//===========================================================================================================================================

//
// FUNZIONI PER VISUALIZZARE IMMAGINI
//

hMax = window.screen.height;
wMax = window.screen.width;

// Restituisce lo spazio disponibile: al netto della barra di avvio se è in primo piano  
// var hMax = window.screen.availHeight;
// var wMax = window.screen.availWidth;

function mostraFoto(nomeFoto,didascalia){
   document.write('<A HREF="javascript:mostraMaxi(\'images/'+nomeFoto+'.jpg\',\''+didascalia+'\')"><IMG SRC="images/'+nomeFoto+'.gif" HSPACE=0 VSPACE=0 BORDER=0 ALT="'+didascalia+'" ></A>');
}


//function mostraFoto(nomeFoto,didascalia){
//   foto = new Image;
//   foto.src = 'foto/jpg/'+nomeFoto+'.jpg';
//   QQ=foto.fileSize;  
//   document.write('<A HREF="javascript:mostraMaxi(\'foto/jpg/'+nomeFoto+'.jpg\',\''+didascalia+'\')"><IMG SRC="foto/gif/'+nomeFoto+'.gif" HSPACE=0 VSPACE=0 BORDER=0 ALT="'+didascalia+', size:" ></A>');
//}



function setW(W,H){
   var HEIGHT = H;
   var WIDTH = W;

   if ( H > hMax ){
      HEIGHT = hMax;  
      WIDTH  = W * hMax / H;
   }
   W = WIDTH;
   H = HEIGHT;
   if (W > wMax ){
      WIDTH  = wMax;  
      HEIGHT = H * wMax / W;
   }

//   debug= 'i1.width='+i1.width+' i1.height='+i1.height+' wMax='+wMax+' hMax='+hMax+' W='+W+' H='+H+' WIDTH='+WIDTH+' HEIGHT='+HEIGHT;
//   alert(debug);

   return(Math.floor(WIDTH)); 
}

function setH(W,H){
   var HEIGHT = H;
   var WIDTH = W;

   if ( H > hMax ){
      HEIGHT = hMax;  
      WIDTH  = W * hMax / H;
   }
   W = WIDTH;
   H = HEIGHT;
   if (W > wMax ){
      WIDTH  = wMax;  
      HEIGHT = H * wMax / W;
   }

//   debug= 'i1.width='+i1.width+' i1.height='+i1.height+' wMax='+wMax+' hMax='+hMax+' W='+W+' H='+H+' WIDTH='+WIDTH+' HEIGHT='+HEIGHT;
//   alert(debug);

   return(Math.floor(HEIGHT)); 
}


function setDim(W,H){
   var HEIGHT = H;
   var WIDTH = W;

   if ( H > hMax ){
      HEIGHT = hMax;  
      WIDTH  = W * hMax / H;
   }
   W = WIDTH;
   H = HEIGHT;
   if (W > wMax ){
      WIDTH  = wMax;  
      HEIGHT = H * wMax / W;
   }

//   debug= 'i1.width='+i1.width+' i1.height='+i1.height+' wMax='+wMax+' hMax='+hMax+' W='+W+' H='+H+' WIDTH='+WIDTH+' HEIGHT='+HEIGHT;
//   alert(debug);

   myDim.width  = Math.floor(WIDTH);
   myDim.height = Math.floor(HEIGHT); 

   return(myDim); 
}


function mostraProp(obj,obj_name) {
   var result = " ";
   for (var i in obj){
      result += obj_name + "." + i + " = " + obj[i] + "##";
   }

   return result;
}

function Controlla(img,path,dida){
    if((i1.width==0)||(i1.height==0)||(i1.fileSize<=0)){
    funzione="Controlla('"+img+"','"+path+"','"+dida+"')";
    intervallo=setTimeout(funzione,20);
 }
  else{
     mostraHtml(path,dida)
 }
}

function mostraMaxi(path,dida) {

   i1 = new Image();
   i1.src = path;
   Controlla(i1,path,dida);
 }

function mostraHtml(path,dida) {

//   DD = foto.fileSize;
   DD = i1.fileSize;

   myDim = { width:0, height:0 }
   
   var n  = 0;
   var HH = 0;
   var WW = 0;

//     debug= 'WW='+i1.width+' HH='+i1.height;
//     alert(debug);

setDim(i1.width,i1.height);
      HH = myDim.height;
      WW = myDim.width;

/*
   do {
      setDim(i1.width,i1.height);
      HH = myDim.height;
      WW = myDim.width;
      n++;

//    debug='Image= ' + mostraProp(Image,i1);
//    debug=mostraProp(Image,this);
//    alert(debug);
           
     debug= 'WW='+WW+' HH='+HH+' n='+n;
     alert(debug);
//      aa=window.open('','_blank',"fullscreen");
//        aa.close();
      
       if ( n > 10 ) {
           alert('Uscito per n='+n);
           break;
        }
   } while ( (HH <= 50) && (WW <= 50) );
*/


// Per visualizzazione a schermo intero con didascalia, pulsante chiudi e resize img
//   html = '<HTML>\n<HEAD>\n</HEAD>\n<BODY BGCOLOR="black" SCROLL="NO" LEFTMARGIN="0" MARGINWIDTH="0" TOPMARGIN="0" MARGINHEIGHT="0">\n<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%" height="100%">\n<TR>\n<TD ALIGN="left" VALIGN="top" HEIGHT="10"><FONT COLOR="yellow" FACE="Arial" SIZE="2"><B>'+dida+' ['+path+']</B></TD>\n<TD ALIGN="right" VALIGN="top" HEIGHT="10"><FORM NAME="form1" HEIGHT="10">\n<INPUT TYPE="button" NAME="chiudi_win" VALUE="CHIUDI" onclick="window.close()" STYLE="font-size: 10 px; font-family: Arial; font-style: bold"></FORM></TD>\n</TR>\n<CENTER>\n<TR>\n<TD ALIGN="center" VALIGN="top" COLSPAN="2" HEIGHT="758"><IMG SRC="'+path+'" BORDER="0" NAME="imageTest" HEIGHT="'+HH+'" WIDTH="'+WW+'"></TD>\n</TR>\n</CENTER>\n</TABLE>\n</BODY>\n</HTML>';


   html1 = '<HTML>\n<HEAD>\n</HEAD>\n<BODY BGCOLOR="black" SCROLL="NO" LEFTMARGIN="0" MARGINWIDTH="0" TOPMARGIN="0" MARGINHEIGHT="0">\n';
   html2 = '<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%" height="100%">\n';
   html3 = '<TR>\n<TD ALIGN="left" VALIGN="top" HEIGHT="10"><FONT COLOR="yellow" FACE="Arial" SIZE="2"><B>'+dida+' ['+path+','+DD+']</B></TD>\n';
   html4 = '<TD ALIGN="right" VALIGN="top" HEIGHT="10"><FORM NAME="form1" HEIGHT="10">\n';
   html5 = '<INPUT TYPE="button" NAME="chiudi_win" VALUE="CHIUDI" onclick="window.close()" STYLE="font-size: 10 px; font-family: Arial; font-style: bold"></FORM></TD>\n</TR>\n';
   html6 = '<CENTER>\n<TR>\n<TD ALIGN="center" VALIGN="top" COLSPAN="2" HEIGHT="'+hMax+'-10"><IMG SRC="'+path+'" BORDER="0" NAME="imageTest" HEIGHT="'+HH+'" WIDTH="'+WW+'"></TD>\n</TR>\n</CENTER>\n';
   html7 = '</TABLE>\n</BODY>\n</HTML>';
   html  = html1+html2+html3+html4+html5+html6+html7;

//  html = '<HTML>\n<HEAD>\n<SCRIPT language="JavaScript" src="funzioni.js" </SCRIPT>\n<SCRIPT i1=new Image; i1.src='+path+'></SCRIPT>\n</HEAD>\n<BODY BGCOLOR="black" SCROLL="NO" LEFTMARGIN="0" MARGINWIDTH="0" TOPMARGIN="0" MARGINHEIGHT="0">\n<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%" height="100%">\n<TR>\n<TD ALIGN="left" VALIGN="top" HEIGHT="10"><FONT COLOR="yellow" FACE="Arial" SIZE="2"><B>'+dida+' ['+path+']</B></TD>\n<TD ALIGN="right" VALIGN="top" HEIGHT="10"><FORM NAME="form1" HEIGHT="10">\n<INPUT TYPE="button" NAME="chiudi_win" VALUE="CHIUDI" onclick="window.close()" STYLE="font-size: 10 px; font-family: Arial; font-style: bold"></FORM></TD>\n</TR>\n<CENTER>\n<TR>\n<TD ALIGN="center" VALIGN="top" COLSPAN="2" HEIGHT="758"><IMG SRC="'+path+'" BORDER="0" NAME="imageTest" onload="window.images.resizeto(setH(document.imageTest.width,document.imageTest.height),setW(document.imageTest.width,document.imageTest.height))"></TD>\n</TR>\n</CENTER>\n</TABLE>\n</BODY>\n</HTML>';

   


// Per visualizzazione a schermo intero con didascalia pulsante X e resize img
// html = '<HTML>\n<HEAD>\n</HEAD>\n<BODY BGCOLOR="black" SCROLL=NO LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0>\n<TABLE BORDER="0" cellpadding="0" cellspacing="0" WIDTH="100%" height="100%">\n<TR>\n<TD ALIGN="left" valign="top" height="16"><FONT COLOR="yellow" FACE="Arial" SIZE="2"><B>'+dida+' ['+path+']</B></TD>\n<TD ALIGN="right" valign="top" height="16"><FORM NAME="form1"> <FONT face="Arial" size="1"><INPUT TYPE="button" NAME="chiudi_win" VALUE="CHIUDI" onclick="window.close()" STYLE="font-size: 10 px; font-family: Arial; font-style: bold"></FORM></TD>\n</TR>\n<CENTER>\n<TR>\n<TD ALIGN="center" valign="top" COLSPAN="2" height="750"><IMG SRC='+i1.src+' BORDER="0" NAME="imageTest" HEIGHT="'+HH+'" WIDTH="'+WW+'"></TD>\n</TR>\n</CENTER>\n</TABLE>\n</BODY>\n</HTML>';

// Per visualizzazione in finestra
// html = '<HTML>\n<HEAD>\n<TITLE>'+path+': '+dida+'</TITLE>\n</HEAD>\n<BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0>\n<CENTER><IMG SRC="'+path+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+14,document.imageTest.height+32)"></CENTER>\n</BODY>\n</HTML>';

// Per visualizzazione a schermo intero senza didascalia
// html = '<HTML>\n<HEAD>\n</HEAD>\n<BODY SCROLL=NO LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0>\n<CENTER><IMG SRC="'+path+'" BORDER=0 NAME=imageTest onKeyPress="return document.imageTest.close()"></CENTER>\n</BODY>\n</HTML>';

// Visualizzazione a finestra
// popupImage = window.open('','_blank','status=0,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');

// Visualizzazione a schermo intero
   popupImage = window.open('','_blank',"fullscreen");


 	
// Per debug	
// alert(html);

   popupImage.document.open();
   popupImage.document.write(html);
//debug='Image= ' + mostraProp(foto,this);
//alert(debug);
   popupImage.document.form1.chiudi_win.focus();
   popupImage.document.close();

//debug='Image= ' + mostraProp(popupImage.document.imageTest,this);
//alert(debug);


   delete i1;
}


