

var photoOpened = new Array();
function openPhotoBig(fiche_num, cli_num) {

	//on ferme les autre photos ouvertes
	for (num in photoOpened) {
		if (num != fiche_num && photoOpened[num] == 1) {
			closePhotoBig(num);
		}
	}

	if (photoOpened[fiche_num] && photoOpened[fiche_num] == 1) {
		closePhotoBig(fiche_num);
		return;
	} else {
		photoOpened[fiche_num] = 1;
	}
	
	var obj_div		= document.getElementById('fiche_'+ fiche_num +'_photoBigDiv');
	var obj_open	= document.getElementById('fiche_'+ fiche_num +'_ouverture');
	
	obj_open.src = '/images/listing/icone-reduirephotos.gif';
	
	var obj_photo	= document.getElementById('fiche_'+ fiche_num +'_photoBig');
	if (obj_photo && obj_div) {
		obj_photo.src = '/filer.php?file=photos/'+ cli_num + '-'+ fiche_num +'a.jpg&resize=1&resize_x=360&resize_y=270';
		obj_div.style.visibility = 'visible';
		var myEffect = new Fx.Morph(obj_div, {duration: 600, transition: Fx.Transitions.Sine.easeOut});
		myEffect.start({
			'width': 360,  //Morphs the 'width' style from 900px to 300px.
			'left': -7,  //Morphs the 'width' style from 900px to 300px.
			'top': -272, //Morphs the 'height' style from 10px to 100px.
			'height': 270 //Morphs the 'height' style from 10px to 100px.
		});
	}
}

function closePhotoBig(fiche_num) {
	photoOpened[fiche_num] = 0;
	var obj_div		= document.getElementById('fiche_'+ fiche_num +'_photoBigDiv');
	mout_photo(fiche_num, 1); // on cache l'icone
	mout_photo(fiche_num, 2); // on cache l'icone
	mout_photo(fiche_num, 3); // on cache l'icone
	var obj_open	= document.getElementById('fiche_'+ fiche_num +'_ouverture');
	obj_open.src = '/images/listing/icone-agrandirphotos.gif';
	if (obj_div) {
		var myEffect = new Fx.Morph(obj_div, {duration: 600, transition: Fx.Transitions.Sine.easeOut, onComplete: function(){ obj_div.style.visibility = 'hidden';} });
		myEffect.start({
			'top': -105, //Morphs the 'height' style from 10px to 100px.
			'height': 105, //Morphs the 'height' style from 10px to 100px.
			'left': 0,  //Morphs the 'width' style from 900px to 300px.
			'width': 140  //Morphs the 'width' style from 900px to 300px.
		});
	}
}

function goPhotoNext(fiche_num, cli_num) {
	if (have_photo[fiche_num] <= 1) return; // on fait rien si pas ou une seule photo
	if (have_photo_cur[fiche_num] < have_photo[fiche_num]) {
		have_photo_cur[fiche_num] ++;
	} else {
		have_photo_cur[fiche_num] = 1;
	}
	var obj_photo	= document.getElementById('fiche_'+ fiche_num +'_photoBig');
	obj_photo.src = '/filer.php?file=photos/'+ cli_num + '-'+ fiche_num + String.fromCharCode(have_photo_cur[fiche_num] + 96) +'.jpg&resize=1&resize_x=360&resize_y=270';
	var obj_compte	= document.getElementById('fiche_'+ fiche_num +'_photoCompte_txt');
	if (obj_compte) obj_compte.innerHTML = have_photo_cur[fiche_num] +" / "+ have_photo[fiche_num];
}

function goPhotoPrev(fiche_num, cli_num) {
	if (have_photo[fiche_num] <= 1) return; // on fait rien si pas ou une seule photo
	if (have_photo_cur[fiche_num] > 1) {
		have_photo_cur[fiche_num] --;
	} else {
		have_photo_cur[fiche_num] = have_photo[fiche_num];
	}
	var obj_photo	= document.getElementById('fiche_'+ fiche_num +'_photoBig');
	obj_photo.src = '/filer.php?file=photos/'+ cli_num + '-'+ fiche_num + String.fromCharCode(have_photo_cur[fiche_num] + 96) +'.jpg&resize=1&resize_x=360&resize_y=270';
	var obj_compte	= document.getElementById('fiche_'+ fiche_num +'_photoCompte_txt');
	if (obj_compte) obj_compte.innerHTML = have_photo_cur[fiche_num] +" / "+ have_photo[fiche_num];
}

var allTimeoutPrev = new Array();
var allTimeoutCompte = new Array();
var allTimeoutNext = new Array();
function mover_photo(fiche_num, laquelle) {
	if (photoOpened[fiche_num] == 0) return; //on quitte  car on ferme la fenettre de toute facon
	var obj;
	if (laquelle == 1) {
		clearTimeout(allTimeoutPrev[fiche_num]);
		obj	= document.getElementById('fiche_'+ fiche_num +'_photoGoPrev');
		if (obj) obj.style.display = 'block';
	} else if (laquelle == 2) {
		if (have_photo[fiche_num] > 1) { 
			clearTimeout(allTimeoutCompte[fiche_num]);
			obj		= document.getElementById('fiche_'+ fiche_num +'_photoCompte');
			obj2	= document.getElementById('fiche_'+ fiche_num +'_photoCompte_txt');
			if (obj2) obj2.innerHTML = have_photo_cur[fiche_num] +" / "+ have_photo[fiche_num];
			if (obj) obj.style.display = 'block';
		} 
	} else if (laquelle == 3) {
		clearTimeout(allTimeoutNext[fiche_num]);
		obj		= document.getElementById('fiche_'+ fiche_num +'_photoGoSuiv');
		if (obj) obj.style.display = 'block';
	}
}
function mout_photo(fiche_num, laquelle) {
	if (!laquelle || laquelle == 0) {
		allTimeoutPrev[fiche_num] = setTimeout('mout_photo('+ fiche_num +', 1)', 50);
		allTimeoutCompte[fiche_num] = setTimeout('mout_photo('+ fiche_num +', 2)', 50);
		allTimeoutNext[fiche_num] = setTimeout('mout_photo('+ fiche_num +', 3)', 50);
	} else {
		var obj;
		if (laquelle == 1) {
			obj		= document.getElementById('fiche_'+ fiche_num +'_photoGoPrev');
			if (obj) obj.style.display = 'none';
			clearTimeout(allTimeoutPrev[fiche_num]);
		} else if (laquelle == 2) {
			obj		= document.getElementById('fiche_'+ fiche_num +'_photoCompte');
			if (obj) obj.style.display = 'none';
			clearTimeout(allTimeoutCompte[fiche_num]);
		} else if (laquelle == 3) {
			obj		= document.getElementById('fiche_'+ fiche_num +'_photoGoSuiv');
			if (obj) obj.style.display = 'none';
			clearTimeout(allTimeoutNext[fiche_num]);
		}
	}
}
