/*
 *	Initialisation.
*/
function init(nomdelagalerie) {
	// Préchargement de certaines images.
	var preload = new Array('montrer','cacher','star_demi','star_empty','star_full','igalsprite','igalsprite2','transparent');
	var preloadext = new Array('.gif','.gif','.png','.png','.png','.gif','.gif','.gif');
	document.preload_images = [];
	for (var i = 0; i < preload.length; i++) {
		document.preload_images[i] = new Image();
		document.preload_images[i].src = style_dir + '/' + preload[i] + preloadext[i];
	}
	// quelques modif dans la barre de position
	if($("#position").length>0 && $("#position").html().indexOf("hvc_result")==-1) {
		$("#position a:first").text(nomdelagalerie);
		var reg=new RegExp("(</a> / <a)", "g");
		if($("#position").length>0) {
			$("#position").html($("#position").html().replace(reg,"</a><span class='position-separator'>></span><a"));
		}
	}
	$("#position").show();
	// section image : position de la photo, remplacement de |
	$(".tab-vignette-nav-left-actu").each(function () { $(this).text($(this).text().replace("image","Photos").replace("|"," sur ")); });
	// hover et blur "page actuelle" ex : page1/5
	$(".page_actuelle").hover( function () { $(this).hide().prev().show().children().focus(); }, function () {});
	$(".startnumclass select").blur( function () { $(this).parent().hide().next().show(); });
	// changement des flèches de navigation par des images
	var chaine=' src="'+style_dir+'/transparent.gif" width="';
	var chaine1=chaine+'30" height="19">';
	var chaine2=chaine+'63" height="19">';
	$(".premiere a").html('<img id="ImgIpremiere" class="Ipremiere"'+chaine1);
	$(".precedente a").html('<img id="ImgIprecedente" class="Iprecedente"'+chaine2);
	$(".derniere a").html('<img id="ImgIderniere" class="Iderniere"'+chaine1);
	$(".suivante a").html('<img id="ImgIsuivante" class="Isuivante"'+chaine2);
	$(".premiere.inactive").html('<img class="Ipremiere-inactive"'+chaine1);
	$(".precedente.inactive").html('<img class="Iprecedente-inactive"'+chaine2);
	$(".derniere.inactive").html('<img class="Iderniere-inactive"'+chaine1);
	$(".suivante.inactive").html('<img class="Isuivante-inactive"'+chaine2);
	$(".tab-vignette-nav td.tab-vignette-nav-center span").show();
	// donne l'effet 'bouton' a ces images + celles du zoom
	$(".Ipremiere,.Iprecedente,.Iderniere,.Isuivante").mousedown(function(){
		switch(this.id) {
			case 'ImgIpremiere': $(this).css("background-position","-189px -38px"); break;
			case 'ImgIprecedente': $(this).css("background-position","-189px 0px"); break;
			case 'ImgIderniere': $(this).css("background-position","-222px -38px"); break;
			case 'ImgIsuivante': $(this).css("background-position","-189px -19px"); break;
		}
	});
	// remplacement de caracteres dans le nombre d'images recentes
	$(".img_recentes").each(function () { $(this).html($(this).html().replace("[","").replace("]","")); });
	// Le menu principal
	$('#MenuMain').menu(
		{minWidth: 150, arrowSrc: 'arrow_right.gif', onClick: function(e, menuItem){  
		var rapport=$("#img").width()/$("#img").height();
		switch ($(this).find("span").attr("id")) {
			case "MenuMainViewComments" : AffichageContenuMenu(1,rapport); break;
			case "MenuMainAddComments" : AffichageContenuMenu(2,rapport); break;
			case "MenuMainViewExif" : AffichageContenuMenu(3,rapport); break;
			case "MenuMainViewIptc" : AffichageContenuMenu(4,rapport); break;
		}
		$.Menu.closeAll();
		$("#MenuopenContenu-AffichageNormal").click( function () { AffichageNormal(); });
	}});
	// correction de la css hover des LI du menu pour IE
	if($.browser.msie) {
		$("li.menumain").hover(
		  function () { $(this).css("border","1px solid #3964C2"); }, 
		  function () {	$(this).css("border","1px solid #fff"); }
    	);
	}
	// vide le dossier des albums a telecharger si ce dernier est operationnel (_param.php)
	if(VIEW_DOWNLOAD_ALB=="1") { DownloadAlbumReset(); }
	// corrige la classe de l'onglet historique impossible a recuperer dans le header
	$(".HeaderTable-tab-active #historique_lien a").addClass("tabactive");
	// remplace les images de type "video" par le lecteur
	if(VIEW_VIDEO=="1" && $("#image_r").length>0 && $("#image_r").html().indexOf("_video.")!=-1) {
		$("#img").hide();
		//var prechemin=$("#nomfichierimage").val().split("?i=");
		var prechemin=$("#nomfichierimage").val().replace(".jpg",".flv").replace(".JPG",".flv");
		//chemin=prechemin[1].split("_video.");
		var code2insert2="<p id='preview'>Si vous ne voyez pas la video, vous avez un probleme avec votre plugin flash !</p>";
		code2insert2+="<script type='text/javascript' src='"+galerie_path+"/template/picasa2/flvplayer/swfobject.js'></script>";
		code2insert2+="<script type='text/javascript'>";
		code2insert2+="var s1 = new SWFObject('"+galerie_path+"/template/picasa2/flvplayer/player.swf','player','470','320','9','#ffffff');";
		code2insert2+="s1.addParam('allowfullscreen','true');";
		code2insert2+="s1.addParam('allowscriptaccess','always');";
		code2insert2+="s1.addParam('wmode','opaque');";
		//code2insert2+="s1.addParam('flashvars','file="+galerie_path+"/albums/"+chemin[0]+"_video.flv&autostart=true&controlbar=over&stretching=none');";
		code2insert2+="s1.addParam('flashvars','file="+prechemin+"&autostart=true&controlbar=over&stretching=none');";
		code2insert2+="s1.write('preview');";
		code2insert2+="</script>";
		$("#img").after("<div id='videodiv'></div>");
		$("#videodiv").html(code2insert2);
		ViewVideo=1;
	} else {
		ViewVideo=0;	
	}
	// effet de 'clic' sur certain bouton et evenement CLIC sur la rotation
	$("#ImgRotateRight,#ImgRotateLeft,#ImgFav,#rechercheav").mousedown(function(){
		if(this.id=="ImgRotateRight") {$(this).css("background-position","-189px -76px");}
		if(this.id=="ImgRotateLeft") {$(this).css("background-position","-226px -76px");}
		if(this.id=="ImgFav") {$(this).css("background-position","-126px -76px");}
		if(this.id=="rechercheav") {$(this).css("background-position","-238px -151px");}
	}).mouseup(function(){
		if(this.id=="ImgRotateRight") {$(this).css("background-position","-63px -76px");}
		if(this.id=="ImgRotateLeft") {$(this).css("background-position","-100px -76px");}
		if(this.id=="ImgFav") {$(this).css("background-position","-152px -57px");}
		if(this.id=="rechercheav") {$(this).css("background-position","-238px -137px");}
	}).click(function(){
		if(this.id=="ImgRotateRight") {$("#img").rotateLeft();}
		if(this.id=="ImgRotateLeft") {$("#img").rotateRight();}
		autoResize();
	});
	// divers	
	$('#igalerie').css('height','');
	autoResize();
	if (typeof preview == 'number') { $('#comment').focus(); }
	$('#adv_search_stext').focus();
	$('#section_pass').focus();
	// Gestion des notes
	vote();
}
/*
  * Gestion des actions menus
*/
function DownloadAlbum(id) {
	$.post(galerie_path+"/template/picasa2/download.php", { dwlalb: id }, function(data){
  		if(data.indexOf('Error')!=-1) {
			alert("Erreur dans la création du ZIP !");
		} else {
			$("#albtodwl a").attr('href',galerie_path+"/template/picasa2/"+data);
			$("#albtodwl").show();
			AddRecent(1);
		}
	});
}
function DownloadAlbumReset() { $.post(galerie_path+"/template/picasa2/download.php", { resetalb: 1 });	}
function AffichageNormal() {
	$("#MenuopenContenu").hide();
	$("#MenuOpenImage, #MenuOpenInfos").empty();
	$(".tab-vignette-nav,#image_note,#image_description,#image_tags,.infos_imeta,#img,#commentaires").show();
	ViewInfosMenu=0;
	if(ViewVideo==1) {$("#videodiv").show();$("#img").hide();}
}
function AffichageContenuMenu(nummenu,rapport) {
	// si c'est une video qu'on lit en ce moment, on la cache
	if(ViewVideo==1) {$("#videodiv").hide();}
	// quelque soit le menu on effectue :
	$(".tab-vignette-nav,#image_note,#image_description,#image_tags,.infos_imeta,#commentaires").hide();				
	$("#MenuopenContenu").show();
	if(ViewInfosMenu==0) {
		$("#img").hide();
		$("#img").clone().appendTo("#MenuOpenImage").animate({ width: "100px", height: 100/rapport+"px"	}, 500 );
	}		
	switch(nummenu) {
		case 1:
			ViewInfosMenu = 1;
			$("#MenuOpenInfos").empty();
			$(".comment").clone().appendTo("#MenuOpenInfos").children(".comment p").each(function () {
				if($(this).hasClass("comment_auteur")) {$(this).css("margin","0px");}
				if($(this).hasClass("comment_num")) {$(this).css("margin-right","0px");}
				if($(this).hasClass("comment_message")) {$(this).css("margin","10px 0 10px");}
			});
			$(".comment:first").css("margin-top","15px");
			$("#comment_null").clone().appendTo("#MenuOpenInfos").html("Aucun commentaire.<br /><a href='javascript:void(0);' onclick='AffichageContenuMenu(2,"+rapport+")'>Ajouter un commentaire</a>");
			break;
		case 2:
			ViewInfosMenu = 2;
			$("#MenuOpenInfos").empty();
			$("#commentaires_ajout").clone().appendTo("#MenuOpenInfos").show();
			break;
		case 3:
			ViewInfosMenu = 3;
			$("#MenuOpenInfos").empty();
			$("#partie_exif").clone().appendTo("#MenuOpenInfos").show();
			break;
		case 4:
			ViewInfosMenu = 4;
			$("#MenuOpenInfos").empty();
			$("#partie_iptc").clone().appendTo("#MenuOpenInfos").show();
			break;
	}
}
/*
  *	Utilisateurs : upload.
*/
function display_upload(n) {
	if ($("#"+n).css('display') == 'block') {
		$("#"+n).hide();
	} else {
		$("#"+n).show().focus();
	}
}
/*
  * Toggle des description
*/
function ToggleDescription() { $(".DescriptionClass p,.DisplayDescriptionLink").toggle(); }
/*
 *	Vote utilisateur.
*/
var stars, stars_defaut, http;
function vote() {
	if (document.getElementById('image') && document.getElementById('note_user')) {
		stars = document.getElementById('note_user').getElementsByTagName('img');
		stars_defaut = [];
		for (var i = 0; i < stars.length; i++) {
			stars_defaut[i] = stars[i].src;
			stars[i].setAttribute('cssText', '');
			stars[i].setAttribute('id', 'star_' + (i+1));
			stars[i].onmouseover = function() { starOver(this); };
			stars[i].onmouseout = function() { starOut(this); };
			stars[i].onclick = function() { starClick(this); };
		}
	}
}
function starOver(star) {
	for (var i = 0; i < 5; i++) { stars[i].src = stars[i].src.replace(/full/, 'empty'); }
	var id = star.id.replace(/star_/, '');
	for (var i = 0; i < id; i++) { stars[i].src = stars[i].src.replace(/empty/, 'full'); }
	star.style.cursor = 'pointer';
}
function starOut(star) {
	var id = star.id.replace(/star_/, '');
	for (var i = 0; i < 5; i++) { stars[i].src = stars_defaut[i]; }
}
function starClick(star) {
	for (var i = 0; i < 5; i++) { stars_defaut[i] = stars[i].src; }
	var note = star.id.replace(/star_/, '');
	var retour = 'note moyenne :<span id="note_stars">!</span><span>(! - !)</span>';
	$.ajax({
		type: "POST",
		url: galerie_path + "/vote.php",
		data: 'note=' + note + '&img=' + image_id + '&retour=' + retour + '&styledir=' + style_dir,
		success: function(msg){ $('#stats_note').html(msg); },
		error: function(msgerr){ alert('Votre vote n\'a pas été pris en compte car une erreur s\'est produite.\n'+msgerr); }
   });
}
/*
 *	Redimensionnement de l'image.
*/
var auto_resize,img_auto_resize,img_width,img_height,img_space,
    img_ratio,fixed_width,fixed_height,ilar;
