$(function()
{
	positionnerElements();
	window.onresize = positionnerElements;
	
	if ($("#galerie_mediatheque").size() > 0)
	{
		$("#galerie_mediatheque  img.tof").click(function(){		
			src = $(this).attr('src');
			x = $(this).offset().left; y = $(this).offset().top;
			$("#photoBig").remove();
			$("body").append("<img src='"+src+"' id='photoBig' />");
			$("#photoBig").css("width", "110px").css("left", x+"px").css("top", y+"px").animate({width:468,left:'-=179',top:'-=145'}, 300, function(){
				$("#photoBig").one("click", function(){				
					$(this).animate({width:110, left:'+=179', top:'+=145'}, 150, function(){
						$(this).remove();						
					});
				}).one("mouseleave", function(){
					$(this).animate({width:110, left:'+=179', top:'+=145'}, 150, function(){
						$(this).remove();						
					});
				});
			});
		});
		
		$("#galerie_mediatheque img.tof:gt(15)").hide();
		
		$("#btnGalerieSuivante").click(function(){
			$("#galerie_mediatheque img.tof").hide();
			$("#galerie_mediatheque img.tof:gt(15)").show();						
			$("#btnGalerieSuivante").hide();
			$("#btnGaleriePrecedente").show();
		});
		
		$("#btnGaleriePrecedente").click(function(){
			$("#galerie_mediatheque img.tof").hide();
			$("#galerie_mediatheque img.tof:lt(16)").show();			
			$("#btnGalerieSuivante").show();
			$("#btnGaleriePrecedente").hide();			
		});
	}
});

function positionnerElements()
{
	h = $(window).height();
	hc = $("#conteneur").height();
	y = (h-hc)>>2; if (y<0) y=0;
	$("#conteneur").css("marginTop", y+"px");
}
