var so;

function ajax_bloc_map(url,Obj) {
	//document.getElementById(Obj).innerHTML = "Chargement ...";
	var base=document.location.href.split("#");
	var data_file="/includes/modules/bloc_map/data/ammap_data.xml";
	var fichier='/includes/modules/bloc_search/index_continents.php';
	var type="";
	var idtype=0;
	if(base.length==2){
		base=base[1];
		base=base.split("continent");
		if(base.length==2){
			$("#map").css("margin-top","22px");
			fichier='/includes/modules/bloc_search/index.php';
			type="continent";
			idtype=base[1];
			switch(base[1]){
				case "1":
					data_file="/includes/modules/bloc_map/data/ammap_data_europe.xml";
					break;
				case "2":
					data_file="/includes/modules/bloc_map/data/ammap_data_asia.xml";
					break;
				case "3":
					data_file="/includes/modules/bloc_map/data/ammap_data_namerica.xml";
					break;
				case "4":
					data_file="/includes/modules/bloc_map/data/ammap_data_samerica.xml";
					break;
				case "5":
					data_file="/includes/modules/bloc_map/data/ammap_data_australia.xml";
					break;
				case "6":
					data_file="/includes/modules/bloc_map/data/ammap_data_africa.xml";
					break;
				case "7":
					data_file="/includes/modules/bloc_map/data/ammap_data_camerica.xml";
					break;
				case "8":
					data_file="/includes/modules/bloc_map/data/ammap_data_nafrica.xml";
					break;
				default:
					data_file="/includes/modules/bloc_map/data/ammap_data.xml";
					break;
			}
		}
		else {
			base=base[0];
			base=base.split("pays");
			if(base.length==2){
				fichier='/includes/modules/bloc_search/index_pays.php';
				type="pays";
				ids=base[1].split("/");
				idtype=ids[0];
				idCon=ids[1];
				switch(idCon){
					case "1":
						data_file="/includes/modules/bloc_map/data/ammap_data_europe.xml";
						break;
					case "2":
						data_file="/includes/modules/bloc_map/data/ammap_data_asia.xml";
						break;
					case "3":
						data_file="/includes/modules/bloc_map/data/ammap_data_namerica.xml";
						break;
					case "4":
						data_file="/includes/modules/bloc_map/data/ammap_data_samerica.xml";
						break;
					case "5":
						data_file="/includes/modules/bloc_map/data/ammap_data_australia.xml";
						break;
					case "6":
						data_file="/includes/modules/bloc_map/data/ammap_data_africa.xml";
						break;
					case "7":
						data_file="/includes/modules/bloc_map/data/ammap_data_camerica.xml";
						break;
					case "8":
						data_file="/includes/modules/bloc_map/data/ammap_data_nafrica.xml";
						break;
					default:
						data_file="/includes/modules/bloc_map/data/ammap_data.xml";
						break;
				}
			}
			else $("#map").css("margin-top","3px");
		}
	}
	$.post(url, function(data){
		document.getElementById(Obj).innerHTML = data;
		// <![CDATA[		
		so = new SWFObject("/includes/modules/bloc_map/ammap/ammap.swf", "ammap", "515", "283", "8", "#FFFFFF");
    	so.addVariable("path", "/includes/modules/bloc_map/ammap/");
		so.addVariable("data_file", escape(data_file));
    	so.addVariable("settings_file", escape("/includes/modules/bloc_map/data/ammap_settings.xml"));		
		so.addVariable("preloader_color", "#999999");
   		so.addParam("wmode", "transparent");
		so.write("map");
		// ]]>
		if(type=="pays"){
			getId("map").style.marginTop="22px";
			getPaysSearch(idtype);
		}
		else {
			if(type=="continent") getId("map").style.marginTop="22px";
			else getId("map").style.marginTop="3px";
			$.post(fichier, { idCon: idtype  }, function(data){
				$("#search_module").html(data);
				$("#champ_search").autocomplete(data_complete, {autoFill: true });
				$('#link_others').fancybox({ 'frameWidth':500, 'frameHeight':500, 'overlayShow':true });
			});
		}
		//ajax_bloc('/includes/modules/bloc_search/index_continents.php','search_module');
		
	});
}

var statut="ini";

