// JavaScript Document

function addEvent(oElem, sEvType, fn, bCapture) {
	return oElem.addEventListener?
		oElem.addEventListener(sEvType, fn, bCapture):
		oElem.attachEvent?
			oElem.attachEvent('on' + sEvType, fn):
			oElem['on' + sEvType] = fn;
}

//addEvent('body','load','init()');

function init() {
	init_menu('defil_verres');
	init_menu('defil_carafes');
	document.getElementById('defil_verres').style.left = 0 + 'px';
	document.getElementById('defil_carafes').style.left = 0 + 'px';
}

function zzoom(block) {
	zoom			= document.getElementById('zoom');
	pzoom			= document.getElementById('pzoom');
	parent			= block.parentNode;
	a				= zoom.parentNode;
	
	zoom.src		= block.src.replace(/menu/, "zoom");
	zoom.alt		= block.alt;
	a.href			= parent.href;
	a.title 		= parent.title;
	pzoom.innerHTML	= "Cliquez sur l'image pour voir les "+parent.title+".";
}

function init_menu(id) {
	menu	= document.getElementById(id);
	nbchild	= menu.childNodes.length;
	for(i=0;i<nbchild;i++) {
		if (menu.childNodes[i].nodeName == "A") {
			a			= menu.childNodes[i];
			href		= a.href;
			title		= a.title;
			nbchildx	= a.childNodes.length;
			for(x=0;x<nbchildx;x++) {
				if (menu.childNodes[i].childNodes[x].nodeName == "IMG") {
					img = menu.childNodes[i].childNodes[x];
					src	= img.src;
					alt	= img.alt;
					
					addEvent(img, 'mouseover', function() { zzoom(this); }, true);
					//addEvent(img, 'mouseover', function() { zzoom(src, alt, href, title); }, true);
					//addEvent(img, 'mouseover', zzoom(src, alt, href, title), true);
					/*addEvent(img, 'mouseover', function(img) {
						zoom		= document.getElementById('zoom');
						zoom.src	= img.src.replace(/menu/, "zoom");
					}, false);*/
				}
			}
		}
	}
}

function defil(id, sens) {
	block	= document.getElementById(id);
	maxleft	= block.offsetWidth - block.parentNode.offsetWidth;
	if (sens) {
		if ( parseInt(block.style.left) > -(maxleft) )
			block.style.left = parseInt(block.style.left) - (3*3) + 'px';
		else
			block.style.left = -(maxleft) + 'px';
	}
	else {
		if (parseInt(block.style.left) < 0)
			block.style.left = parseInt(block.style.left) + (3*3) + 'px';
		else
			block.style.left = 0 + 'px';
	}
	Timer = setTimeout('defil(\'' + id + '\', ' + sens + ');', 50);
}
