// JavaScript Document
var jsarray;
var jsarrayfotos;
var album;
var ifoto;
var indexfoto;
var tfotos;
var maxindex;
var carregant;
var timerID = 0;
var diapo=0;
var temps=2000;
carregant=new Image();
carregant.src="../js/imbecil.gif";

function novaArray(noualbum, fotost){
 jsarray = new Array(); 
 jsarrayfotos = new Array();
 album=noualbum;
 ifoto=1;
 indexfoto=0;
 maxindex=4;
 tfotos=fotost;
 document.getElementById('titol').innerHTML= ".. / "+album;
 document.getElementById('foto').src=carregant.src;
}
 
function rebArray( i, fotoi ) {	
 jsarray[i] = fotoi; 
 if (i < 5) {
   jsarrayfotos[i] = new Image();
   jsarrayfotos[i].src= "fotos/edicions/" + encodeURI(album) + "/" + encodeURI(fotoi);
		  //alert(jsarrayfotos[i].name);
 }
} 


function fotoseguent(){
if (indexfoto<tfotos){
 indexfoto += 1;
 ifoto += 1;
 mostrafoto();
 if (indexfoto>=2){
	 seguent= indexfoto + 1;
	 if (seguent > maxindex) {
         maxindex = seguent;
		 jsarrayfotos[seguent] = new Image();
		 jsarrayfotos[seguent].src= "fotos/edicions/" + encodeURI(album) + "/" + encodeURI(jsarray[seguent]);
	 }
   }
 }
}
 
function fotoanterior(){
if (indexfoto>0){
 indexfoto -= 1;
 ifoto -= 1;
	mostrafoto(); 
	}
}

function mostrafoto(){
switch (indexfoto){
 case 0:
 if (tfotos>1){
   document.getElementById('comptador').innerHTML= "&nbsp;&nbsp;&nbsp;" + ifoto + "/"
												 + tfotos
												 + "&nbsp;<a href='#' class='Text14' onclick='fotoseguent()'>Seg&uuml;ent&nbsp;&gt;&gt;</a>&nbsp;&nbsp;";
 }else{
   document.getElementById('comptador').innerHTML= "&nbsp;&nbsp;&nbsp;" + ifoto + "/"
												 + tfotos + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
 	
 }
   break;												 
 case tfotos-1:
   document.getElementById('comptador').innerHTML="<a href='#' class='Text14' onclick='fotoanterior()'>&lt;&lt;&nbsp;Anterior</a>&nbsp;"
                                                 + ifoto 
												 + "/"
												 + tfotos + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
   break;												 
 default:
   document.getElementById('comptador').innerHTML="<a href='#' class='Text14' onclick='fotoanterior()'>&lt;&lt;&nbsp;Anterior</a>&nbsp;"
                                                 + ifoto 
												 + "/"
												 + tfotos
												 + "&nbsp;<a href='#' class='Text14' onclick='fotoseguent()'>Seg&uuml;ent&nbsp;&gt;&gt;</a>&nbsp;&nbsp;";
   break;												 
 }
 document.getElementById('foto').src=jsarrayfotos[indexfoto].src;
 document.getElementById('titol').innerHTML=".. / " + album + " / " + jsarray[indexfoto];
}

function netjafoto(){
   document.getElementById('comptador').innerHTML= "";
   document.getElementById('foto').src=carregant.src;
   document.getElementById('titol').innerHTML="";
}



function diapos(){
	document.getElementById('index').style.display='none';
    document.getElementById('gtitol').innerHTML= "<a href=\"#\"  class='index' onclick=\"prou()\">Parar</a>";
    document.getElementById('diapos').innerHTML= "&nbsp;";
    if (diapo==0){
	indexfoto = diapo;
    ifoto = diapo+1;
		mostrafoto();
		diapo+=1;
	}
	else{
	fotoseguent();
	diapo=indexfoto;
	}
	if (diapo<tfotos-1) {
        timerID = setTimeout("diapos()", temps);
	}
	else
	{
	diapo=0;
	document.getElementById('gtitol').innerHTML= "Fotos";
	document.getElementById('index').style.display='block';
    document.getElementById('diapos').innerHTML= "<br /><br /><a href=\"#\"  class='index' onclick=\"diapos()\">Dipos</a>";
	clearTimeout(timerID);
	timerID = 0;
       }
	}
	
function prou(){
	clearTimeout(timerID);
    timerID  = 0;
	document.getElementById('gtitol').innerHTML= "Fotos";
	document.getElementById('index').style.display='block';
    document.getElementById('diapos').innerHTML= "<br /><br /><a href=\"#\"  class='index' onclick=\"diapos()\">Segueix</a>";
	}
	
function passa(obj){
	switch (obj.id){
		case "edicio":
           document.getElementById('content').style.display='block';
           document.getElementById('autor').focus();
           clientSideInclude('zvars', 'varssessio.php?edicio='+obj.options[obj.selectedIndex].text);
        break;
		case "autor":
           clientSideInclude('zvars', 'varssessio.php?autor='+obj.value);
		break;
		
	}
}

function pujafotos(j){
	var enviat=false;
	for (i=j;i<=5;i++){
		var form=document.getElementById("formf" + i);
		if (document.getElementById("ffoto" + i).value.length!=0 && !enviat){
			form.submit();
			enviat=true;
		}
	}
}