var mostra = new Object()

function show(mylayer)
{
  if (document.layers)
  {
		 eval("document.layers" + "['" + mylayer + "'].visibility='visible'")
   }
  else
	if (document.all)
  {
		 eval("document.all" + "['" + mylayer + "'].style.visibility='visible'")
	}
	else
	if(document.getElementById(mylayer))
  {
		 document.getElementById(mylayer).style.visibility="visible";  	 
	}
}

function hide(mylayer)
{
  if (document.layers)
  {
		 eval("document.layers" + "['" + mylayer + "'].visibility='hidden'")
   }
  else
	if (document.all)
  {
		 eval("document.all" + "['" + mylayer + "'].style.visibility='hidden'")
	}
	else
	if(document.getElementById(mylayer))
  {
		 document.getElementById(mylayer).style.visibility="hidden";
	}
}

function show_menu(num)
{
 show("menu"+num);
 for(i=1;i<8;i++)
 {
	 if(i!=num)
	 {
	   //hide("section"+i);
	   hide("menu"+i);
   }
 }
}

function hide_menu(num)
{
 if(num)	
 {
   hide("menu"+num); 
 }
 else
  for(i=1;i<8;i++)
    hide("menu"+i); 

}

function move(str,ytop,xleft)
{
 if(xleft!=0)
  eval(layer +  str + stile + ".left="+xleft) 
 if(ytop!=0)
  eval(layer + str + stile + ".top="+ytop)
}

function init()
{
	if (document.layers)
  {
	  //alert('layers');
	  layer = "document.layers['";
	  stile = "']";
	}
	else 
	if (document.all)
	{
	 //alert('all');
 	 layer = "document.all['";
 	 stile = "'].style";
	}  
	else
	{ 
		//alert('byID');
		layer = "document.getElementById('";
 		stile = "').style";
	}
}

function init_gallery(dir)
{
  var iniziale = 0;
	
	 init()
 
 //get_list(dir)	// da commentare se non si lavora server-side!

 document.images[9].src="./../banners/gallery.gif";

 if(nomi.length==0)  //nessuna immagine
 {
	  //nascondi i livelli non utilizzati 
	  for(j=0;j<=7;j++)
	  {
		   hide("immagine"+j);
	  }
	
	  //via la copertura
	  hide("copertura");
 	}
 else
 {
  	for(i=0;i<=7;i++)
  	{
	   //document.images[i].src="./"+dir+"/"+nomi[i]+" 50.jpg"
	   document.images[i].src="./"+dir+"/"+nomini[i]
	   document.images[i].title=nomi2[i]
	   document.images[i].width=80
	   document.images[i].height=50
   
	   if((i==nomi.length-1)&&(i<7)) //7 immagini o meno
	   {
	    //sposta di 1
	    for(j=i+1;j>0;j--)
	    {
	     document.images[j].src=document.images[j-1].src
	     document.images[j].title=nomi2[j-1]
	     document.images[j].width=80
	     document.images[j].height=50
	    }
	    iniziale=-1
	    
	   
	    if(i<6) //6 immagini o meno
	    {
	     //sposta ancora
	     for(j=i+2;j>1;j--)
	     {
	      document.images[j].src=document.images[j-1].src
	      document.images[j].title=nomi2[j-2]
	      document.images[j].width=80
	      document.images[j].height=50
	     }
	     iniziale=-2
	    }
	    
	    if(i==6)// 7 immagini
	    {
		     // 0 in 8
		     //document.images[8].src="./"+dir+"/"+nomi[0]+" 50.jpg"
		     document.images[8].src="./"+dir+"/"+nomini[0]
		     document.images[8].title=nomi2[0]
		     document.images[8].width=80
		     document.images[8].height=50
	    }
     
	    //riordina
	    for(c=1;c<=8;c++)
	      move("immagine"+c,  250+(c%2)*100, 400+c*50);
	    
	    // nascondi la 0
	    hide("immagine0");
	    // nascondi la 1
	    hide("immagine1");
	    //via la copertura
			hide("copertura");
			
			//nascondi i livelli non utilizzati 
	    for(j=i+3;j<=8;j++)
				hide("immagine"+j);

			return iniziale
	   }//end if meno di 8
   }//end for
 }//end foto>0
 return 0
}

function pose_all_o()
{
 for(j=0;j<=7;j++)
 {
  eval("pos="+layer+"immagine" + j + stile+".left=290+90*"+j)
  if(j==nomi.length-1)
   break
 }
}

