function ouvre_projet(id_onglet, projet, tab_images){
	
	div_onglet = "#"+id_onglet;
	
	$(div_onglet).unbind();
	$("#cache_blanc").unbind();
	
	
	//on affiche des "hand" sur nos images
	$(".onglets_links").removeClass("moveable_link");
	$(".onglets_links").addClass("clickable_link");
	
	affiche_infos(projet);
	
	//$(div_onglet).unbind("mouseout", mouseout_funcs[id_onglet]);
	//on ne déclenche la fonction que si easydrag a fini le drag (cf. fichier easydrag.js)
	if(window.drag_fini){
		
		window.drag_possible = false;

		window.max_z_index ++;
		max_z = window.max_z_index;
		//on affiche le cache_blanc
		$("#cache_blanc").css({"z-index":max_z});
		$("#cache_blanc").show().fadeTo("normal", 0.8);

		window.max_z_index ++;
		max_z = window.max_z_index;
		$(div_onglet).css({"z-index":max_z});
	
		//on enlève toutes les fonctions de notre onglet (elles sont enregistrées dans les tableaux globaux
		//contenant les fonctions (window.click_funcs, ...))
		$(div_onglet).unbind();
		$(div_onglet).unbind("click", click_funcs[id_onglet]);
		$(div_onglet).unbind("mouseover", mouseover_funcs[id_onglet]);
		$(div_onglet).unbind("mouseout", mouseout_funcs[id_onglet]);
		
		setTimeout(function () {enleve_fonctions(div_onglet, id_onglet)}, 200);
		setTimeout(function () {enleve_fonctions(div_onglet, id_onglet)}, 600);
		//setTimeout(function () {met_fermeture(div_onglet)}, 700);
	
		//on enregistre d'abord les infos à récupérer lorsque l'on va fermer
	
		window.x_temp = $(div_onglet).css("left");
		window.y_temp = $(div_onglet).css("top");
		window.id_en_cours = id_onglet;
		window.projet_en_cours = projet;
	
	
	
		img_src = $(div_onglet+" > img").attr("src");
		//on dit (pour safari) que l'image est bien chargée
		window.tab_img_chargees[img_src] = true;
		var width = get_img_width_onglet(img_src);
		//var width = get_img_width_bis(div_onglet);
		var height = get_img_height_onglet(img_src);
		//var height = get_img_height_bis(div_onglet);
		setTimeout(function () {
		$(div_onglet).animate({left:24, top:148});
	
		$(div_onglet+" > img").animate({"width":width, "height":height}, function () {
			$("#cache_blanc").bind("click", function(){ferme_projet(window.id_en_cours, window.projet_en_cours); });
			//setTimeout(function (){met_fermeture(div_onglet)}, 200);
			setTimeout(function(){met_click_suiv(div_onglet, id_onglet, projet, tab_images)}, 200);
		})
		}, 100)//setTimeout
	
		//on affiche les liens
		
	
		
			var html_string = "<div class='info_rouge'>Planches</div><div id='planches' class='info_noire'>&nbsp;";
			var i_ancienne_image = window.tab_images_en_cours[id_onglet];
			for (var i=1; i<window.tab_toutes_images[tab_images].length+1; i++){
				
				var img_src = window.tab_toutes_images[tab_images][i-1];
			
				if (id_onglet == "nor_txt_a" && i == 1){j = "contacts -"; }
				else if (id_onglet == "nor_txt_a" && i == 2){j = "nor -";}
				else if (id_onglet == "nor_txt_a" && i== 3){j = "news";}
				else {j=i;}
				//on cree nos fiches derrière notre fiche actuelle
				html_string += "<a";
				if (window.tab_images_en_cours[id_onglet] == i){html_string += " class='croix_menu select'"}
				else{html_string += " class='croix_menu non_select'"}
				html_string += " id='"+id_onglet+"_"+i+"' href='#' onclick=\"change_image('"+id_onglet+"','"+i+"','"+i_ancienne_image+"',  '"+img_src+"')\">"+j+"</a>&nbsp;";
			}
			html_string += "- <a class='croix_lien' href='#' id='croix' onclick=\"ferme_projet('"+id_onglet+"', '"+projet+"')\">X</a></div>";
		
		
		$("#planches_bloc").html(html_string);
		
		
		
	}//if window.drag_fini
}

function image_suivante(div_onglet, id_onglet, projet, tab_images){
	var num_ancienne_img = tab_images_en_cours[id_onglet];
	if ((window.tab_images_en_cours[id_onglet] + 1) > window.tab_toutes_images[tab_images].length){
		window.tab_images_en_cours[id_onglet] = 1;
	}
	else {
		window.tab_images_en_cours[id_onglet] += 1;
	}
	
	var img_src = window.tab_toutes_images[tab_images][window.tab_images_en_cours[id_onglet] -1];
	change_image(id_onglet, window.tab_images_en_cours[id_onglet], num_ancienne_img, img_src)
	
	$(div_onglet).unbind("click", click_funcs[window.id_onglet]);
	//var img_src = window.tab_toutes_images[tab_images][i-1];
	
}

