
// profondeur vaut 1 si les images sont des enfants directs du conteneur
// vaut 2 si chaque image est encapsulée dans un DIV
function initZoom(conteneurCSS, profondeur)
{	
	$(conteneurCSS+" img.zoomable").each(function(k){
		$(this).unbind("click").bind("click", function(){			
			affPhotoBig($(this), k, profondeur);
		});
	});
}


function affPhotoBig(obj, k, profondeur)
{
	if (profondeur == 1) nb = obj.parent().children("img.zoomable").size();
	else nb = obj.parent().parent().find("img.zoomable").size();
	
	url = obj.attr('src');
	p = url.lastIndexOf("/");
	dossier = url.substr(0,p+1);
	fichier = url.substr(p+1);
	p = fichier.lastIndexOf("-");
	fichier = fichier.substr(0, p);
	$.post("/wp-content/themes/ecoelec/ajax_getPhotoBig.php", {d:dossier, f:fichier}, function(urlBig)
	{
		if ($("#calqueBlanc").size() == 0) $("body").append("<div id='calqueBlanc'></div>");
		$("body").append("<div id='zoneBig'><div id='messageSouris'>Cliquez pour<br/>revenir<br/>au site</div><div id='btnPhotoPrec'><img src='"+IMGPATH+"flecheGauche.png' /><br/>PHOTO<br/>PRECEDENTE</div><div id='btnPhotoSuiv'><img src='"+IMGPATH+"flecheDroite.png' /><br/>PHOTO<br/>SUIVANTE</div><img id='loading' src='"+IMGPATH+"loading.gif' /><img src='"+urlBig+"' id='photoBig' /></div>");
		$("#btnPhotoPrec, #btnPhotoSuiv, #messageSouris").hide();
		$("#calqueBlanc").fadeTo(0,0.5).css("visibility", "visible");
		
		yloading = ($(window).height() - 50) >> 1;
		xloading = ($(window).width() - 50) >> 1;
		$("#loading").css("top", yloading+"px").css("left", xloading+"px").fadeTo(0,0).fadeTo(500,0.4);
		
		$("#photoBig").load(function()
		{
			$("#loading, #global, #sloganVertical, #fondPerduBlanc, #fondPerduTitre, #fondPerduActus").hide();
			$(this).css("visibility", "visible");
			lp = $(this).width(); hp = $(this).height();
			lg = $(window).width(); hg = $(window).height();					
			if (hp > hg) {ratio = hg/hp; lp=ratio*lp; hp=ratio*hp;}					
			if (lp > 1000) {ratio = 1000/lp; lp=1000; hp=ratio*hp;}					
			xp = (lg-lp)>>1; yp = (hg-hp)>>1;
			$(this).css("left", xp+"px").css("top", yp+"px").css("height", hp+"px");					
			xBtnGauche = (($(window).width() - $("#global").width()) >> 1) - 95;					
			if (k > 0) $("#btnPhotoPrec").css("top", (hg>>1)+"px").css("left", xBtnGauche+"px").show();					
			xBtnDroite = $("#global").width() + xBtnGauche + 100;					
			if (k < nb-1) $("#btnPhotoSuiv").css("top", (hg>>1)+"px").css("left", xBtnDroite+"px").show();			
		}
		).mouseenter(function(e){
			$("#messageSouris").css("left", e.pageX+"px").css("top", (e.pageY+22)+"px").show();					
		}).mousemove(function(e){
			$("#messageSouris").css("left", e.pageX+"px").css("top", (e.pageY+22)+"px").show();					
		}).mouseleave(function(){
			$("#messageSouris").hide();
		}).click(function(){
			$("#zoneBig, #calqueBlanc").remove();
			$("#global, #sloganVertical").show();
			positionnerElements();
		});
		
		$("#btnPhotoPrec").click(function(){
			$("#zoneBig").remove();			
			if (profondeur == 1) obj = obj.parent().find("img.zoomable").eq(k-1);			
			else obj = obj.parent().parent().find("img.zoomable").eq(k-1);
			affPhotoBig(obj, k-1, profondeur);
		});
		
		$("#btnPhotoSuiv").click(function(){
			$("#zoneBig").remove();			
			if (profondeur == 1) obj = obj.parent().find("img.zoomable").eq(k+1);
			else obj = obj.parent().parent().find("img.zoomable").eq(k+1);
			affPhotoBig(obj, k+1, profondeur);
		});
	});
}