function autoAjust() {
	if (auto_resize) {
		var img = document.getElementById('img');
		if (img) {
			autoResizeImage(img);
			autoResizeImage(img);
		}
		imageResizeMessage(img);
	}
}
function imageResize(img) {
	autoResizeValues();
	var body_width = document.body.offsetWidth;
	var largeur = img.width + img_space;
	if (largeur > body_width) {
		img.width = img.width - (largeur - body_width);
	}
	if (img.width > img_width) {
		img_auto_resize = 0;
		autoResizeImage(img);
		img_auto_resize = 1;
	}
	img.height = img.width / img_ratio;
}
function autoResizeValues() {
	var img = document.getElementById('img');
	var img_pos_left = getPageOffsetLeft(img);
	var page_width = document.getElementById('ensemble').offsetWidth;
	var img_pos_right = page_width - img_pos_left - img.width;
	img_space = img_pos_left + img_pos_right;
}
function getPageOffsetLeft(el) {
	return el.offsetLeft + (el.offsetParent ? getPageOffsetLeft(el.offsetParent) : 0);
}
function autoResize() {
	var image_r = document.getElementById('image_r');
	if (!image_r || (navigator.userAgent.search(/Gecko/) == -1 && img_auto_resize == 2) || img_gd_resize) {
		return;
	}
	var img = image_r.getElementsByTagName('img')[0];
	if (img) {
		if (!ilar) {
			ilar = (img_auto_resize) ? 1 : 2;
		}
		img_ratio = img_width / img_height;
		if (img_auto_resize) {
			auto_resize = 1;
			imageResizeMessage(img);
			autoResizeValues();
			img_auto_resize = (img_auto_resize == 2) ? 1 : 0;
		} else {
			auto_resize = 0;
			fixed_width = img.width;
			fixed_height = img.height;
			imageResizeMessage(img);
		}
		$(".ImgZoom").click(function () { autoResizeImage(img); });
		$("#ImgZoomPlusId").mousedown(function(){ $(this).css("background-position","-189px -57px"); });
		$("#ImgZoomMoinsId").mousedown(function(){ $(this).css("background-position","-226px -57px"); });

	}
	window.onresize = autoAjust;
}
function imageResizeMessage(img) {
	var msg = document.getElementById('image_r_msg');
	var e = document.getElementById('ensemble');
	if (img.width == img_width) {
		$('#image_r_msg').html('<img src="'+style_dir+'/transparent.gif" width="10" height="19" />');
		$('#image_r_msg').html('');
		img.setAttribute('title', '');
		e.style.width = '';
	} else {
		$('#image_r_msg').html('<img id="ImgZoomPlusId" class="ImgZoom" src="'+style_dir+'/transparent.gif" width="26" height="19" /><img id="ImgZoomMoinsId" class="ImgZoom" src="'+style_dir+'/transparent.gif" width="26" height="19" />');
		$("#ImgZoomPlusId").show();
		$("#ImgZoomMoinsId").hide();
		$('#image_r_msg').show();
		if (ilar < 2) {
			e.style.width = document.body.offsetWidth + 'px';
		}
	}
}
function autoResizeImage(img) {
	if (auto_resize) {
		if (img_auto_resize) {
			imageResize(img);
			img_auto_resize = 0;
		} else {
			img.width = img_width;
			img.height = img_height;
			img.setAttribute('style', '');
			img_auto_resize = 1;
		}
		imageResizeMessage(img);
	} else {
		if (img_auto_resize) {
			img_auto_resize = 0;
			img.width = fixed_width;
			img.height = fixed_height;
			imageResizeMessage(img);
		} else {
			img_auto_resize = 1;
			img.width = img_width;
			img.height = img_height;
			imageResizeMessage(img);
			$('#image_r_msg').html('<img id="ImgZoomPlusId" class="ImgZoom" src="'+style_dir+'/transparent.gif" width="26" height="19" /><img id="ImgZoomMoinsId" class="ImgZoom" src="'+style_dir+'/transparent.gif" width="26" height="19" />');
			$("#ImgZoomMoinsId").show();
			$("#ImgZoomPlusId").hide();
			$('#image_r_msg').show();
		}
	}
	$(".ImgZoom").click(function () { autoResizeImage(img); });
	$("#ImgZoomPlusId").mousedown(function(){ $(this).css("background-position","-189px -57px"); });
	$("#ImgZoomMoinsId").mousedown(function(){ $(this).css("background-position","-226px -57px"); });
}
/*
 *	Vérification des formulaires.
*/
function comment_verif(f) {
	var aut = f.elements.auteur.value;
	var msg = f.elements.message.value;
	if (aut.search(/^\W*$/gi) == -1) {
		if (msg.search(/^\s*$/gi) == -1) {
			return true;
		} else {
			alert('Votre message est vide !');
			f.elements.message.focus();
			return false;
		}
	} else {
		alert('Vous devez entrer votre nom ou un pseudo.');
		f.elements.auteur.focus();
		return false;
	}
}
function advsearch_verif(f) {
	if (document.getElementById('adv_search_taille') &&
		document.getElementById('adv_search_poids') &&
		document.getElementById('adv_search_width_start') &&
	    document.getElementById('adv_search_width_end') &&
		document.getElementById('adv_search_height_start') &&
		document.getElementById('adv_search_height_end') &&
		document.getElementById('adv_search_poids_start') &&
		document.getElementById('adv_search_poids_end')) {
		if (document.getElementById('adv_search_taille').checked == true) {
			if (document.getElementById('adv_search_width_start').value.search(/^\d{0,6}$/) == -1 ||
			    document.getElementById('adv_search_width_end').value.search(/^\d{0,6}$/) == -1 ||
				document.getElementById('adv_search_height_start').value.search(/^\d{0,6}$/) == -1 ||
				document.getElementById('adv_search_height_end').value.search(/^\d{0,6}$/) == -1) {
				alert('Vous devez entrer un nombre entier pour les limites de dimensions.');
				return false;
			}
		}
		if (document.getElementById('adv_search_poids').checked == true) {
			if (document.getElementById('adv_search_poids_start').value.search(/^\d{1,12}(\.\d{1,6})?$/) == -1 ||
				document.getElementById('adv_search_poids_end').value.search(/^\d{1,12}(\.\d{1,6})?$/) == -1) {
				alert('Vous devez entrer un nombre pour les limites de poids.');
				return false;
			}
		}
		return true;
	}
}
function perso_verif(f) {
	if (f.elements.it && f.elements.it[1].checked == true) {
		var il = f.elements.il.value;
		var ih = f.elements.ih.value;
		if (il.search(/^[\d]{2,}$/gi) != -1) {
			if (ih.search(/^[\d]{2,}$/gi) != -1) {
				return true;
			} else {
				alert('Vous devez entrer un entier supérieur à 9 comme hauteur maximale.');
				f.elements.ih.focus();
				return false;
			}
		} else {
			alert('Vous devez entrer un entier supérieur à 9 comme largeur maximale.');
			f.elements.il.focus();
			return false;
		}
	}
	if (f.elements.ra && f.elements.ra.checked == true) {
		var rj = f.elements.rj.value;
		if (rj.search(/^[\d]+$/gi) != -1) {
			return true;
		} else {
			alert('Vous devez entrer un entier pour le nombre de jours.');
			f.elements.rj.focus();
			return false;
		}
	}
}
/*
 *	Parties repliables.
*/
var parties = [];
parties['navigation'] = -1;
parties['hasard'] = -1;
parties['perso'] = -1;
parties['stats'] = -1;
parties['tags'] = -1;
parties['liens'] = -1;
parties['exif'] = -1;
parties['iptc'] = -1;
parties['comments'] = -1;
parties['enlarge'] = -1;
parties['membres'] = -1;
var titles = [];
titles['navigation'] = []; titles['navigation']['m'] = 'Montrer la géolocalisation'; titles['navigation']['c'] = 'Cacher la géolocalisation';
titles['hasard'] = []; titles['hasard']['m'] = 'Montrer une image choisie au hasard'; titles['hasard']['c'] = 'Cacher une image choisie au hasard';
titles['perso'] = []; titles['perso']['m'] = 'Montrer les options de personnalisation'; titles['perso']['c'] = 'Cacher les options de personnalisation';
titles['stats'] = []; titles['stats']['m'] = 'Montrer les statistiques'; titles['stats']['c'] = 'Cacher les statistiques';
titles['membres'] = []; titles['membres']['m'] = 'Montrer la partie membre'; titles['membres']['c'] = 'Cacher la partie membre';
titles['tags'] = []; titles['tags']['m'] = 'Montrer les tags'; titles['tags']['c'] = 'Cacher les tags';
titles['liens'] = []; titles['liens']['m'] = 'Montrer les liens'; titles['liens']['c'] = 'Cacher les liens';
titles['exif'] = []; titles['exif']['m'] = 'Montrer les informations Exif'; titles['exif']['c'] = 'Cacher les informations Exif';
titles['iptc'] = []; titles['iptc']['m'] = 'Montrer les informations IPTC'; titles['iptc']['c'] = 'Cacher les informations IPTC';
titles['comments'] = []; titles['comments']['m'] = 'Montrer les commentaires'; titles['comments']['c'] = 'Cacher les commentaires';
titles['enlarge'] = []; titles['enlarge']['m'] = 'Montrer la sidebar'; titles['enlarge']['c'] = 'Cacher la sidebar';
var gpj = GetCookie('galerie_perso_js');
if (gpj) { gpj = gpj.split(''); }
function cacher_montrer(p) {
	if (p == 'enlarge') {
		if (parties[p] == -1) {
			parties[p] = ($("#enlarge_icon").hasClass("enlarge_opened")==true) ? 1 : 0;
			$("#enlarge").attr('href','javascript:void(0);');
		}
		if (parties[p]==1) {
			$("#enlarge img").attr("alt",titles[p]['m']);
			$("#enlarge").attr("title",titles[p]['m']);
			parties[p] = 0;
		} else {
			$("#enlarge img").attr("alt",titles[p]['c']);
			$("#enlarge").attr("title",titles[p]['c']);
			parties[p] = 1;
		}
		$("#div_panneau_1").toggle(500);
		setTimeout("AddRecent()",600);
		$("#enlarge_icon").toggleClass("enlarge_opened").toggleClass("enlarge_closed");
		$("#enlarge").blur();
		autoAjust();
	} else { 
		if (parties[p] == -1) {
			parties[p] = ($('#red_' + p).hasClass("cacher") == true) ? 1 : 0;
			$('#ldp_' + p).attr('href','javascript:void(0);');
		}
		if (parties[p]) {
			$("#partie_"+p).slideUp().parent().animate({ marginTop: "0px" }, 300 );
			if (p == 'comments') { $('#commentaires_ajout').hide(); }
			$('#red_' + p).removeClass("cacher").addClass("montrer");
			$('#ldp_' + p).attr('title',titles[p]['m']);
			parties[p] = 0;
		} else {
			$("#partie_"+p).slideDown().parent().animate({ marginTop: "10px" }, 300 );
			if (p == 'comments') { $('#commentaires_ajout').show(); }
			$('#red_' + p).removeClass("montrer").addClass("cacher");
			$('#ldp_' + p).attr('title',titles[p]['c']);
			parties[p] = 1;
		}
		$("#ldp_"+p).blur();
	}
	saveDisplay();
}
function saveDisplay() {
	var date = new Date;
	date.setFullYear(date.getFullYear()+10);
	var n = document.getElementById('red_navigation');
	if (n) { var i0 = (n.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i0 = gpj[0]; } else { var i0 = '2'; }
	var h = document.getElementById('red_hasard');
	if (h) { var i1 = (h.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i1 = gpj[1]; } else { var i1 = '2'; }
	var p = document.getElementById('red_perso');
	if (p) { var i2 = (p.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i2 = gpj[2]; } else { var i2 = '2'; }
	var s = document.getElementById('red_stats');
	if (s) { var i3 = (s.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i3 = gpj[3]; } else { var i3 = '2'; }
	var t = document.getElementById('red_tags');
	if (t) { var i4 = (t.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i4 = gpj[4]; } else { var i4 = '2'; }
	var c = document.getElementById('red_comments');
	if (c) { var i5 = (c.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i5 = gpj[5]; } else { var i5 = '2'; }
	var e = document.getElementById('enlarge');
	if (e) { var i6 = ($("#enlarge img").hasClass("enlarge_opened")==true) ? '1' : '0'; } else if (gpj) { var i6 = gpj[6]; } else { var i6 = '2'; }
	var x = document.getElementById('red_exif');
	if (x) { var i7 = (x.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i7 = gpj[7]; } else { var i7 = '2'; }
	var l = document.getElementById('red_liens');
	if (l) { var i8 = (l.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i8 = gpj[8]; } else { var i8 = '2'; }
	var i = document.getElementById('red_iptc');
	if (i) { var i9 = (i.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i9 = gpj[9]; } else { var i9 = '2'; }
	var m = document.getElementById('red_membres');
	if (m) { var i10 = (m.className.search(/cacher/gi) != -1) ? '1' : '0'; } else if (gpj) { var i10 = gpj[10]; } else { var i10 = '2'; }
	var path = (galerie_path == '/') ? '/' : galerie_path + '/';
	SetCookie('galerie_perso_js', i0+i1+i2+i3+i4+i5+i6+i7+i8+i9+i10, date, path);
}
function initDisplay() {
	if (gpj) {
		gpj[0] = (gpj[0]) ? gpj[0] : '2';
		gpj[1] = (gpj[1]) ? gpj[1] : '2';
		gpj[2] = (gpj[2]) ? gpj[2] : '2';
		gpj[3] = (gpj[3]) ? gpj[3] : '2';
		gpj[4] = (gpj[4]) ? gpj[4] : '2';
		gpj[5] = (gpj[5]) ? gpj[5] : '2';
		gpj[6] = (gpj[6]) ? gpj[6] : '2';
		gpj[7] = (gpj[7]) ? gpj[7] : '2';
		gpj[8] = (gpj[8]) ? gpj[8] : '2';
		gpj[9] = (gpj[9]) ? gpj[9] : '2';
		gpj[10] = (gpj[10]) ? gpj[10] : '2';
		affichageParties('navigation', gpj[0], titles['navigation']['m'], titles['navigation']['c']);
		affichageParties('hasard', gpj[1], titles['hasard']['m'], titles['hasard']['c']);
		affichageParties('perso', gpj[2], titles['perso']['m'], titles['perso']['c']);
		affichageParties('stats', gpj[3], titles['stats']['m'], titles['stats']['c']);
		affichageParties('tags', gpj[4], titles['tags']['m'], titles['tags']['c']);
		affichageParties('comments', gpj[5], titles['comments']['m'], titles['comments']['c']);
		affichageParties('exif', gpj[7], titles['exif']['m'], titles['exif']['c']);
		affichageParties('liens', gpj[8], titles['liens']['m'], titles['liens']['c']);
		affichageParties('iptc', gpj[9], titles['iptc']['m'], titles['iptc']['c']);
		affichageParties('membres', gpj[10], titles['membres']['m'], titles['membres']['c']);
		if (gpj[6] == '0') {
			$('#div_panneau_1').hide();
			$('#enlarge_icon').removeClass("enlarge_opened").addClass("enlarge_closed").parent().attr("title",titles['enlarge']['m']);
		} else if (gpj[6] == '1') {
			$('#div_panneau_1').show();
			$('#enlarge').attr("title",titles['enlarge']['c']);
		}
	} else {
		// affichage par defaut si pas de cookie 
		affichageParties('navigation', 1, titles['navigation']['m'], titles['navigation']['c']);
		affichageParties('hasard', 1, titles['hasard']['m'], titles['hasard']['c']);
		affichageParties('perso', 0, titles['perso']['m'], titles['perso']['c']);
		affichageParties('stats', 0, titles['stats']['m'], titles['stats']['c']);
		affichageParties('tags', 0, titles['tags']['m'], titles['tags']['c']);
		affichageParties('comments', 0, titles['comments']['m'], titles['comments']['c']);
		affichageParties('exif', 0, titles['exif']['m'], titles['exif']['c']);
		affichageParties('liens', 0, titles['liens']['m'], titles['liens']['c']);
		affichageParties('iptc', 0, titles['iptc']['m'], titles['iptc']['c']);
		affichageParties('membres', 0, titles['membres']['m'], titles['membres']['c']);		
	}
}
function affichageParties(part, e, title_m, title_c) {
	if (e == '0') {
		$('#partie_' + part).hide();
		$('#red_' + part).removeClass("cacher").addClass("montrer");
		$('#ldp_' + part).attr("title",title_m);
	} else if (e == '1') {
		$('#partie_' + part).show();
		$('#red_' + part).removeClass("montrer").addClass("cacher");
		$('#ldp_' + part).attr("title",title_c);
		$("#partie_"+part).parent().css("margin-top","10px");
	}
}
/*
 *	Fonctions de cookies.
*/
//  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
//  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
/*
 *	Geolocalisation
*/
function load(type,idalb,idimg) {
	if (GBrowserIsCompatible()) {
		var AucuneImage=1;
		var AucunAlbum=1;
		var AucuneImgactuelle=1;
		var iJaune = new GIcon(G_DEFAULT_ICON);
		iJaune.image = style_dir+'/mm_20_yellow.png';
		iJaune.shadow = style_dir+'/mm_20_shadow.png';   
		iJaune.iconSize = new GSize(12, 20);   
		iJaune.shadowSize = new GSize(22, 20);   
		iJaune.iconAnchor = new GPoint(6, 20);
		var iVert = new GIcon(G_DEFAULT_ICON);
		iVert.image = style_dir+'/mm_20_green.png';
		iVert.shadow = style_dir+'/mm_20_shadow.png';   
		iVert.iconSize = new GSize(12, 20);   
		iVert.shadowSize = new GSize(22, 20);   
		iVert.iconAnchor = new GPoint(6, 20);
		// pour que la carte se charge correctement elle doit absolument être visible
		var acacher=0;
		if($("#partie_navigation").css("display")=="none") {$("#partie_navigation").show();acacher=1;}	
		$("#map").height(200);
		// on est en version MAX
		if(idalb==0 && idimg==0) {
			var MaxWidth = $("#div_affichage2").width()-20;
			var MaxHeight = MaxWidth*3/4;
			if(MaxHeight>700) {MaxHeight=700;}
			$("#map").height(MaxHeight).width(MaxWidth);
		}

		var map = new GMap2(document.getElementById("map"));
		
		bubble = new EBubble(map, style_dir+"/chrome.png",new GSize(175,150), new GSize(160,120), new GPoint(8,8), new GPoint(98,150),true);
		function createMarker(point,html,icone,lat,lng) {
			if(icone==0) {
				var marker = new GMarker(point);
			} else {
				var marker = new GMarker(point,{ icon:icone });
			}
			// === Open the EBubble instead of an Info Window ===
			GEvent.addListener(marker, "click", function() {
				map.setCenter(new GLatLng(lat,lng));
				map.setCenter(new GLatLng(map.getBounds().getNorthEast().lat(),lng));
				bubble.openOnMarker(marker,html);
				GEvent.addListener(bubble, "click", function() {
					map.setCenter(new GLatLng(lat,lng),15);
				});
				GEvent.addListener(map, "click", function(marker,point) {
					if (point) {
					  bubble.hide();
					}
				});
			});
			return marker;
		}
		
		if(idalb==0 && idimg==0) {
			map.setMapType(G_HYBRID_MAP);     
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(47,0.5),2);
			/*
			$.ajax({ type: "POST",
				url: galerie_path+"/template/picasa2/geoloc.php",
				data: "geolocmax=1&geoloctype="+type+"&geolocidalb="+idalb+"&geolocidimg="+idimg,
				dataType: "json",
				//beforeSend: fonction(),
				success: function(msg){
					for (var i = 0; i < msg.images.length; i++) {
						if(msg.images[i].lat!='') {
							point = new GLatLng(msg.images[i].lat,msg.images[i].lng);
							var html = "<strong>"+msg.images[i].nom+"</strong><br /><em>lieu : </em>"+msg.images[i].lieu+"<br /><a href='javascript:void(0);'>zoomer sur ce lieu</a>";
							var marker = createMarker(point,html,iJaune,msg.images[i].lat,msg.images[i].lng);
							map.addOverlay(marker);
						}
					}
				},// fin success
				error: function(req,str,e){alert('erreur GEOLOCMAX :'+e);}
				//complete: fonction(Type)
			});
			*/
			
			$.post(galerie_path+"/template/picasa2/geoloc.php", { geolocmax: "1" },
			  function(data){
				alert(data);
			});
			

		} else {
			map.setMapType(G_SATELLITE_MAP);     
			map.addControl(new GSmallZoomControl());
			map.addControl(new GHierarchicalMapTypeControl());
			$.ajax({ type: "POST",
				url: galerie_path+"/template/picasa2/geoloc.php",
				data: "geoloctype="+type+"&geolocidalb="+idalb+"&geolocidimg="+idimg,
				dataType: "json",
				//beforeSend: fonction(),
				success: function(msg){
					if(type=='image' && msg.imgactuelle[0].lat!='') {
							map.setCenter(new GLatLng(msg.imgactuelle[0].lat,msg.imgactuelle[0].lng),4);
							var point = new GLatLng(msg.imgactuelle[0].lat,msg.imgactuelle[0].lng);
							var html = "<strong>"+msg.imgactuelle[0].nom+"</strong><br /><em>lieu : </em>"+msg.imgactuelle[0].lieu+"<br /><a href='javascript:void(0);'>zoomer sur ce lieu</a>";
							var marker = createMarker(point,html,iVert,msg.imgactuelle[0].lat,msg.imgactuelle[0].lng);
							map.addOverlay(marker);
							AucuneImgactuelle=0;
					} else {
						map.setCenter(new GLatLng(msg.albums[0].lat,msg.albums[0].lng),4);
					}
					// on place les images de l'album
					for (var i = 0; i < msg.images.length; i++) {
						if(msg.images[i].lat!='' && msg.images[i].actu!=1) {
							point = new GLatLng(msg.images[i].lat,msg.images[i].lng);
							var html = "<strong>"+msg.images[i].nom+"</strong><br /><em>lieu : </em>"+msg.images[i].lieu+"<br /><a href='javascript:void(0);'>zoomer sur ce lieu</a>";
							var marker = createMarker(point,html,iJaune,msg.images[i].lat,msg.images[i].lng);
							map.addOverlay(marker);
							AucuneImage=0;
						}
					}
					// on place l'album
					if(msg.albums[0].lat!='') {
						var point = new GLatLng(msg.albums[0].lat,msg.albums[0].lng);
						var html = "<strong>"+msg.albums[0].nom+"</strong><br /><em>lieu : </em>"+msg.albums[0].lieu+"<br /><a href='javascript:void(0);'>zoomer sur ce lieu</a>";
						var marker = createMarker(point,html,0,msg.albums[0].lat,msg.albums[0].lng);
						map.addOverlay(marker);
						AucunAlbum=0;
					}
					// si il n'y a rien à montrer on cache la carte
					if((type=='album' && AucunAlbum==1 && AucuneImage==1) || (type=='image' && AucunAlbum==1 && AucuneImage==1 && AucuneImgactuelle==1)) {
						$("#partie_navigation").html("Aucun lieu associ&eacute;.");
					}
					if(acacher==1) {$("#partie_navigation").hide();}
				},// fin success
				error: function(req,str,e){alert('erreur :'+e);}
				//complete: fonction(Type)
			});
		}
	} 
}
function loadmax(id) {
	if (GBrowserIsCompatible()) {
		$("#mapMax").show().height(400).width(400);
		var map = new GMap2(document.getElementById("mapMax"));
		map.setMapType(G_SATELLITE_MAP);     
		map.addControl(new GSmallZoomControl());
		map.addControl(new GHierarchicalMapTypeControl());

		/*
		$("#mapMax").height($("#div_affichage2").height()-20).width($("#div_affichage2").width()-20).show();	
		$("#div_affichage2").hide();
				
		var mapMax = new GMap2(document.getElementById("mapMax"));
		mapMax.setCenter(new GLatLng(46,1),6);
		mapMax.setMapType(G_HYBRID_MAP);     
		mapMax.addControl(new GSmallZoomControl());
		mapMax.addControl(new GHierarchicalMapTypeControl());
		*/
	}
}
