
 var plus = "[+]";
 var moins = "[-]";
 $(document).ready(function() {
	$('.infoSupp').hide();	
	$(".infoSupp").each(  
						function(index) {
						var idCible = this.id;
						var cible = this;
						var boutonPlus = $("<span>" +plus + "</span>").click(
							function() {					
								if (this.estVisible)
									{
									this.estVisible = false;
									$(this).html(plus);
									$(cible).hide('fast');
									}
								else
									{
									$(cible).show('fast');
									this.estVisible = true;
									$(this).html(moins);
									}
								}
							) ;
						var balisePlus = $("<a  href=\"javascript:void(0);\"></a>").append(boutonPlus);
						$(this).before (balisePlus); 
						//$(this).removeClass('infoSupp');

						}
					);
	
	$(".menu").each(  function(index) {
		if ($(this).hasClass('ferme') || $(this).hasClass('ouvert'))
		{
			var interieur = $(this).next("ul")
			if ($(this).hasClass('ferme'))
				interieur.hide();
			var titre = $(this).attr("titre");
			$(this).click(
				function() {
					if ( $(this).hasClass('ouvert') )
						{							
						interieur.slideUp("fast");
						$(this).removeClass('ouvert');
						$(this).addClass('ferme');

						}
					else
						{
						interieur.slideDown("fast");
						$(this).removeClass('ferme');
						$(this).addClass('ouvert');
						}
					}
				) 
			
			$(this).wrapAll('<a class="tooltip" title="' + titre + '" href="javascript:void(0);"></a>');
		}		


	}
	
	);
	
	$(".fiche").hover(function(){
	   $(this).addClass("fichehover");
	   var ims = $(this).find(".pouce");	   
	   if (ims.length >0)
		ims[0].src = ims[0].src.replace("pouce1","pouce2");
	   var ims = $(this).find(".crochet");	   
	   if (ims.length >0)
		ims[0].src = ims[0].src.replace("crochet1","crochet2");		
	 },function(){
	   $(this).removeClass("fichehover");
	   var ims = $(this).find(".pouce");
	   if (ims.length >0)
		ims[0].src = ims[0].src.replace("pouce2","pouce1");
		var ims = $(this).find(".crochet");
		if (ims.length >0)
			ims[0].src = ims[0].src.replace("crochet2","crochet1");
	 });
	 $(".preferes").each(function(index){	
		setStatutPrefere(this.id.replace("p_",""));		
		}
		);
	
	$(".urlext").each(function(index){	
				
				var idP = this.id.replace("url_","");
				$(this).click(function()
								{
								st(idP);
								}
							);	
				if(estDejaVisite(idP))
				{					
					$(this).find(".crochet").removeClass("inv");
					if (typeof(langue) != "undefined") 
					{
						if (langue == "fr")
							this.title += " à nouveau (déjà visité)";
						else
							this.title +=  " again (already visited)";
					}
				}
				$(this).addClass("tooltip");	
				this.target="_blank" ;
				
			}			
		);
	
	 if ($("#carte").length>0) centrerLaCarte();//fichier c-gmapapi.php
	 afficherPreferes();
	 afficherVisites();
	 tooltip();
	 
			
		 /*nouveaux onglets*/
	$(".onglet:not(:first)").hide();
	 //to fix u know who
	 $(".onglet:first").show();
	 //when we click one of the tabs
	 $("#tabnav a").click(function(){
		$("#tabnav li").removeClass('tabactuel');
		$("#tabnav li").addClass('tab');
		
		$(this).parents("li").removeClass('tab');
		$(this).parents("li").addClass('tabactuel');
		
		 //get the ID of the element we need to show
		 //var stringref = $(this).attr("href").split('#')[1];
		 
		  stringref =this.id.replace("t","onglet");
		 //hide the tabs that doesn't match the ID
		 $('.onglet:not(#'+stringref+')').hide();
		 //fix
		if ($.browser.msie && $.browser.version.substr(0,3) == "6.0") {
			$('.onglet#' + stringref).show();
		 }
		 else
		 //display our tab fading it in
			$('.onglet#' + stringref).fadeIn();		 
		 });
		 
		 
	 equalHeight($(".fichesSimilaires h4"));
	 equalHeight($(".fichesSimilaires ul"));
	 equalHeight($(".fichesSimilaires .description"))

	 $(".in").each(function(index){	
		$(this).removeClass('in');	
		}
		);

	/*var largeurMiniature = 150;
	 $(".imgminiaturecommandite").each(function(index){	
		if ($(this).width()> largeurMiniature)
			largeurMiniature = $(this).width();
		}		
		);
	if (largeurMiniature>150)
	{
		//alert("plus");
		$(".miniaturecommandite").width(largeurMiniature);
		$(".descriptioncommandite").width(330+150-largeurMiniature);
	}*/
	
	reselectTag();
	
	/*
	 
	*/
	/*
	...
	*/
	
	}
); 


 function preferes(idPost)
{
	var texte = $("#p_" + idPost);
	if (estpreferes(idPost))
		supprimerFavori(idPost);
	else
		ajouterFavori(idPost);	
	setStatutPrefere(idPost);
	afficherPreferes();
	if (getParameter("preferes") =="1") 
		window.location = window.location;	
}

