
 var plus = "[+]";
 var moins = "[-]";
 $(document).ready(function() {
	
	$('#zoneContact').hide()
	$('.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');

						}
					);
	$('#formInfo').hide();	
	
	$('.infoContact').hide();	
	$(".infoContact").each(  
						function(index) {
						var idCible = this.id;
						var cible = this;
						if (langue == "fr") plus = "Cliquez ici pour l'information de contact";
						else plus = "Click here for contact info";
						var boutonPlus = $("<span>" +plus + "</span>").click(
							function() {	
								st2(idCible,"clicscontact");							
								$(cible).show('fast');
								//this.estVisible = true;
								$(this).html("");									
								}
							) ;
						var balisePlus = $("<a class=\"gras orange t12\" 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>');
		}		


	}
	
	);
	
	
	$(".cursor-pointer").hover(function(){
	   $(this).addClass("cursor-pointer-hover");	
	 },function(){
	   $(this).removeClass("cursor-pointer-hover");
	 });
	
	$(".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).mousedown(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" ;
				
			}			
		);
		
	$(".urlext2").each(function(index){	
				//var idP = this.id.replace("url_","");
				var idP = $(this).attr("idp");
				
				var action = $(this).attr("action");
				$(this).mousedown(function()
								{
								st2(idP,action);
								}
							);	
				
				$(this).addClass("tooltip");	
			}			
		);
	
	 if ($("#carte").length>0) centrerLaCarte();//fichier c-gmapapi.php
	 
	 afficherPreferes();
	 afficherVisites();
	 afficherNavigationPerso();
	 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("J'aime");
			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)
{
	$.get(url, 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 afficherNavigationPerso()
{
	var preferes = getValeurCookie("preferes");
	var visites = getValeurCookie("visites");
	if (preferes =="" && visites=="")
		$('#navigationPerso').hide();
}
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");
	});		
	$("#topnav").html($("#bottomnav").html());
	
};


/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);

(function($){
	/* hoverIntent by Brian Cherne */
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
	
})(jQuery);

jQuery(function(){
			jQuery('ul.sf-menu').superfish();
		});
