//-- Une fois l'objet window chargé, la fonction gereDivSurgissant est appelée
Event.observe(this,'load',gereDivSurgissant);
cpt = 0;

//-- Cache tous les div surgissants
//-- Appelle la fonction affiche_div après un click sur un élément de classe "lien_contact"
function gereDivSurgissant(event){
    $$('.contact_surgissant').each(function(div){
	    div.hide();
	});
    $$('.title1_contact').each(function(div){
	    Event.observe(div,'click', affiche_div);
	});
    $$('.title1_contact1').each(function(div){
	    Event.observe(div,'click', affiche_div);
	});
    $$('.lien_contact').each(function(div){
	    Event.observe(div,'click', affiche_div);
	});
}
function affiche_div(event){
    
    // Commence par effacer tous les div surgissants
    $$('.contact_surgissant').each(function(div){
	    div.hide();
	});
   
    var position = 0;
    
    // le div ou le h1 où l'internaute clique
    var container_div = Event.findElement(event,'div');
    
    // Sa position parmi les autres div cliquables
    $$('.lien_contact,.title1_contact,.title1_contact1').each(function(div){
	    //alert(Object.inspect(div));
	    if (div === container_div) position = cpt;
	    cpt++;
	});
    cpt = 0;
    $$('.contact_surgissant').each(function(div){
	    if (cpt == position) {

		div.style.position="absolute";
		//-- position de l'objet sur lequel on clique
		initial_position = Element.positionedOffset(container_div);
 
		div.style.left="55%";
    top_div_surgissant = 0;
    if(initial_position[1] > 600) top_div_surgissant = initial_position[1]-150;
    else top_div_surgissant = initial_position[1];
    div.style.top=top_div_surgissant+"px";  
    //div.style.top=initial_position[1]+"px";  
    div.style.zIndex = 1000;      
		div.show();
        
		//-- Position du div surgissant
		position_div = div.positionedOffset();
		x_img = position_div[0];
		y_img = position_div[1];
					
		//-- largeur du div surgissant :
		var dimensions = div.getDimensions();
		width_div = dimensions.width;
					
		//-- Position de l'image de fermeture
		left_position = width_div-17+"px";
					
		//-- Création  de l'image de fermeture
		var img_vide = new Element('img', { 'class': 'fermeture', src: 'Local/icons/menu-close.gif', width:'7', height:'7'});
        
		//-- Fermeture du div surgissant au click sur l'image vide
		Event.observe(img_vide,'click', cacheDiv);
        
		//-- Insertion de l'image vide, positionnement et affichage
		div.insert(img_vide);
		img_vide.style.position="absolute"; 		
		img_vide.style.left=left_position;  
		img_vide.style.top="0px"; 
		img_vide.show();  
	    }
	    cpt ++;
	});
    cpt = 0;
 
}
function cacheDiv(event){
    var div_surgissant = Event.findElement(event,'div');
    div_surgissant.hide();
}

