var EnsProjects = null;
var Projects = null;
var Gallery = null;
var GalleryImg = null;
var ArrowR = null;
var ArrowL = null;
var current = 0;

function initPage()
{
	EnsProjects = document.getElementById("EnsPro"); Projects = EnsProjects.getElementsByTagName("div");
	Gallery = document.getElementById("gallery"); GalleryImg = Gallery.getElementsByTagName("IMG");
	ArrowR = document.getElementById("ArrowR"); ArrowL = document.getElementById("ArrowL");
	var nb = null;
	
	for( i = 0; i <  Projects.length; i++ )
	{
		if( Projects[i].className == "Projets" )
		{
			var txt = Projects[i].getElementsByTagName("div");
			var img = Projects[i].getElementsByTagName("img");
			
			if( nb == null && txt.length == 1 )
			{
				nb = i;
				txt[0].style.display = "block";
			}
			else if( txt.length == 1 )
			{
				txt[0].style.display = "none";
			}
			
			for( j = 0; j <  img.length; j++ )
			{
				if( img[j].className == "img_projects" )
				{
					img[j].onclick = changeText;
				}
			}
			
		}
	}
	
	k = 0;
	
	for(  i = 0; i <  GalleryImg.length; i++ )
	{
		if(GalleryImg[i].tagName == "IMG")
		{
			GalleryImg[i].style.display = "none";	
			nb = ( nb != null ) ? nb : i;
		}
	}
	
	GalleryImg[nb].style.display = "inline";
	GalleryImg[nb].style.marginLeft = "auto";
	GalleryImg[nb].style.marginRight = "auto";
	
	ArrowR.onclick = droite;
	ArrowL.onclick = gauche;
}

function changeText()
{
	var parent = this.parentNode;
	
	for( i = 0; i <  Projects.length; i++ )
	{
		if( Projects[i].className == "Projets" )
		{
			var txt = Projects[i].getElementsByTagName("div");

			if( txt.length == 1 && Projects[i] == parent )
			{
				txt[0].style.display = "block";
			}
			else if( txt.length == 1 )
			{
				txt[0].style.display = "none";
			}
		}
	}
}

function droite()
{
	GalleryImg[current].style.display = "none";
	current = ( (current + 1) < GalleryImg.length ) ? current + 1 : 0;
	GalleryImg[current].style.display = "block";
	GalleryImg[current].style.marginLeft = "auto";
	GalleryImg[current].style.marginRight = "auto";
}

function gauche()
{
	GalleryImg[current].style.display = "none";
	current = ( (current - 1) >= 0 ) ? current - 1 : GalleryImg.length-1;
	GalleryImg[current].style.display = "block";
	GalleryImg[current].style.marginLeft = "auto";
	GalleryImg[current].style.marginRight = "auto";
}

window.onload = initPage;
