var Galerie =
{
	section : 1,
	
	init : function(id)
	{
		var cible = document.getElementById(id);
		this.id = id;
		this.cible = cible;
		this.autoriser = true;
		
		if(this.cible != null)
		{
			var ul = cible.getElementsByTagName('ul');
			
			if(ul != null)
			{
				var total = ul.length;
		
				for(i = 0; i < total; i++)
				{
					var pos = ul[i].offsetWidth * i;
					ul[i].style.marginLeft = pos + 'px';	
				}
				
				if(total < 10)
				{
					var suivant = document.getElementById('suivant');
					suivant.style.visibility='hidden';
					
					var precedent = document.getElementById('precedent');
					precedent.style.display='none';
				
				
				}
				
			}
		}
		
		this.activerSection(this.section);
	},//init
	
	
	suivant : function()
	{
		if(this.autoriser)
		{
			var ul = this.cible.getElementsByTagName('ul');
			var total = ul.length;
			var cible = ul[total-1];
			this.desactiverSection(this.section);
			this.autoriser = false;
			if(cible.offsetLeft == 0)
			{
				var pos = ul[0].offsetWidth * (total-1);
					
				$('.vue').animate({"left": "+="+pos+"px"}, "slow", function() {
	  Galerie.autoriser = true;
	  });
				var precedent = document.getElementById('precedent');
				var img = precedent.getElementsByTagName('img')[0];
				img.src = '/assets/images/btn/precedent2.png';
				img.style.left = "10px"; 
				this.section = 1;
				this.activerSection(this.section);
				//alert(precedent.src)
			}
			else
			{
				$('.vue').animate({"left": "-="+ul[0].offsetWidth+"px"}, "slow", function() {
	  Galerie.autoriser = true;
	  });
				
				var precedent = document.getElementById('precedent');
				var img = precedent.getElementsByTagName('img')[0];
				img.src = '/assets/images/btn/precedent.png';
				img.style.left = "10px"; 
				this.section++;
				this.activerSection(this.section);
			}
		}//autoriser
	},//suivant
	
	prcedent : function()
	{
		if(this.autoriser)
		{
			var ul = this.cible.getElementsByTagName('ul');
			var total = ul.length;
			var cible = ul[0];
			
			if(this.section > 1)
			this.desactiverSection(this.section);
			
			if(cible.offsetLeft < 0)
			{
				this.autoriser = false;
				$('.vue').animate({"left": "+="+ul[0].offsetWidth+"px"}, "slow",function() {
	  Galerie.autoriser = true;
	  });
				var precedent = document.getElementById('precedent');
				var img = precedent.getElementsByTagName('img')[0];
				img.src = '/assets/images/btn/precedent2.png';
				img.style.left = "10px"; 
				this.section--;
				this.activerSection(this.section);
			}
			
		}//autoriser
	},//suivant
	
	
	aller : function(n)
	{
		if(this.autoriser)
		{
			if(n !=  this.section)
			{	
				this.autoriser = false;
				this.desactiverSection(this.section);
				var ul = this.cible.getElementsByTagName('ul');
				var total = ul.length;
				var cible = ul[0];
				var pos = cible.offsetWidth * Math.abs(this.section - n);
				if(this.section > n)
				{
					$('.vue').animate({"left": "+="+pos+"px"}, "slow", function() {
	  Galerie.autoriser = true;
	  });
				}
				else
				{
				
					$('.vue').animate({"left": "-="+pos+"px"}, "slow", function() {
	  Galerie.autoriser = true;
	  });
				}
				
				this.section = n;
				this.activerSection(n);
			}
		}
	},//aller
	
	activerSection : function(n)
	{
		var img = document.getElementById('section'+n);
		
		if(img != null)
		img.src = '/assets/images/btn/rond.png';
	},//activerSection
	
	desactiverSection : function(n)
	{
		var img = document.getElementById('section'+n);
		
		if(img != null)
		img.src = '/assets/images/btn/rond2.png';
		
	}//activerSection
	
}//Galerie




