
var p_normal_i = "";
var p_zoom_i = "";
var p_duree = 0;
var p_zoom_height = 0;
var p_zoom_width = 0;

var p_d_x = 0;
var p_d_y = 0;

function openZoom(normal_i,zoom_i,zoom_width,zoom_height,duree){
	//Paramètres :
	p_normal_i = normal_i;
	p_zoom_i = zoom_i;
	p_duree = duree;
	p_zoom_width = zoom_width;
	p_zoom_height = zoom_height;
	
	//on récupère les dimensions des images (normales et zoom)
	var s_img = getImgSize(normal_i);
	var e_img = {width:0, height:0};
	e_img.width = zoom_width;
	e_img.height = zoom_height;
	
	//On récupère les divs utilisées (normales et zoom)
	var normal = document.getElementById("zoom_vuenormale");
	var zoom = document.getElementById("zoom_vuezoom_img");
	zoom.setAttribute('src',p_normal_i);
	
	//On récupère la position de la div normale
	var pos = getPos(normal);
	
	//On redéfinit les dimensions de la div zoom
	zoom.style.width = s_img.width;
	zoom.style.height = s_img.height;
	
	//On place la div zoom au dessus de la div normale
	zoom.style.top = pos.y+"px";
	zoom.style.left = pos.x+"px";
	
	//On l'affiche
	zoom.style.display = "";
	
	//Calcul du décalage pour centrage de l'image
	var d_x = (document.documentElement.clientWidth/2)-(e_img.width / 2);
	var d_y = (document.documentElement.clientHeight/2)-(e_img.height / 2)+document.documentElement.scrollTop;
	p_d_x = d_x;
	p_d_y = d_y;
	
	//Effect du zoom de l'image
	new Effect.Morph('zoom_vuezoom_img', {
	  style: 'width:'+e_img.width+'px; height:'+e_img.height+'px;top:'+d_y+'px; left:'+d_x+'px;', // CSS Properties
	  duration: duree // Core Effect properties
	});
	
	//Set ocacité à 0
	set_opacity("zoom_forground",0);
	document.getElementById("zoom_forground").style.display = "";
	
	//Effet sur l'opacité du fond
	Effect.Appear('zoom_forground', { duration: p_duree, from:0, to:0.5 });
	
	setTimeout("loadBigImage()",p_duree*1000+5);
}

function loadBigImage(){
	var zoom = document.getElementById("zoom_vuezoom_img");
	var fermer = document.getElementById("zoom_fermer");
	zoom.setAttribute('src',p_zoom_i);
	zoom.style.cursor = "pointer";
	
	fermer.style.top = (p_d_y-17-5)+"px";
	fermer.style.left = (p_d_x+p_zoom_width-80)+"px";
	fermer.style.display = "";
	
	//Effet sur le bouton fermer
	set_opacity("zoom_fermer",0);
	document.getElementById("zoom_fermer").style.display = "";
	Effect.Appear('zoom_fermer', { duration: 0.4, from:0, to:1 });
	
	zoom.onclick = function(){
		closeZoom();
	}
}

function closeZoom(){
	//On récupère les divs utilisées (normales et zoom)
	var normal = document.getElementById("zoom_vuenormale");
	var zoom = document.getElementById("zoom_vuezoom_img");
	
	//On récupère la position de la div normale
	var pos = getPos(normal);
	
	//on récupère les dimensions des images (normales et zoom)
	var s_img = getImgSize(p_normal_i);
	
	
	//Effect du zoom de l'image
	new Effect.Morph('zoom_vuezoom_img', {
	  style: 'width:'+s_img.width+'px; height:'+s_img.height+'px;top:'+pos.y+'px; left:'+pos.x+'px;', // CSS Properties
	  duration: p_duree // Core Effect properties
	});
	
	//Effet sur l'opacité du fond
	Effect.Appear('zoom_forground', { duration: p_duree, from:0.5, to:0 });
	
	//Effet sur le bouton fermer
	Effect.Appear('zoom_fermer', { duration: 0.2, from:1, to:0 });

	setTimeout("endClose()",p_duree*1000+5);
}

function endClose(){
	var zoom = document.getElementById("zoom_vuezoom_img");
	
	zoom.style.display = "none";
	document.getElementById("zoom_forground").style.display = "none";
	
	document.getElementById("zoom_fermer").style.display = "none";
	
}

function loadView(normal,zoom,dureeeffet,loupe,tooltip,nbvues,cvue,url_actif){
	for(var i=1; i<=nbvues; i++){
		document.getElementById("zoom_vue_"+i).setAttribute("class","item");	
	}
	document.getElementById("zoom_vue_"+cvue).setAttribute("class","item_selected");	
	
	sendAjax("/zoom/ajax_normal.cfm", self.viewLoaded, 'post', "normal="+normal+"&zoom="+zoom+"&dureeeffet="+dureeeffet+"&loupe="+loupe+"&tooltip="+tooltip+"&url_actif="+url_actif, []);
}

function viewLoaded(text,xml,params){
	document.getElementById("zoom_container").innerHTML = text;
}

function getPos(el){
	for(var lx=0, ly=0;
		el != null;
		lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
	return {x: lx, y: ly};
}

function getImgSize(imgSrc){
	var newImg = new Image();
	newImg.src = imgSrc;
	var height = newImg.height;
	var width = newImg.width;
	return {width: width, height: height};
}

function set_opacity(id, opacity){
	el = document.getElementById(id);
	try{ el.style["filter"] = "alpha(opacity="+opacity+")"; }catch(err){}
	try{ el.style["-moz-opacity"] = opacity/100; }catch(err){}
	try{ el.style["-khtml-opacity"] = opacity/100; }catch(err){}
	try{ el.style["opacity"] = opacity/100; }catch(err){}
	return true;
}

