//init
window.onload= function(){
	//	alert('init : ' + cat);
	//
	affich(43);// affichage des liens courants lors de PREMIERE ARRIVEE (page affichée par défaut : 0)

	var liens_p = $$("a.a_cat1");// liens MENU GAUCHE
	// "a.a_cat1_crs" observé lors de affich(0) de onload
	if(liens_p.length){
		for(prop in liens_p){
			if(typeof liens_p[prop] == 'object') {
				Event.observe(liens_p[prop], "click", affich, false);
			}
		}
	}
	var divs = $$("a.titre_2");// liens MENU HAUT
	if(divs.length){
		$H(divs).each(function(item){
			var str = String(item.value);
			//alert(str + ' = ' + cat + ' ? ');
			if(str.match(eval(cat))){
				//alert(item.value);
				var enfants = item.value.childNodes;
				var mess = '';
				for(prop in enfants){
					if(typeof enfants[prop] == "object"){
						var obj = enfants[prop];
						var j = obj['src'].lastIndexOf('.');// ! il pt y avoir plusieurs '.' (http://127.0.0.1/...)
						var chemin = obj['src'].substring(0, j);// chemin + nom de fichier sans extension
						new_img = chemin + '_roll.gif';
						//alert(new_img);
						obj['src'] = new_img;
					}
				}
				//alert('enfants ' + mess);
			}else{
				Event.observe(item.value, "mouseover", hover, false);
				Event.observe(item.value, "mouseout", hover_out, false);
			}
		});
	}
	//menu gauche : gestion du chgt de puce avec mouse
	var liens = $$("a.dossier");
	//var enfants = liens.childNodes
	var n = 0;
	$H(liens).each(function(item, value){
		n++;
		if(n < 14){
			//			alert(item.value + ' => ' + item.value.childNodes.length);
			var enfants = item.value.childNodes;
			Event.observe(item.value, "mouseover", hover2, false);
			Event.observe(item.value, "mouseout", hover2_out, false);
			Event.observe(item.value, "click", affich, false);
		}
	});
}

/********************* functions *************************/
/**
@ public
@ purpose : gère les liens en cours pour menu gauche / affiche l equipier courant
@ return cible : array : numéro de page / C_cat(s) / A_article(s)
*/
function affich(e){
	// j'afficher la page voulue
	//	alert('e : ' + typeof e);
	if(typeof e == 'object'){
		var elt = Event.element(e).id;
	}else{
		//
		var elt = 43;// 1ère arrivée : page 0 à afficher
	}

	var pages = $$("div.bloc");
	var ok = 0;
	if(pages.length){
		var cible = new Array();
		var id = new String();
		$H(pages).each(function(item, value){
			//
			var id = pages[value].id;//
			//alert('comparaison : ' + id + ' = ' + elt + ' ?');
			if(id == elt){
				//alert('id de page : ' + compts.toString());
				//cible = compts; // récup numéro/titres cat et art de page affichée
				ok = 1;
			}
			if(ok){
				//alert('bloc : ' + id);
				pages[value].style.display = '';
				var mail = 'mail' + id;
				$(mail).style.display = '';
				affich_menu_g(id);
				affich_photos(id);
			}else{
				pages[value].style.display = 'none';
				var mail = 'mail' + id;
				$(mail).style.display = 'none';
				//$('_' + compts[0]).className = 'lien_page';
			}
			ok = 0;
		});
	}
	//alert('ID : ' + id);

}