function amRegisterClick(map_id, object_id, title, value){
	//alert(map_id+" "+object_id+" "+title+" "+value);
	$("#headerphoto").slideUp(700);
	switch(value){
		case 1:
			$("#search_module").fadeOut("normal",function(){
				$.post("/includes/modules/bloc_search/index.php", { idCon: object_id  }, function(data){
					document.getElementById("search_module").innerHTML = data;
					document.location.href="#continent"+object_id;
					$("#search_module").fadeIn("normal");
					$("#champ_search").autocomplete(data_complete, {autoFill: true });
					$('#link_others').fancybox({ 'frameWidth':500, 'frameHeight':500, 'overlayShow':true });
				});
			});
			break;
		case 2:
			document.location.href="#pays"+object_id+"/"+getId("id_continent_hidden").innerHTML;
			/*$("#search_module").fadeOut("normal",function(){
				$.post("/includes/modules/bloc_search/index_pays.php", { idPays: object_id  }, function(data){
					document.getElementById("search_module").innerHTML = data;
					document.location.href="#pays"+object_id+"/"+getId("id_continent_hidden").innerHTML;
					$("#search_module").fadeIn("normal");
					$("#champ_search").autocomplete(data_complete, {autoFill: true });
				});
			});*/
			break;
		case 3:
			document.location.href="#pays"+object_id+"/"+getId("id_continent_hidden").innerHTML;
			/*$("#search_module").fadeOut("normal",function(){
				$.post("/includes/modules/bloc_search/index_pays.php", { idPays: object_id  }, function(data){
					document.getElementById("search_module").innerHTML = data;
					document.location.href="#pays"+object_id+"/"+getId("id_continent_hidden").innerHTML;
					$("#search_module").fadeIn("normal");
				});
			});*/
			break;
		case 4:
			break;
		default:
			if(object_id=="0") {
				$("#search_module").fadeOut("normal",function(){
					$.post("/includes/modules/bloc_search/index_continents.php", {  }, function(data){
						document.getElementById("search_module").innerHTML = data;
						document.location.href="#";
						$("#search_module").fadeIn("normal");
					});
				});
			}
			ajax_bloc('/includes/modules/bloc_blog/index.php','bloc_blog');
			ajax_bloc('/includes/modules/bloc_membre/index.php','bloc_membre');
			ajax_bloc('/includes/modules/bloc_photo/index.php','bloc_photo');
			break;
	}
	/*if(object_id=="0") statut="nothing";
	
	if(statut=="ini"){
		$.post("/includes/modules/bloc_search/index.php", { idCon: object_id  }, function(data){
			document.getElementById("search_module").innerHTML = data;
			statut="continent";
		});
	}
	else if(statut=="continent"){
		$.post("/includes/modules/bloc_search/index_pays.php", { idPays: object_id  }, function(data){
			document.getElementById("search_module").innerHTML = data;
		});
	}
	else if(statut=="nothing"){
		$.post("/includes/modules/bloc_search/index_continents.php", {  }, function(data){
			document.getElementById("search_module").innerHTML = data;
		});
		statut="ini";
	}*/
}

function getPaysSearch(idPays){
	if(idPays==64){
		$("#search_module").fadeOut("normal",function(){
			$.post("/includes/modules/bloc_search/index.php", { idPays: idPays  }, function(data){
				document.getElementById("search_module").innerHTML = data;
				document.location.href="#pays"+idPays+"/"+getId("id_continent_hidden").innerHTML;
				$("#search_module").fadeIn("normal");
				$("#champ_search").autocomplete(data_complete, {autoFill: true });
			});
		});
	}
	else {
		$("#search_module").fadeOut("normal",function(){
			$.post("/includes/modules/bloc_search/index_pays.php", { idPays: idPays  }, function(data){
				document.getElementById("search_module").innerHTML = data;
				document.location.href="#pays"+idPays+"/"+getId("id_continent_hidden").innerHTML;
				$("#search_module").fadeIn("normal");
				$("#champ_search").autocomplete(data_complete, {autoFill: true });
			});
		});
	}
}

var ex_hash;
function pageload(hash) {
	if(hash!=ex_hash && hash!="other_pays"){
		 if(hash) {
			var base=hash.split("continent");
			if(base.length==2){
				   ajax_bloc_map('/includes/modules/bloc_map/index.php','topcarte');
					$("#bloc_blog").fadeOut("normal",function(){
						$.post("/includes/modules/carnets/getTop.php", { type: "top", niveau:"continent", id:base[1]  }, function(data){
							$("#bloc_blog").html(data);
							$("#bloc_blog").fadeIn();
						});
					});
					$("#bloc_membre").fadeOut("normal",function(){
						$.post("/includes/modules/membres/getTop.php", { type: "top", niveau:"continent", id:base[1]  }, function(data){
							$("#bloc_membre").html(data);
							$("#bloc_membre").fadeIn();
						});
					});
					$("#bloc_photo").fadeOut("normal",function(){
						$.post("/includes/modules/albums/getTop.php", { type: "top", niveau:"continent", id:base[1]  }, function(data){
							$("#bloc_photo").html(data);
							$("#bloc_photo").fadeIn();
						});
					});
			}
			else {
				base=hash.split("pays");
				if(base.length==2){
					base=base[1].split("/");
				   ajax_bloc_map('/includes/modules/bloc_map/index.php','topcarte');
				   getPaysSearch(base[0]);
					$("#bloc_blog").fadeOut("normal",function(){
						$.post("/includes/modules/carnets/getTop.php", { type: "top", niveau:"pays", id:base[0]  }, function(data){
							$("#bloc_blog").html(data);
							$("#bloc_blog").fadeIn();
						});
					});
					$("#bloc_membre").fadeOut("normal",function(){
						$.post("/includes/modules/membres/getTop.php", { type: "top", niveau:"pays", id:base[0]  }, function(data){
							$("#bloc_membre").html(data);
							$("#bloc_membre").fadeIn();
						});
					});
					$("#bloc_photo").fadeOut("normal",function(){
						$.post("/includes/modules/albums/getTop.php", { type: "top", niveau:"pays", id:base[0]  }, function(data){
							$("#bloc_photo").html(data);
							$("#bloc_photo").fadeIn();
						});
					});
				}
			}
		 }
		 else {
						/*
						FADING BLOC SEARCH ACCUEIL
						$("#search_module").fadeOut("normal",function(){
							$.post("/includes/modules/bloc_search/index_continents.php", {  }, function(data){
								document.getElementById("search_module").innerHTML = data;
								document.location.href="#";
								$("#search_module").fadeIn("normal");
							});
						});*/
					ajax_bloc('/includes/modules/bloc_blog/index.php','bloc_blog');
					ajax_bloc('/includes/modules/bloc_membre/index.php','bloc_membre');
					ajax_bloc('/includes/modules/bloc_photo/index.php','bloc_photo');
					ajax_bloc_map('/includes/modules/bloc_map/index.php','topcarte');
		 }
		 ex_hash=hash;
	}
}
