var elemento = new Array();
var FlashElement;
var TotCapes = 5; // Número total de capes a moure
var Zindex;
var wWdth= 800;// amplada de les finestres 

//var kLeft = -190;  	  //Posició inicial de les finestres 
var kLeft =5;    		//Posició inicial de les finestres 
var ttop = 13;		// Posició top de les finestres 
var vez=0; 
var oInt;

window.onload=inicializa;


function inicializa()
{

	/*
	var bt1 = document.getElementById("izda");
	//bt1.style.color="red";
	bt1.onclick = function(){btClk(-10);};

	var bt2 = document.getElementById("dcha");
	//bt2.style.color="green";
	bt2.onclick = function(){btClk(10);};
	*/
	FlashElement = document.getElementById("FlReforestacio");
	
	// Definicion de las capas y posicion inicial
	for (i=0; i<=TotCapes; i++) {
		
		xx= "z" + i;
		elemento[i]= document.getElementById(xx);
		/*
		elemento[i].style.position= "absolute";
		
		elemento[i].style.width= 0.95*wWdth;
		
		elemento[i].style.top = (ttop) +"px";
		elemento[i].style.left= (kLeft +wWdth*(i-1)) +"px";
	
		elemento[i].style.zIndex= i;
		*/
		
		//elemento[i].onclick=mouseIn;
		elemento[i].onmouseover=mouseIn;
		elemento[i].onmouseout=mouseOut;
		
		
		}
}

function btClk(kk){

//	Mueve hacia la izquierda 
vez = 0; 
oInt = setInterval(function(){Mueve(kk)}, 25);

}



//-----------------------------------------------------------
function Mueve(kk){
	vez=vez +1;
	kLeft = kLeft +kk;
	var topeVeces = Math.abs(wWdth/kk);
	//alert(topeVeces) ; 
	
	if ((kLeft > (-1)*(TotCapes-2)*wWdth) && (kLeft<=5))
		{
			situaCapas();
		}
	else
		{
			alert("Has llegado al màximo");
			clearInterval(oInt);
		}
	

	//if (vez>=20) {clearInterval(oInt);};
	if (vez>=topeVeces) {clearInterval(oInt);};

}



function situaCapas(){

for (i=1; i<=TotCapes; i++) 
	{
		elemento[i].style.left= (kLeft +wWdth*(i-1)) +"px";
	}

}



function mouseIn()
{
	//this.style.backgroundColor="#124";
	
	
	var cp=(this.id);
	var nCapa = cp.substr(1,2);
	
	if (eval(nCapa) > 0 ){
		FlashElement.style.display = "none";  // Oculta l'objecte Flash 
	}
	
	MostrarCapa(nCapa); 
	
}



function mouseOut()
{
	//this.style.backgroundColor="#1A1A22";
	MostrarCapa(0); 
	FlashElement.style.display = "block";// Torna a mostrar el Objecte Flash 
}



function MostrarCapa(LaCapa){


	for (i=1; i<=LaCapa; i++) 
		{
			elemento[i].style.left = (i-1)*100 + "px";
		}
			
		///var xxx= eval(nCapa)+1;
	for (i=(eval(LaCapa)+1); i<=TotCapes; i++) 
		{
			elemento[i].style.left = 400+(i-1)*100 + "px";
		}

	
}
