//photo=true;
var indice;
var lincSec;
var ella;

/*function setupFoto(){
	compLinkFoto();
}*/

/*function controlloFoto(){
	indirizzo=new String(window.location);
	present=indirizzo.lastIndexOf('?');
	if(present!='-1'){
		rnd=indirizzo.slice(present+1,indirizzo.length);
	}else{
		rnd=Math.floor(((Math.random()*10)+1)/2);
		if(rnd==0)rnd=1;
	}
}*/

function compLinkFoto(){
	/*lincs=document.getElementById('barra');
	linc=lincs.getElementsByTagName('a');
	for(i=0;i<linc.length;i++){
		linc[i].href+='?'+valo;
	}*/
	secondo=document.getElementById('lista');
	lincSec=secondo.getElementsByTagName('a');
	//creaListaFoto();
	for(i=0;i<lincSec.length;i++){
		/*lincSec[i].href='javascript:void(null);';
		lincSec[i].target='_self';*/
		lincSec[i].onclick=apriFoto;
	}
	document.getElementById('torna').onclick=chiudiFoto;
	/*document.getElementById('prec').onclick=cambiaFoto;
	document.getElementById('succ').onclick=cambiaFoto;*/
}

function apriFoto(){
	a=this.getElementsByTagName('img');
	b=a[0].src.split('/');
	c='/'+b[b.length-5]+'/'+b[b.length-4]+'/'+b[b.length-3]+'/foto/'+b[b.length-1];
	if (document.all&&document.getElementById) {
		cc=new Image();
		cc.src=c;
		cc.onload=function (){
			document.getElementById('grande').src=cc.src;
		}
	}
	document.getElementById('lista').style.display='none';
	document.getElementById('barra').style.display='none';
	document.getElementById('displ').style.display='block';
	//alert(c);
	document.getElementById('grande').src=c;
	//alert(cc.src);
	d=this.name;
	indice=d.slice(4,d.length);
	ella=indice-1;
	cont='';
	if(ella>0)cont+='<a id="prec" href="javascript:void(null);" onclick="cambiaFoto(this.id)">&lt;&lt;&lt; Precedente</a>';
	if(ella>0&&lincSec.length>1&&ella<lincSec.length-1)cont+='&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
	if(ella<lincSec.length-1)cont+='<a id="succ" href="javascript:void(null);" onclick="cambiaFoto(this.id)">Successiva &gt;&gt;&gt;</a>';
	document.getElementById('nav').innerHTML=cont;
}

function chiudiFoto(){
	document.getElementById('displ').style.display='none';
	document.getElementById('lista').style.display='block';
	document.getElementById('barra').style.display='block';
	document.getElementById('grande').src='';
	a=new String(window.location);
	b=a.lastIndexOf('#');
	if(b!='-1'){
		c=a.slice(0,b);
	}else{
		c=window.location;
	}
	if(indice>3){
		indice-=3;
		window.location=c+'#foto'+indice;
	}
	indice=false;
}

function cambiaFoto(dove){
	if(dove=='prec')a=lincSec[ella-1];
	if(dove=='succ')a=lincSec[ella+1];
	ab=a.getElementsByTagName('img');
	b=ab[0].src.split('/');
	c='/'+b[b.length-5]+'/'+b[b.length-4]+'/'+b[b.length-3]+'/foto/'+b[b.length-1];
	if (document.all&&document.getElementById) {
		cc=new Image();
		cc.src=c;
		cc.onload=function (){
			document.getElementById('grande').src=cc.src;
		}
	}
	document.getElementById('grande').src=c;
	d=a.name;
	indice=d.slice(4,d.length);
	ella=indice-1;
	cont='';
	if(ella>0)cont+='<a id="prec" href="javascript:void(null);" onclick="cambiaFoto(this.id)">&lt;&lt;&lt; Precedente</a>';
	if(ella>0&&lincSec.length>1&&ella<lincSec.length-1)cont+='&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
	if(ella<lincSec.length-1)cont+='<a id="succ" href="javascript:void(null);" onclick="cambiaFoto(this.id)">Successiva &gt;&gt;&gt;</a>';
	document.getElementById('nav').innerHTML=cont;
}

function creaListaFoto(){
	stringa='<h3 class="tito">'+titolo+'</h3>';
	for(i=0;i<numeroFoto;i++){
		foto=i+1;
		stringa+='\n\t\t\t<div class="thumb">\n\t\t\t\t';
		stringa+='<div class="top"><a name="foto'+foto+'" href="javascript:void(null);" target="_self"><img src="'+cartellaFoto+'/thumb/'+foto+'.jpg" /></a></div>\n\t\t\t\t';
		stringa+='<div class="bott"></div>\n\t\t\t';
		stringa+='</div>';
	}
	document.getElementById('lista').innerHTML=stringa;
}