function setStatutPrefere(idPost)
{
	var texte = $("#p_" + idPost);
	var lien = texte.parents("a");
	if (langue == "fr")
	{
		
		if (estpreferes(idPost))
			{
			texte.html("Retirer");
			lien.attr("title","Retirer des mes sites préférés");
			}
		else
			{
			texte.html("Ajouter");
			action = "Supprimer";
			lien.attr("title","Ajouter à mes sites préférés");
			}
	}
	else
	{
		if (estpreferes(idPost))
			{
			texte.html("Substract");
			lien.attr("title","Substract from my favorites websites");
			
			}
		else
			{
			texte.html("Add");
			action = "Supprimer";
			lien.attr("title", "Add to my favorites websites");
			}
	}
	var ims = $(lien).find(".pouce");
	   
	if (estpreferes(idPost))
	{
		if (ims.length >0)
			ims[0].src = ims[0].src.replace("apouce","bpouce");
	}
	else
	{
		if (ims.length >0)
			ims[0].src = ims[0].src.replace("bpouce","apouce");
	}
}

function ajoutObjectif()
{
try{

pageTracker._trackPageview("/visiteexterne");
} catch(err) {}
}
function stat(url)
{
	//ajoutObjectif();
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}

	
	 xmlhttp.open("GET", url,true);
	 xmlhttp.onreadystatechange=function() {
	 }
	xmlhttp.send(null);

}
var imactuelle = null;
function ov(obj)
{
	obj.style.borderColor="#CE3000";
	imactuelle = obj;
}
function out(obj)
{
;	if(imactuelle) 
		if (imactuelle.style) 
			{imactuelle.style.borderColor="#FFFFFF";}
	
}
function detail(im){
	document.body.style.cursor = 'wait';
	var o = document.getElementById("pp");
	if (o)
	{
		o.onload = imageChargee;	
		o.src=im;
	}
	
	

}
function imageChargee(){
	document.body.style.cursor = 'default';
}
function afficherVisites()
{
	var visites = getValeurCookie("visites");
	if (visites =="")
		$('#sitesVisites').hide();
	else
	{
		$('#sitesVisites').show();
		$('#nbSitesVisites').show();
		var nbSites = visites.split("|").length -2;
		$('#nbSitesVisites').html(nbSites);
		
	}
		
}
function afficherPreferes()
{
	var preferes = getValeurCookie("preferes");
	if (preferes =="")
		$('#sitesPreferes').hide();
	else
	{
		$('#sitesPreferes').show();
		$('#nbSitesPreferes').show();
		var nbSites = preferes.split("|").length -2;
		$('#nbSitesPreferes').html(nbSites);
		
	}
}
function ajouterVisite(no)
{
	
	ajouterJeton(no,"visites") ;
	afficherVisites();	
}
function ajouterFavori(no)
{
	ajouterJeton(no,"preferes") ;	
}
function supprimerFavori(no)
{
	supprimerJeton(no,"preferes");
}
function getpreferes()
{
	getValeurCookie("preferes");
}
function estpreferes(no)
{
	var preferes = getValeurCookie("preferes");
	var deja = preferes.indexOf("|" + no + "|");
	return (deja >-1);
}
function estDejaVisite(no)
{
	var preferes = getValeurCookie("visites");
	var deja = preferes.indexOf("|" + no + "|");
	return (deja >-1);
}
function ajouterJeton(no, nomCookie) {
	
	var visites ;
	if(document.cookie )
	{
		
		visites = getValeurCookie(nomCookie) ;
		var deja = visites.indexOf("|" + no + "|");
		if (deja ==-1)
			{
			if (visites == "")
				visites =  "|" + no + "|";
			else
				visites = "|" + no + visites;
			}
		
		
	}
	else
		visites =  "|" + no + "|";
	setValeurCookie(nomCookie, visites);
}
function supprimerJeton(no, nomCookie) {
	
	var jeton =  "|" + no + "|";
	var actuel = getValeurCookie(nomCookie);
	if (actuel == jeton)
		substituerValeurCookie(nomCookie,jeton,"");
	else
		substituerValeurCookie(nomCookie,jeton,"|");
}
function substituerValeurCookie(idCookie, valeur, substitution) {
	
	var avant = getValeurCookie(idCookie);
	if (avant =="") return;
	
	var apres = avant.replace(valeur,substitution);
	setValeurCookie(idCookie,apres);	

}
function setValeurCookie(idCookie, nouvelleValeur) {
	document.cookie = idCookie+"="+nouvelleValeur+"; expires=Monday, 04-Apr-2050 05:00:00 GMT; path=/";	
}


function getValeurCookie(idCookie) {
	if(document.cookie)
	{
		var debut = document.cookie.indexOf(idCookie);
		if (debut == -1) return "";
		var fin = document.cookie.indexOf(";",debut);	
		if (fin ==-1) fin =document.cookie.length;
		return document.cookie.substring(debut + idCookie.length + 1,fin) ;			
	}
	else
	{ 
		return "";
	}

}

function getParameter ( parameterName ) {
	queryString = window.top.location.search;
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) 
		{
		var begin = queryString.indexOf ( parameterName );
		if ( begin != -1 ) 
			{
				begin += parameterName.length;
				var end = queryString.indexOf ( "&" , begin );
				if ( end == -1 ) 
				{
					end = queryString.length
				}
			return unescape ( queryString.substring ( begin, end ) );
			}
		return "";
		}
}
function reselectTag()
{
	var tag = getParameter("tag");
	if (tag != "")
	{
		var o = document.getElementById("tag-menu");
		if (! o) return;
		for (var i=0; i<o.options.length; i++){
		 if (o.options[i].value==tag)
			o.options[i].selected='selected';
		 else
			o.options[i].selected=false;
		 
		}
		
	}
}

function unloadPage()
{
	; // surcharger par GUnload si cartes google
}
/*pour google map*/
//http://www.cssnewbie.com/equal-height-columns-with-jquery/
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}


/** *****/
/*http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery*/
this.tooltip = function(){	
	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){	
		//this.title = "Visiter";	
		if (this.title != "")
			this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		//this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

