$(document).ready(function(){
	
	if($.browser.msie) {
		//$("#cont_move").
		
	}
	
	$("#fleche_left").fadeTo(0, 0.5);
	$("#fleche_right").fadeTo(0, 0.5);
	$(".mini").fadeTo(0, 0.8);

	// CALCULE DE LA TAILLE ET POSITIONNEMENT DE L'IMAGE
	$("#big").fadeTo(0, 0);
	
	//alert($("#big").children("img").width())
	var img_b = $("#big").children("img").width();
	if(img_b == null) {
		$("#big").children("img").css("width", "auto");
		$("#blockcenter").css("height", "800px");
	}
	if(img_b == 0) {
		$("#big").children("img").css("width", "auto");
		$("#blockcenter").css("height", "800px");
		img_b = $("#big").children("img").width();
	}
	if(img_b > 550) {
		$("#big").children("img").css("width", "550px");
		$("#blockcenter").css("height", ($("#big").children("img").height() + 350) + "px");
		img_b = $("#big").children("img").width();
	}
	$("#big").css("visibility", "visible");
	$("#big").width(img_b)
	//$("#big").css("width", $("#big").children("img").width() + "px");
	$("#big").fadeTo(600, 1);
	$("#big").css("margin-left", ((615 - img_b) / 2) + "px");
	

	// CALCULE DE LA TAILLE DU SLIDER
	var taille = 0;
	$(".mini").each(function(i){
		taille += $(this).width();
	 });
	
	// OVER
	$("#fleche_left").mouseover(function() {
		move_mini(0);
		$(this).fadeTo(200, 1);
	});
	$("#fleche_right").mouseover(function() {
		move_mini(-(taille - 450));
		$(this).fadeTo(200, 1);
	});
	$(".mini").mouseover(function() {
		$(this).fadeTo(100, 1);
		
	});

	// OUT
	$("#fleche_left").mouseout(function() {
		$("#cont_move").stop();
		$(this).fadeTo(200, 0.5);
	});
	$("#fleche_right").mouseout(function() {
		$("#cont_move").stop();
		$(this).fadeTo(200, 0.5);
	});
	$(".mini").mouseout(function() {
		$(this).fadeTo(100, 0.8);
		
	});
	
	function move_mini(i) {
		$("#cont_move").stop();
		if($("#cont_move").css("margin-left").replace("px", "") == "auto") {
			var t = (taille - 0) * 2;
		}else {
			var t = taille - ($("#cont_move").css("margin-left").replace("px", ""));
		}
		var newi = i + "px";
		$("#cont_move").animate({"marginLeft": newi}, t);
	}
	
	// IMAGE
	$(".mini").click(function() {
		$("#image_url").val($(this).children("img").attr("src"));
		$("#image_titre").val($(this).children("span").html());
		$("#form_hidden").submit();
	});
	
});