function move_all_o(px)
{
 for(i=1;i<7;i++)
 {
  eval(layer + "immagine" + i + stile + ".left=290+90*"+i+"+"+px)
  if(i==nomi.length-1)
   break
 }
 if(px<0) //verso sn
 {
  eval(layer + "immagine0"+stile + ".left=290")
  eval(layer + "immagine7"+stile + ".left=920+"+px)
 }
 else //verso ds
 {
  eval(layer + "immagine0"+stile + ".left=290+"+px)
  eval(layer + "immagine7"+stile + ".left=920")
 }
 if(px==-41)
 {
  pose_all_o(0)
 }
 if(px==91)
 {
  pose_all_o(0)
 }
}

function pos_in_0(des)
{
 var prox
 if(des==0)
 {
  prox=in0+1
  if(prox==nomi.length)
   prox=0
 }
 else
 {
  prox=in0-1
  if(prox==-1)
   prox=nomi.length-1
 }
 return prox
}

function change(dir)
{ 
 var a
 for(i=0;i<=7;i++)
 {
  a=i+in0
  if(a>=nomi.length)
  {
   a=a-nomi.length
  }
  else if(a<0)
  {
   a=a+nomi.length
  }
  
   document.images[i].src="./"+dir+"/"+nomini[a]
 	//document.images[i].src="./"+dir+"/"+nomi[a]+" 50.jpg"
//  document.images[i].src="./"+dir+"/"+nomi[a]+".jpg"
  document.images[i].title=nomi2[a]
 }
}

function shift_ph(gal,px)
{
 if(nomi.length>7) //8 o pił immagini
  move_all_o(px)
}

 function carica()
 {
	 document.images[0].src="./"+gallery+"/"+foto[pos]+".jpg";
	 document.images[0].title=foto[pos];
	 scrivi();
	 adatta();
	document.forms[0].tit.value=foto[pos];
	}
 
	function adatta()
	{
 		var w=800;
 		var h=660;
	
	 self.resizeTo(w+200,h+100);w+=110;
	 eval(layer+'c'+stile+".left="+w);
	 eval(layer+'b'+stile+".left="+w);
	 eval(layer+'f'+stile+".left="+w)
	 w-=20;
	 eval(layer+'scritte'+stile+".left="+w)
	 eval(layer+'naturale'+stile+".left="+w)
	 }

 function avanti()
 {
	 pos=(pos+1);
	 if(pos==foto.length)
	 	pos=0;
	 carica();
 }
 
 function indietro()
 {
	 pos=(pos-1);
	 if(pos==-1)
	 {pos=foto.length-1};
	 carica();
	}
 
 function chiudi()
 {
	 window.self.close();
	}
 
 function scrivi()
 {
		alt=0;
		hide("scritte");
		hide("naturale");
		if(scritte[pos].length>0)
			show("scritte");
 		else
 			alt=-1;
 }

 function alter()
 {
 	if(alt==0)
 	{
	 	document.images[0].src="./"+gallery+"/"+scritte[pos]+".jpg";alt++;
	 	hide("scritte");
	 	show("naturale");
	 }
 	else if(alt==1)
 	 {
	 	document.images[0].src="./"+gallery+"/"+foto[pos]+".jpg";
	 	alt--;
	 	hide("naturale");
	 	show("scritte");
	 	} 	
 }