/**
@ private <= function affich
@ purpose : affichage lien en cours de liens de menu gauche
*/
function affich_menu_g(cible){
	// 	alert ('récup tous les liens de menu_gauche : ');
	var frag = $$('div.cadre_gauche');
	if(frag.length){
		$H(frag).each(function(item, value){
			//				alert(frag[value].childNodes.toString());
			var pages = frag[value].childNodes;
			$H(pages).each(function(item, value){
				//alert(typeof pages[value]);
				if(typeof pages[value] == 'object'){
					var num = pages[value];
					if(num.tagName == 'P'){
						//alert(num.innerHTML);
						if(num.childNodes.length > 0){
							var liens = num.childNodes;
							$H(liens).each(function(item, value){
								var a = liens[value];
								if(typeof a == 'object'){
									if(a.tagName == 'A'){
										//alert(a.id);
										//typeof cible[prop] != 'function' &&
										if(a.id != ''){// ne prend pas en cpte les a sans id (titres dossiers)
											//											alert(a.id + ' == ' + cible + ' ? ');
											if(a.id == cible){
												//alert('en cours : ' + a.id + ' => ' + a.innerHTML + ' => class : ' + a.className);
												a.className = 'dossier_crs';
												Event.observe(a, "click", affich, false);
												Event.stopObserving(a, "mouseout", hover2_out, false);
												//alert('en cours : ' + a.id + ' => ' + a.innerHTML + ' => class : ' + a.className);
												var enfants = a.childNodes;
												for(prop in enfants){
													//	alert('nodeType : ' + enfants[prop]["nodeType"] + " => " + enfants[prop]["tagName"]);
													if(enfants[prop]["tagName"] == 'IMG'){
														//alert('img : ' + enfants[prop]["src"]);
														enfants[prop]["src"] = 'img/LMC/cat/sup_rouge.jpg';
													}
												}
											}else{
												a.className = 'dossier';
												Event.observe(a, "mouseout", hover2_out, false);
												var enfants = a.childNodes;
												for(prop in enfants){
													//	alert('nodeType : ' + enfants[prop]["nodeType"] + " => " + enfants[prop]["tagName"]);
													if(enfants[prop]["tagName"] == 'IMG'){
														//alert('img : ' + enfants[prop]["src"]);
														enfants[prop]["src"] = 'img/LMC/cat/sup_noir.jpg';
													}
												}
											}
										}

									}
								};
							});
						}
					}
				}
			});
		});
	}
}
function affich_photos(cible){
	var frag = $$('img.gall_nb');
	//alert ('récup photos : ' + frag.toString());
	var img_nb = new Array();
	var n = 0;
	$H(frag).each(function(item, value){
		//				alert(value + ' => ' + frag[value]);
		img_nb[n] = frag[value];
		n++;
	});
	//alert('tab nb : ' + img_nb.toString());
	var frag = $$('img.gall_c');
	var img_c = new Array();
	n=0;
	//alert ('récup photos : ' + frag.toString());
	$H(frag).each(function(item, value){
		img_c[n] = frag[value];
		n++;
	});
	var frag = $$('img.gall');
	n = 0;
	$H(frag).each(function(item, value){
		//	alert(item + ' => ' + frag[value]);
		var img_dest = frag[value];
		if(img_dest.id == cible){
			img_dest.src = img_c[n].src;
		}else{
			img_dest.src = img_nb[n].src;
		}
		//alert('ID => ' + img_dest.id);
		n++;
	});
}

var img_src = '';
function hover(e){
	//alert('hover : ' + Event.element(e).src);
	img_src = Event.element(e).src;
	var i = img_src.lastIndexOf('.');// ! il pt y avoir plusieurs '.' (http://127.0.0.1/...)
	var chemin = img_src.substring(0, i);// chemin + nom de fichier sans extension
	new_img = chemin + '_roll.gif';
	//alert(new_img);
	Event.element(e).src = new_img;
}
function hover_out(e){
	//alert('out');
	Event.element(e).src = img_src;
}
/*********************** hovers menu gauche **********************/
function hover2(e){
	var enfants = Event.element(e).childNodes;
	for(prop in enfants){
		//			alert('nodeType : ' + enfants[prop]["nodeType"] + " => " + enfants[prop]["tagName"]);

		if(enfants[prop]["tagName"] == 'IMG'){
			enfants[prop]["src"] = 'img/LMC/cat/sup_rouge.jpg';
		}/**/

	}
}
function hover2_out(e){
	var enfants = Event.element(e).childNodes;
	for(prop in enfants){
		//alert('nodeType : ' + enfants[prop]["nodeType"] + " => " + enfants[prop]["tagName"]);
		if(enfants[prop]["tagName"] == 'IMG'){
			enfants[prop]["src"] = 'img/LMC/cat/sup_noir.jpg';
		}/**/

	}
}
