positionImage = new Array();
var description = new Array();
var timers = new Array();
widthTotal = 0;
familleActuelle = 0;
/*
$(document).keypress(function() {
test = $("#liste_miniatures").css("left");
test= parseInt(test);
test = Math.abs(test);
test+=1;

$("#liste_miniatures").css("left",test+"px");

} );
*/
function afficheGrande(ID, position){



var famille = $("#liste_miniatures a#"+ID).parent().attr('name');
	$("#liste_miniatures img#"+ID).removeClass("origin");
	$("#liste_miniatures img#"+ID).addClass("light");

	$("#grande_photo").html("<a id='"+ID+"' rel='gallerie' href='/cgi-local/album_photo.pl?Action=Image&ID="+ID+"&format=Photo'><img src='/cgi-local/album_photo.pl?Action=Image&ID="+ID+"&format=Photo' border='0' alt='' title=''></a>");
	$("#liste_miniatures a[rel='desactive']").attr("rel", "gallerie");
	$("#liste_miniatures a[rel='gallerie'][id='"+ID+"']").attr("rel", "desactive");
	



position_img = position;


//alert(position);

	$("a[rel='gallerie']").colorbox({photo:'false', current:'image {current} sur {total}'});


	$("#description_photo").html(description[ID]);


}

function clearAllTimeouts(){  
  for(key in timers ){  
    clearTimeout(timers[key]);  
  }  
}  


function goLeft(el){
//alert("coucou");
famille = $(el).attr("name");

pos = $(".liste_miniatures.famille"+famille).css("left");

if(widthTotal < 1 || famille != familleActuelle)
{
widthTotal = 0;
nbImage = 0;
widthImages = 0;
$(".liste_miniatures.famille"+famille+" img").each(function(i){
thisWidth = $(this).outerWidth();
widthImages += $(this).outerWidth();
nbImage++;
});

marge = parseInt($(".liste_miniatures.famille"+famille+" img").css("marginRight"));
//bordure = parseInt($("#liste_miniatures[name="+famille+"] img").css("border-left"));

widthMarges = marge*2*nbImage -(2*marge) ;
widthMarges *=2; // Si je ne mets pas les images à left, les marges sont doublées...

//widthBordures = bordure*2*nbImage;

widthTotal = widthImages + widthMarges;
}

familleActuelle = famille;
//alert($("#liste_miniatures img:last-child").offset().left);
pos= parseInt(pos);
abspos = Math.abs(pos);

jetriche = 610;
jetriche = $("#bloc_miniatures").width();

/* TEST OPTIMISATION 
var derniereImage = positionImage.length -1;
var offsetLM = $(".liste_miniatures img#"+derniereImage).offset();
alert(offsetLM.left);
offsetLM += $(".liste_miniatures img#"+derniereImage).outerWidth();

alert(offsetLM + "  "+ widthTotal);

FIN TEST */
if( widthTotal - jetriche > abspos )
{
newpos = pos-2;
$(".liste_miniatures.famille"+famille).css("left",newpos+"px");
timers.pop;
timers.push(setTimeout(function(){goLeft(el);}, 10));
}

/*
offsetImg = premiere_image.offset();
if(offsetImg.left + premiere_image.width() < 0)
{
	$("div#liste_miniatures").append("a#"+premiere_image_id);
	premiere_image_id = getNextImage();
	premiere_image = $("img#"+premiere_image_id);
}
*/




}

function getNextImage()
{
	for(i=0;$i<positionImage.length;i++)
	{
		if(positionImage[$i] == premiere_image_position + 1)
		{
			return $i;
		}
	}
}






function goRight(el){
famille = $(el).attr("name");
objet = $(".liste_miniatures.famille"+famille);

pos = objet.position().left;

pos = parseInt(pos);
if(pos<0)
{
	newpos = pos+2;
	objet.css("left", newpos+"px");
	timers.pop;
	timers.push(setTimeout(function(){goRight(el);}, 10));
}
}



$(window).load(function(){
defile();
$(".liste_miniatures img").mouseover(function(){
clearAllTimeouts(); // Je supprime le déplacement automatique s'il était là
ID = $(this).attr("id");
$(this).removeClass("origin");
$(this).addClass("light");
});


$(".liste_miniatures img").mouseout(function(){
$(this).removeClass("light");
$(this).addClass("origin");
defile()
});






$("img.gauche").mouseover(function(){
goRight($(this));
});

$(".gauche").mouseout(function(){
clearAllTimeouts();
});

$("img.droite").mouseover(function(){
goLeft($(this));
});

$(".droite").mouseout(function(){

clearAllTimeouts();
});

});


