var DDSPEED = 5;
var DDTIMER = 10;

// main function to handle the mouse events //
function ddMenu(id,dir) {
var head = document.getElementById(id + '-ddheader');
var cont = document.getElementById(id + '-ddcontent');
clearInterval(cont.timer);
if(dir == 1) {
clearTimeout(head.timer);
if(cont.maxh && cont.maxh <= cont.offsetHeight) {
return;
} else if(!cont.maxh) {
cont.style.display = 'block';
cont.style.height = 'auto';
cont.maxh = cont.offsetHeight;
cont.style.height = '0px';
}
cont.timer = setInterval("ddSlide('" + id + "-ddcontent', 1)", DDTIMER);
} else {
head.timer = setTimeout('ddCollapse(\'' + id + '-ddcontent\')', 30);
}
}

// collapse the menu //
function ddCollapse(id) {
var cont = document.getElementById(id);
cont.timer = setInterval("ddSlide('" + id + "', -1)", DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown content //
function cancelHide(id) {
var head = document.getElementById(id + '-ddheader');
var cont = document.getElementById(id + '-ddcontent');
clearTimeout(head.timer);
clearInterval(cont.timer);
if(cont.offsetHeight < cont.maxh) {
cont.timer = setInterval("ddSlide('" + id + "-ddcontent', 1)", DDTIMER);
}
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(id,dir) {
var cont = document.getElementById(id);
var currheight = cont.offsetHeight;
var dist;
if(dir == 1) {
dist = (Math.round((cont.maxh - currheight) / DDSPEED));
} else {
dist = (Math.round(currheight / DDSPEED));
}
if(dist <= 1 && dir == 1) {
dist = 1;
}
cont.style.height = currheight + (dist * dir) + 'px';
cont.style.opacity = currheight / cont.maxh;
cont.style.filter = 'alpha(opacity=' + (currheight * 100 / cont.maxh) + ')';
if((currheight < 2 && dir != 1) || (currheight > (cont.maxh - 2) && dir == 1)) {
clearInterval(cont.timer);
}
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function displayPics()
{
	var photos = document.getElementById('tt_vues') ;
	// On récupère l'élément ayant pour id galerie_mini
	var liens = photos.getElementsByTagName('a') ;
	// On récupère dans une variable tous les liens contenu dans tt_vues
	var big_photo = document.getElementById('big_pict') ;
	// Ici c'est l'élément ayant pour id big_pict qui est récupéré, c'est notre photo en taille normale
	
	var imgPath = document.getElementById('theProductImg').style.backgroundImage;
	
	for(var i = 0 ; i < liens.length ; i++)
	// Une boucle parcourant l'ensemble des liens contenu dans galerie_mini
	
	{
		liens[i].onclick = function()
		// Au clic sur ces liens
		{
			big_photo.src = this.href ; // On change l'attribut src de l'image en le remplaçant par la valeur du lien
			var my_id = this.id ;
			var my_small_pic = document.getElementById('small_' + my_id);
			// Le lien sur la grande photo
			var lien_big_pict = document.getElementById('lien_big_pict') ;
			my_small_pic.setAttribute("style","border:1px solid #eb4a0b");
			for(var i = 0 ; i < liens.length ; i++)
			{
				if (i != my_id) {
				var my_small_pic = document.getElementById('small_' + i);
				my_small_pic.setAttribute("style","none");
				}
			}
			lien_big_pict_temp = this.href ;
			lien_big_pict_temp = lien_big_pict_temp.replace('/overview/','/zoom/');
			lien_big_pict.href = lien_big_pict_temp ;
			// on change aussi le backgroung pour le div#overlay
			var new_bg_pictpict = "url("+lien_big_pict_temp+")"
			document.getElementById('theProductImg').style.backgroundImage = new_bg_pictpict;
			return false ; // Et pour finir on inhibe l'action réelle du lien
		}

	}
}


//afficher ou masquer DIV
function montrerCacher(div)
	{
		if(document.getElementById(div).style.display == 'none')
		{
			document.getElementById(div).style.display = 'block';
		}
		else
		{
			document.getElementById(div).style.display = 'none';
		}
	}
