$(document).ready(function() {
						
			oldCat=new Object();
			afficheCarte($('div#supportRegionCarte').css("background-image"));			
			init();
			function init(){
				$("div").each(function (index, domEle){							
					valueR = domEle.id.substring(0,2);
					nom=domEle.id;
					if(valueR=="R_"){
						$("#"+nom+" > a").each(function (index1, domAEle){
							nomA=domAEle.id;
							if(nomA==$("#faillotDept").val()){	
								$('#oldRegion').val(nom);
								$('#oldDept').val(nomA);
								$("#"+nom).removeClass().addClass("affiche");
								//nom=$(this).attr('id');				
								$('div#supportRegionCarte').removeClass().addClass(nomA);
								afficheCarte($('div#supportRegionCarte').css("background-image"))								
								
								//$("#"+nomA).css('background-color','#0066FF');
								dept=$("#inputIpDept").attr("value");
								$("#"+nomA).css("border-left","3px solid #FF6600");
								//$("#inputOu").attr("value",dept);
							}
						});																			
					}
				});				
			}
			$("#rdQui").click(function(){  $('#labelQuoi').hide(); $('#labelQui').show();  });
			$("#rdQuoi").click(function(){ $('#labelQuoi').show(); $('#labelQui').hide();  });
			
			//Chargement de la categorie professionnel-------------------------------------
			htmlMonde=$("#cat_professionnel").html();
			$("#categorie_tempo").html(htmlMonde+"<br>");
			$("#categorie_tempo .titreCategorie").html("").css("width","0px");
			//Chargement de la categorie professionnel-------------------------------------

			append_upandown('div#monde_titre','30px');
			append_upandown('div#AaZ_titre','30px');			
			//append_upandown('div#categorie_titre','70px');			
			function append_upandown(elmt,elmtHeight) {
				$(elmt).append("<div class='show down'></div>");
				var button = $(elmt + '> div.show')
				button.click(function() {
					if(button.hasClass('down')) {
						$(elmt).css('height','auto');
						button.removeClass('down').addClass('up');
					}
					else {
						$(elmt).css('height',elmtHeight).css('border-bottom','0');
						button.removeClass('up').addClass('down');
					}
					goUL(elmt);	
				});
			 }			 			 			 			 
			 
			 function goUL(elmt){
			 	
				if(elmt=="div#monde_titre"){
					if($("#monde_contenu").hasClass('cacher')) {
							$("#monde_contenu").maxZIndex();
							$("#monde_contenu").removeClass('cacher').addClass('active');
					}else {
							$("#monde_contenu").removeClass('active').addClass('cacher');
					}	
				}
			 	else if(elmt=="div#AaZ_titre"){
					if($("#AaZ_contenu").hasClass('cacher')) {
							$("#AaZ_contenu").maxZIndex();
							$("#AaZ_contenu").removeClass('cacher').addClass('active');
					}else {
							$("#AaZ_contenu").removeClass('active').addClass('cacher');																												
					}					
				}
			 	else if(elmt=="div#categorie_titre"){
					if($("#categorie_contenu").hasClass('cacher')) {
						$("#categorie_contenu").maxZIndex();
						$("#categorie_contenu").removeClass('cacher').addClass('active');
						//$("#mondeDiapo").css("opacity","0").css("filter","alpha(opacity = 0)");
						$htmlMondeDiapo=$("#mondeDiapo").html();
						$("#mondeDiapo").html("");
					}else {
						$("#categorie_contenu").removeClass('active').addClass('cacher');																												
						$("#mondeDiapo").html($htmlMondeDiapo);
					}																				
				}				
			 }

			$('#monde_contenu > ul > li > a')
			.click(function(){
				goUL('div#monde_titre');
				nom=$(this).html();	
				$("#txtMonde").val(nom);												
				dept=$("#inputIpDept").attr("value");
				varMonde=$("#txtMonde").attr("value");
				if(varMonde=="Pme"){ varMonde="professionnel"; }
				fichier="./fiches/recherche.php";
				type="monde="+varMonde+"&departement="+dept;
				ajaxRecherche(fichier,type,"slider");
								
				htmlThis=$("#cat_"+varMonde.toLowerCase()).html();
				$("#categorie_tempo").html(htmlThis+"<br><br>");
				$("#categorie_tempo .titreCategorie").html("").css("width","0px");



				return false;
			})
			.mouseup(function(){

				//$("#monde_contenu").removeClass('active').addClass('cacher');				
				//return false;
			})
			//Region 									
			$('.porteRegion').mouseout(function() {								
				rg=$("#oldRegion").val();
				tbDept=rg.split("R_");
				rg=tbDept[1];				
				dpt=$("#oldDept").val();
				$("#"+rg).removeClass().addClass("affiche");
				$('div#supportRegionCarte').removeClass().addClass(rg);
				afficheCarte($('div#supportRegionCarte').css("background-image"))								
				//$("#"+dpt).css('background-color','#0066FF');
			});
												
			$('#a > li > a')			
			.mouseover(function(){
				nom=$(this).attr('id');
				$('div#supportRegionCarte').removeClass().addClass(nom);
				afficheCarte($('div#supportRegionCarte').css("background-image"))								
			})			
			.click(function(){				
				//On ferme toute les regions select
				$("div").each(function (index, domEle){							
					valueR = domEle.id.substring(0,2);
					nom=domEle.id;
					if(valueR=="R_"){
						$("#"+nom).removeClass().addClass("affichePas");
						/*
						$("#"+nom).css('background-color','#6fa1fb');
						$("#"+nom).css('color','#0000FF');
						*/
						
					}
				});
				//On affiche notre region select
				regionR="R_"+$(this).attr('id'); 
				deptR=$(this).html()//attr('value');								
				$("#inputIpRegion").attr("value",deptR);
				$('#oldRegion').val(regionR);
				$("#"+regionR).removeClass().addClass("affiche");
				return false;
			})	 		
			//departement
			$('#region ul li div > a')
			.mouseover(function(){
				nom=$(this).attr('id');				
				$('#oldDept').val(nom);
				$('div#supportRegionCarte').removeClass().addClass(nom);				
				afficheCarte($('div#supportRegionCarte').css("background-image"));
				//$("#"+$("#faillotDept").val()).css('background-color','#0066FF');				
			})
			.click(function(){
				//alert($('#faillotDept').val());
				sauveDept=$('#faillotDept').val();
				$("#"+sauveDept).css('border-left','3px solid gray').css('border-bottom','');				

				dept=$(this).html();
				thisId=($(this).attr('id'));
				tbDept=dept.split("-");
				$("#inputIpDept").attr("value",tbDept[0]);
				
				$("#"+$("#faillotDept").val()).css('background-color',''); //Enlever couleur de fond
				$('#inputQuoi,#inputOu').val("");
				$(oldCat).css('border-bottom','');	
				
				$("#faillotDept").attr("value",thisId); //sauvegarde du nom de dept et dept
				varMonde=$("#txtMonde").attr("value");
				fichier="./fiches/recherche.php";
				type="monde="+varMonde+"&departement="+tbDept[0];
				ajaxRecherche(fichier,type,"slider");
				
				dept=$("#inputIpDept").attr("value");
				$("#inputOu").attr("value",dept);
				
				
				return false;
				
			})
			$('#categorie_contenu img , #categorie_tempo img ')
			.mouseover(function(){
				srcH=$(this).attr('rel1');				
				$(this).attr("rel1",$(this).attr("src"));
				$(this).attr("src",srcH);
			})
			.mouseout(function(){
				src=$(this).attr('rel1');				
				$(this).attr("rel1",$(this).attr("src"));
				$(this).attr("src",src);
			})
			.click(function(e){	
				cat=$(this).attr("rel");	
				varMonde=$("#txtMonde").attr("value");
				dept=$("#faillotDept").attr("value").replace("d","");				
				rechStrOu=$("#inputOu").attr("value"); //Verifier si chaine Mulhouse, colmar
				if($("#inputOu").attr("value")==""){
					$("#inputOu").attr("value",dept);
				}

				fichier="./fiches/recherche.php";
				type="categorie="+cat+"&monde="+varMonde+"&dept="+dept+"&rechStrOu="+rechStrOu;
				ajaxRecherche(fichier,type,"slider");					
				$('#inputQuoi').val("");		
				
				$(oldCat).css('border-bottom','');	
				$(this).css('border-bottom','3px solid #FF6600');	
				oldCat=$(this);
				return false;
			})
			
			$('#contacterNous,#aide,#abonnezVous').click(function(e){
				fichier=$(this).attr("href");
				ajaxRecherche(fichier,"","slider");					
				return false;
			});
			$('h5 .abonnez-vous').click(function(e){
			});
												
			function fixe(){
				$("div").each(function (index, domEle){							
					valueR = domEle.id.substring(0,2);
					nom=domEle.id;
					if(valueR=="R_"){
						$("#"+nom+" > a").each(function (index1, domAEle){
							nomA=domAEle.id;
							if(nomA==$("#faillotDept").val()){	
								$('#oldRegion').val(nom);
								$('#oldDept').val(nomA);
								$("#"+nom).removeClass().addClass("affiche");
								//nom=$(this).attr('id');				
								$('div#supportRegionCarte').removeClass().addClass(nomA);
								afficheCarte($('div#supportRegionCarte').css("background-image"))								
								/*enleve le 22/01/2012
								$("#"+nomA).css('background-color','#0066FF');
								dept=$("#inputIpDept").attr("value");
								/***********************************************************************/
								
								//$("#inputOu").attr("value",dept);
							}
						});																			
					}
				});				
			}
			
			$('#inputQuoi').keyup(function(e){		
				if($("#inputOu").attr("value").length < 2){						
					//si < à 2 on fixe
					dept=$("#inputIpDept").val();
					$("#inputOu").attr("value",dept);					
				}
				$('#inputOu').keyup();
			})

			$('#inputOu').keyup(function(e){		
				if($("#inputOu").attr("value").length >= 2){	
					oldR=$('#oldRegion').val();					
					dept=$("#inputOu").attr("value");
					$("#faillotDept").val("d"+dept);										
					varMonde=$("#txtMonde").attr("value");
					quoi=$("#inputQuoi").attr("value");
					radioQQ=$('input[type=radio][name=rdQQ]:checked').attr('value');
					fichier="./fiches/recherche.php";
					type="searchOu="+dept+"&monde="+varMonde+"&inputQuoi="+quoi+"&etatQQ="+radioQQ;
					ajaxRecherche(fichier,type,"slider");
					fixe();										
					tbR=oldR.split("_");
					/*enleve le 22/01/2012-----------------------------------------
					//$("#"+oldR).removeClass().addClass("affichePas");
					//$("#"+tbR[1]).css('background-color','#0066FF');
					/*--------------------------------------------------------------*/
					$(oldCat).css('border-bottom','');	
					//$(this).css('border-bottom','3px solid #FF6600');	
					
				}
			})
			
			
			
			$("#openGeo").click(function(){  
				fichier="geoCook.php";
				type="init=oui";
				$('#slider').html("");
				$("#slider").append("<iframe id='ifr' src='geoCook.php'></iframe>");				
				$('iframe#ifr').css("width","99%");
				$('iframe#ifr').css("height","550px");
				
				return false;
			});					
			
			$('.loupe').click(function(e){	recherche(0);	})
			$('#rdQui , #rdQuoi').click(function(e){ prepare(""); 		});						
});
			
			function prepare(lastKey){
					txtQuoi=$("#inputQuoi").attr("value").replace("&","49");
					txtOu=$("#inputOu").attr("value");
					varMonde=$("#txtMonde").attr("value");
					QQ=$('input[type=radio][name=rdQQ]:checked').attr('value');
					deptEnCours=$("#inputIpDept").attr("value");
					fichier="./fiches/recherche.php";
					type="prepareQuoi="+txtQuoi+"&prepareOu="+txtOu+"&typeRech="+QQ+"&monde="+varMonde+"&dept="+deptEnCours+"&lastKey="+lastKey;
					ajaxRecherche(fichier,type,"slider");	
					return false;
			}

			function recherche(page){
					//alert(page);
					txtQuoi=$("#inputQuoi").attr("value");
					txtOu=$("#inputOu").attr("value");
					varMonde=$("#txtMonde").attr("value");
					QQ=$('input[type=radio][name=rdQQ]:checked').attr('value'); 
					
					fichier="./fiches/recherche.php";
					type="quoi="+txtQuoi+"&ou="+txtOu+"&typeRech="+QQ+"&monde="+varMonde+"&numeroPage="+page;
					ajaxRecherche(fichier,type,"slider");	
					return false;
			}
	function ajaxRecherche(fichier,type,div) {
		//alert("cp change "+$(this).val());		
				
			$("#"+div).html("<img width='25px' src='./img/attente.gif' border='0' style='position:absolute; left:48%; top:48%;'>");																
				$.ajax({
					type: "POST",
					url: fichier,
					cache: true,
					data: type,
					//dataType: 'jsonp',
					async:   true, 
					success: function(msg) {
						$('#'+div).html(msg);
					}
				});
		sauveDept=$('#faillotDept').val();
		$("#"+sauveDept).css('border-left','5px solid #FF6600');				
	}
	
	function afficheCarte(nomImg){
		if($.browser.webkit){
			nomImg=nomImg.replace("url(","");
			nomImg=nomImg.replace(")","");
		}else{						
			var tbImg=nomImg.split('"');
			nomImg=tbImg[1];
		}
		$('img#cartedefrance').attr("src",nomImg);
		$('div#supportRegionCarte').removeClass();



		//$("#cat_professionnel").html("");
	}	
			
			
			//Zindex max
			$.maxZIndex = $.fn.maxZIndex = function(opt) {
				var def = { inc: 10, group: "*" };
				$.extend(def, opt);    
				var zmax = 0;
				$(def.group).each(function() {
					var cur = parseInt($(this).css('z-index'));
					zmax = cur > zmax ? cur : zmax;
				});
				if (!this.jquery)
					return zmax;
			
				return this.each(function() {
					zmax += def.inc;
					$(this).css("z-index", zmax);
				});
			}					

	function favorie()
	{
		if ( navigator.appName != 'Microsoft Internet Explorer' )
				{ window.sidebar.addPanel("Managerclic Annuaire des professionnels","http://managerclic.fr/",""); }
		else 	{ window.external.AddFavorite("http://managerclic.fr/","Managerclic Annuaire des professionnels"); } 
	}

	

