var effet_zoom;
var num_zoom;
var Wzoom = 300;
var Hzoom = 340;
var nbrePxW=1;
var nbrePxH=1;
var opacity=0;
var filter=0;
var Vitesse=9;

function zoom(num_id, num) {
	dezoom();
	num_zoom=num_id;
	var boxZoom = $E('zoom_'+num_id);	
	var imgAppelante = $E('img_art_'+num_id);
	
	var widthAppelante = imgAppelante.width;
	var margeLeft = widthAppelante/2;
	var heightAppelante = imgAppelante.height;
	var margeTop = heightAppelante/2;
	
	boxZoom.style.background='#fff url("./images/articles/art_'+num+'_zoom.jpg") no-repeat center';
	boxZoom.style.width=widthAppelante+'px';
	boxZoom.style.height=heightAppelante+'px';
	boxZoom.style.zIndex='50000';
	boxZoom.style.border='2px solid #ccc';
		
	effet_zoom = setInterval(function(){ouvreWzoom(boxZoom, widthAppelante, margeLeft, heightAppelante, margeTop)}, 30);
}

function preloadImgArt(box) {
	
}

function ouvreWzoom(box, Wdepart, margeL, Hdepart, margeT) {
	Wdepart += nbrePxW*2;
	box.style.marginLeft = -nbrePxW+'px';
	box.style.width = Wdepart+'px';
	//y*100/c.scrollHeight
	nbrePxW +=Vitesse;
	
	if(Wdepart >= Wzoom) {
		clearInterval(effet_zoom);
		opacity=(nbrePxW/box.offsetWidth);
		filter=(nbrePxW*100/box.scrollWidth);
		effet_zoom = setInterval(function(){ouvreHzoom(box, Hdepart, margeT)}, 30);
	}
}

function ouvreHzoom(box, Hdepart, margeT) {
	Hdepart += nbrePxH*2;
	box.style.marginTop = -nbrePxH+'px';
	box.style.height = Hdepart+'px';
	nbrePxH +=Vitesse;
	
	if(Hdepart >= Hzoom) {
		box.innerHTML = '<a class="right" href="#" title="Fermer le zoom" onclick="dezoom('+num_zoom+'); return false"><img src="./images/close.png" alt="" /></a>';
		clearInterval(effet_zoom);
	}
}

function dezoom(num) {
	if(num) {
		var boxZoom = $E('zoom_'+num);
		boxZoom.innerHTML='';
		boxZoom.style.width=0;
		boxZoom.style.height=0;
		boxZoom.style.marginLeft=0;
		boxZoom.style.marginTop=0;
		boxZoom.style.border=0;
		nbrePxW=1;
		nbrePxH=1;
	}
	else {
		var i;
		for(i=0; i<50; i++) {
			if($E('zoom_'+i) && $E('zoom_'+i).offsetHeight>0) {
				var boxZoom = $E('zoom_'+i);
				boxZoom.innerHTML='';
				boxZoom.style.width=0;
				boxZoom.style.height=0;
				boxZoom.style.marginLeft=0;
				boxZoom.style.marginTop=0;
				boxZoom.style.border=0;
				nbrePxW=1;
				nbrePxH=1;
			}
		}
	}
}

