var nbOnglets = 4; // Nombre d\'onglets
var temps = 8000; // Temps d\'attente en millisecondes (=10 secondes)
var transitiondelay = 200; // Delay JQuery de transition
var t2 = transitiondelay + 10;
// Première image
$(document).ready(function(){
	changeImage(1);
	setTimeout("auto(2)",temps);
});

// Change une image
var sel = 0;
var isChanging = false;
var timer;
function changeImage(img)
{
	if(isChanging)
		return;
	
	if( img != sel )
	{
		// On cache tout
		$("#contenttext").animate({ 
	        opacity: 1
	     }, 1 );
		$("#contenttext").hide("drop",{ direction: "down" }, transitiondelay);
		$("#content").hide("drop",{ direction: "right" },transitiondelay);
		sel = img;
		isChanging = true;
		setTimeout("showImage("+img+")", t2);
	}
}

// Montre la nouvelle image apr�s que l\'autre est disparue
function showImage(img)
{
	// On change l\'onglet avant
	ongletSelect(img);
	
	document.getElementById("content").innerHTML = document.getElementById("content"+img).innerHTML;
	$("#content").show("drop",{ direction: "right" },transitiondelay);
	setTimeout("showText("+img+")", t2);
}

// Monter le texte apr�s que l\'image soit apparue
function showText(img)
{
	document.getElementById("contenttext").innerHTML = document.getElementById("contenttext"+img).innerHTML;
	$("#contenttext").show("drop",{ direction: "down" },transitiondelay);
	setTimeout("IEFix("+img+")", t2);
}

// Remet le texte transparent
function IEFix(img)
{
	$("#contenttext").animate({ 
		opacity: 0.85
	}, transitiondelay );
	setTimeout("Finish()", t2);
}

// Permet de rechanger de diapo
function Finish()
{
	isChanging = false;
}

// ========= SCRIPT AUTO
function auto(nb)
{
	changeImage(nb);
	nb = nb + 1;
	if(nb > nbOnglets)
		nb = 1;
	
	clearTimeout(timer);
	timer = setTimeout("auto("+nb+")",temps);
}

function ongletSelect(nb)
{	a=1;
	for(var i=1; i<=nbOnglets; i++)
	{
		document.getElementById("onglet"+i).style.background = "url(templates/graphique/Site-MVSDistrib-SliderArticle-Bouton230610.jpg)";				
		document.getElementById("onglet"+i).style.backgroundPosition = "top";
		document.getElementById("onglet"+i).onmouseover = function() {this.style.backgroundPosition = "center";};
		document.getElementById("onglet"+i).onmouseout = function() {this.style.backgroundPosition = "top";};
		a++;
		if (a==3){a=1;}
	}
	document.getElementById("onglet"+nb).style.backgroundPosition = "bottom";
	document.getElementById("onglet"+nb).onmouseover = function() {this.style.backgroundPosition = "center";};
	document.getElementById("onglet"+nb).onmouseout = function() {this.style.backgroundPosition = "bottom";};

}

function clickOnglet(nb)
{
	if( isChanging )
		return;
	
	var nbnext = nb + 1;
	if(nbnext > nbOnglets)
		nbnext = 1;
	clearTimeout(timer);
	timer = setTimeout("auto("+nbnext+")",temps);
	changeImage(nb);
}