function apri(win,num,gal,en)
{
 var opzioni="scrollbars=yes,status=no,toolbar=no, menu=no, width=1000, height=800,resizable=no,top=0,left=0"

 win=window.open("","mostra_foto",opzioni)

 //old=document.location
 
 win.document.writeln('<html><head><title>'+gal+'</title>')

 win.document.writeln('<link rel="stylesheet" type="text/css" href="./../stili.css">')
 win.document.writeln('<style> img{ border-color: #FFFFFF}')
 win.document.writeln('a:link {color: #FADC1B;}')
 win.document.writeln('a:active {color: #FADC1B;}')
 win.document.writeln('a:hover {color: #FADC1B;}')
 win.document.writeln('.formtext{width: 500px; height: 34px; border: none; font-size: 18pt; text-align: left;}')
 win.document.writeln('</style>')
 
 win.document.writeln('<script language="javascript" src="./../funzioni.js"></script>')
 win.document.writeln('<script>')
 win.document.writeln('var foto=new Array()')
 win.document.writeln('var layer=""')
 win.document.writeln('var stile=""')
 win.document.writeln('var scritte=new Array()')
 win.document.writeln('var gallery="'+gal+'"')
 win.document.writeln("var pos="+(num%nomi.length))
 win.document.writeln("var alt=0")

 for(i=0;i<nomi.length;i++)
 {
 win.document.writeln('foto['+i+']="'+nomi2[i]+'"')
 win.document.writeln('scritte['+i+']="'+scritte[i]+'"')
 }
 
 win.document.writeln('</script>')
 win.document.writeln('</head><body onLoad="init();carica()">')
 
 if(en==0)
 {
 win.document.writeln('<div id="f"><a href="javascript:avanti()">avanti</a></div>')
 win.document.writeln('<div id="b"><a href="javascript:indietro()">indietro</a></div>')
 win.document.writeln('<div id="c"><a href="javascript:chiudi()">chiudi</a></div>')
 }
 else
  {
 win.document.writeln('<div id="f"><a href="javascript:avanti()">next</a></div>')
 win.document.writeln('<div id="b"><a href="javascript:indietro()">previous</a></div>')
 win.document.writeln('<div id="c"><a href="javascript:chiudi()">close</a></div>')
 }

 win.document.write('<div id="scritte"><span class="aslink">')
 if(gal.search("costellazioni")==-1)
 {
	 if(en==0)
	 {
     win.document.write('clicca sulla foto per maggiori info')
   }
   else
   {
     win.document.write('click on image for further info')
   }
 }
 else
 {
	 if(en==0)
     win.document.write('clicca sulla foto per vedere le linee')
   else
     win.document.write('click on image for const. lines')
 }
 win.document.writeln('</span></div>')
 win.document.writeln('<div id="naturale"></div>')
 win.document.writeln('<div id="fotografia"><img border=3 src="./'+gal+'/'+nomi[num]+'.jpg"></div>')
 win.document.writeln('<div id="no-download"><img border=0 height=800 width=1000 src="./copri.gif" usemap=#change></div>')
 win.document.writeln('<div id="fototitolo"><p class="titolino"><span class="giallo"><form>')
 win.document.writeln('<input type="text" name="tit" class="formtext" />')
 win.document.writeln('</form></span></p></div>')   
 win.document.writeln('<map name="change">')
 win.document.writeln('<area border=0 href="javascript:alter()" shape="rect" coords="0,0,900,800">')
 win.document.writeln('<area border=0 href="javascript:avanti()" shape="rect" coords="901,0,1000,50">')
 win.document.writeln('<area border=0 href="javascript:indietro()" shape="rect" coords="901,100,1000,150">')
 win.document.writeln('<area border=0 href="javascript:chiudi()" shape="rect" coords="901,200,1000,250">')
 win.document.writeln('<area border=0 href="javascript:void()"  shape="rect" coords="901,300,1000,800">')
 win.document.writeln('</map>')
 
 win.document.writeln('</body></html>')
 win.document.close()
 //document.location=old
}

function shift_gal(px,gal)
{
 eval(layer+"'gallery"+gal+stile+".left="+px)
}

function pose_gal(num)
{
 init()
}


function ch_subMenu(menuLetter,subMenu)
{ 
 var left=0
 
 window.document.lang_form.lev2.value=subMenu;
 
 for(i=1;i<14;i++)
 {
  hide("Menu"+menuLetter+i)
  hide("Menu"+menuLetter+i+'b')
  hide("Menu"+menuLetter+i+'c')
  //move("content"+menuLetter+i,0,pos_left)
  if(i==3&&menuLetter=='M')break
  if(i==5&&menuLetter=='F')break
 }
 show("Menu"+menuLetter+subMenu)
 show("Menu"+menuLetter+subMenu+'b')
 show("Menu"+menuLetter+subMenu+'c')
 //move("content"+menuLetter+subMenu,0,pos_left+30)
}

function ch_Menu(num)
{
 var menuL='A';
 
 window.document.lang_form.lev1.value = num+1;
 window.document.lang_form.lev2.value = 0;

 if(num==1) menuL='M'
 if(num==2) menuL='F'
 
 for(i=1;i<14;i++)
 {
  hide("content"+'A'+i)
  hide("Menu"+'A'+i)
  hide("Menu"+'A'+i+'b')
  hide("Menu"+'A'+i+'c')
  //move("content"+'A'+i,0,pos_left)
  if(i<6)
  {
   hide("content"+'F'+i)
   hide("Menu"+'F'+i)
   hide("Menu"+'F'+i+'b')
   hide("Menu"+'F'+i+'c')
   //move("content"+'F'+i,0,pos_left)
   if(i<4)
   {
    hide("content"+'M'+i)
    hide("Menu"+'M'+i)
    hide("Menu"+'M'+i+'b')
    hide("Menu"+'M'+i+'c')
   //move("content"+'M'+i,0,pos_left)
   }
  }
 }
 
 for(i=0;i<3;i++)
		move("line"+i,0,280)
 move("line"+num,0,260)
 //window.document.lang_form.submenu.value = 0; 
 
 for(i=1;i<14;i++)
 {
  show("content"+menuL+i)
  //window.document.lang_form.content.value = num+1; 
  if(menuL=='M'&&i==3) break
  if(menuL=='F'&&i==5) break
 }
}


function set_lang(it)
{ 
	window.document.lang_form.action=window.self.location;  

  if(it)
   window.document.lang_form.lang.value="it";
  else
   window.document.lang_form.lang.value="en";
   
  window.document.lang_form.submit();  
}