function enleve_fonctions (div_onglet, id_onglet) {
		$(div_onglet).unbind();
		//on enlève toutes les fonctions de notre onglet (elles sont enregistrées dans les tableaux globaux
		//contenant les fonctions (window.click_funcs, ...))
		$(div_onglet).unbind("click", click_funcs[id_onglet]);
		$(div_onglet).unbind("mouseover", mouseover_funcs[id_onglet]);
		$(div_onglet).unbind("mouseout", mouseout_funcs[id_onglet]);

}
function met_fermeture(div_onglet){
//	$(div_onglet).bind("click", ferme_click_funcs[id_onglet])
}

function met_click_suiv(div_onglet, id_onglet, projet, tab_images){
	//console.log("div_onglet : "+div_onglet+" - projet :"+projet+"  - tab_images :"+tab_images+" - tab_images.length : "+tab_images.length)
	$(div_onglet).unbind("click", click_funcs[id_onglet]);
	$(div_onglet).bind("click", function(){image_suivante(div_onglet, id_onglet, projet, tab_images)});
}

function enleve_fermeture(div_onglet, id_onglet){
	//$(div_onglet).unbind("click", ferme_click_funcs[id_onglet])
}

function drag_fini_func(){
	window.drag_fini = true;
	$('#'+window.id_onglet).bind("click", window.click_funcs[window.id_onglet]);
	$('#'+window.id_onglet).bind("mouseover", window.mouseover_funcs[window.id_onglet]);
}
function enleve_cache_blanc(){
	$("#cache_blanc").fadeTo("normal", 0, function(){$("#cache_blanc").hide();})
}

function ferme_projet(id_onglet, projet){
	$("#cache_blanc").unbind();
	$(div_onglet).unbind();
	
	window.projet_en_cours = "";
	window.id_onglet_drag_en_cours = "";
	
	
	//on affiche des "move" sur nos images
	$(".onglets_links").removeClass("clickable_link");
	$(".onglets_links").addClass("moveable_link");
	
	//................
	//on elnlève image_suivante qui empeche de rouvrir une image
	$(div_onglet).unbind();
	
	
	window.drag_possible = true;
	//on vide les rubriques
	mouseout_func();
	
	div_onglet = "#"+id_onglet;
	
	enleve_cache_blanc();
	//on enlève les liens des images
	$("#planches_bloc").html("");
	var img_src = $(div_onglet+" > img").attr("src");
	var width_mini = Math.round(get_img_width(img_src)/4);
	var height_mini = Math.round(get_img_height(img_src)/4);
	
	$(div_onglet).animate({left:window.x_temp, top:window.y_temp});
	
	
	
	$(div_onglet).unbind();
	$(div_onglet+" > img").animate({"width":width_mini, "height":height_mini}, function () {remet_fonctions(id_onglet)});
	var tab = [25, 150, 940, 600];
	window.x_temp = 230; window.y_temp = 230;
}

function remettre(div_onglet, id_onglet){
	$(div_onglet).bind("click", window.click_funcs[id_onglet]);
	$(div_onglet).bind("mouseover", window.mouseover_funcs[id_onglet]);
	$(div_onglet).bind("mouseout", window.mouseout_funcs[id_onglet]);
	$(div_onglet).easydrag(id_onglet);
	
}

function remet_fonctions(id_onglet){

	var div_onglet = "#"+id_onglet;
	$(div_onglet).unbind();
	//on remet les fonctions à notre onglet grace à nos tableaux de fonctions globaux
	$(div_onglet).bind("click", window.click_funcs[id_onglet]);
	$(div_onglet).bind("mouseover", window.mouseover_funcs[id_onglet]);
	$(div_onglet).bind("mouseout", window.mouseout_funcs[id_onglet]);
	$(div_onglet).easydrag(id_onglet);
	
	setTimeout(function (){$(div_onglet).unbind(); remettre(div_onglet, id_onglet)}, 100);	
	setTimeout(function (){$(div_onglet).unbind(); remettre(div_onglet, id_onglet)}, 300);
	setTimeout(function (){$(div_onglet).unbind(); remettre(div_onglet, id_onglet)}, 500);
}

function get_img_width_onglet(img_src){
	window.new_img = new Image();
	window.new_img.src = img_src;
	var width = new_img.width;
	return width;
}
function get_img_height_bis(div_onglet){
	var height_bis = $(div_onglet+" > img").height;
	return height_bis;
}

function get_img_width_bis(div_onglet){
	var width_bis = $(div_onglet+" > img").width;
	return width_bis;
}

function get_img_height_onglet(img_src){
	var new_img = new Image();
	new_img.src = img_src;
	var height = new_img.height;
	return height;
}

function get_img_width(img_src){
	window.new_img = new Image();
	window.new_img.src = img_src;
	var width = new_img.width;
	return width;
}

function get_img_height(img_src){
	var new_img = new Image();
	new_img.src = img_src;
	window.new_img.onload = function (){taille_image(img_src)};
	if (window.tab_img_chargees[img_src]){
		taille_image(img_src);
	}
	var height = new_img.height;
	return height;
	
}

function taille_image(img_src){
	//window.img_src_dernierement_chargee;
	//window.img_a_charger_ok = true;
	window.tab_img_chargees[img_src] = true;
	
	
	div_en_cours = "#"+window.id_en_cours;
	width = window.new_img.width;
	height = window.new_img.height;
	$(div_en_cours+" > img").attr({"src": window.new_img.src});
	$(div_en_cours+" > img").css({"width":width, "height":height})
}

function change_image(id_div, i, i_ancienne_img, img_src){
	
	
	window.tab_images_en_cours[id_div] = i;
	if (id_div != 'nor'){
		
		//on remet l'ancien lien de l'image selectionnée en noir
		$(".croix_menu").removeClass('select');
		$("#"+id_div+"_"+i_ancienne_img).removeClass('select');
		$("#"+id_div+"_"+i_ancienne_img).addClass('non_select');
		window.tab_images_en_cours[id_div] = i;
		
		$("#"+id_div+"_"+window.tab_images_en_cours[id_div]).removeClass('non_select');
		$("#"+id_div+"_"+window.tab_images_en_cours[id_div]).addClass('select');
	
	
		if(img_src != window.img_src_dernierement_chargee){
			window.img_a_charger_ok = false;
		}
		
		var width = get_img_width(img_src);
		var height = get_img_height(img_src);
	}
	
	else {
		if (i==1){
			$("#nor_1").removeClass('non_select');
			$("#nor_1").addClass('select');
			$("#nor_2").removeClass('select');
			$("#nor_2").addClass('non_select');
		}
		else if (i==2){
			$("#nor_1").removeClass('select');
			$("#nor_1").addClass('non_select');
			$("#nor_2").removeClass('non_select');
			$("#nor_2").addClass('select');
		}
		if(img_src != window.img_src_dernierement_chargee){
			window.img_a_charger_ok = false;
		}
		var width = get_img_width(img_src);
		var height = get_img_height(img_src);
	}
}

function affiche_infos(projet){
	var nom_html = "<span style='font-weight:bold; text-transform:uppercase'>"+$("#"+projet+"_nom").html()+"</span>";
	//on met à jour les textes affichés
	$("#nom").html(nom_html);
	$("#type").html($("#"+projet+"_type").html());
	$("#annee").html($("#"+projet+"_annee").html());
	$("#adresse").html($("#"+projet+"_adresse").html());
	$("#lieu").html($("#"+projet+"_lieu").html());
	$("#txt").html($("#"+projet+"_txt").html());
	
}

function mouseover_func(id_onglet, projet){
	div_onglet = "#"+id_onglet;
	
	affiche_infos(projet);
	
	//on déplace légerement l'onglet
	var rand_plus = Math.floor(Math.random()*8);
	var plus_ou_moins_rand = Math.random();
	if(plus_ou_moins_rand < 0.5){plus_ou_moins = -1;}
	else {plus_ou_moins = 1;}
	left_num = get_left_num(id_onglet);
	if (left_num > 600){
		plus_ou_moins = -1;
	}
	if(left_num < 300){
		plus_ou_moins = 1;
	}
	left_num_but = left_num + plus_ou_moins * rand_plus;
	
	$(div_onglet).animate({left:left_num_but}, 120);
}

function get_left_num(id_element){
	left_value = $("#"+id_element).css("left");
	left_value = left_value.substr(0, left_value.length-2);
	left_num = Number(left_value);
	return left_num;
}

function get_top_num(id_element){
	top_value = $("#"+id_element).css("top");
	top_value = top_value.substr(0, top_value.length-2);
	top_num = Number(top_value);
	return top_num;
}

function get_width_num(id_element){
	width_value = $("#"+id_element).css("width");
	width_value = width_value.substr(0, left_value.length-2);
	width_num = Number(left_value);
	return width_value;
}

function mouseout_func(id_onglet) {
	$("#nom").html("");
	$("#type").html("");
	$("#annee").html("");
	$("#adresse").html("");
	$("#lieu").html("");
	$("#txt").html("");
}

function cache_nor(){
	var rand_left = Math.floor(Math.random()*700)+20;
	var rand_top = 220;//Math.floor(Math.random()*400)+150;
	$("#cache_rouge").animate({left:rand_left, top:rand_top, width:"140px", height:"100px"});
	var tab = [25, 150, 940, 600];
}

function nor_over(){
	$("#nom").html("<b>NOR</b>");
	$("#type").html("Architectes");
	$("#annee").html("");
	$("#adresse").html("");
	$("#lieu").html("");
	var et = "@";
	$("#txt").html("<span style='color:#ff0000;'>Rue du Nord 11<br>CH-1005 Lausann<br>Switzerland<br>t +41 21 31197 58<br>f +41 21 311 89 91<br><a href='mailto:nor"+et+"norarchitectes.ch'>nor"+et+"norarchitectes.ch</a></span>");
}
