function imgFromIndice(indice) {
		if (indice < 40) {
			retour = 'Cafe-GG-DOUX.gif';
		} else if (indice >=40 && indice < 65) {
			retour = 'Cafe-GG-MELLOW.gif';
		} else if (indice >= 65 && indice < 75) {
			retour = 'Cafe-GG-MI-CORSE.gif';
		} else if (indice >= 75) {
			retour = 'Cafe-GG-CORSE.gif';
		}
		return retour;
	}
function seeDealer(id) {
	//$("body").trigger(gmarkers[id].click);
	gmarkers[id].openInfoWindowHtml(gmarkersHTML[id]);
	//console.log(id);
}

$(function(){


	//////// GOogle maps
	$("#AjoutFournisseur .mapupdate").bind("blur change", function(){
		str_recherche = document.getElementById("info_Adresse").value +', '+
		document.getElementById("info_Ville").value+', '+
		document.getElementById("info_CodePostal").value;
		
		adresse_latitude = '';
		adresse_longitude = '';
		adresse_recherche = str_recherche;
		
		if (typeof(showMap) != "undefined") {
			showMap();
		}
		
	});

	// passe pour le carré cliquable complet
	$(".cta_02, .cta_03").click(function(){ window.location = $("a", this).attr("href"); });



	$(".listefournisseur_admin li a").bind("mouseover", function(){ 
		id = 'span_'+$(this).attr('id');
		if ($("#"+id).length < 1) 
			$(this).after(" <span id='"+id+"' style='display:none' class='suggestion'>Cliquez pour modifier</span>"); 
		$("#"+id).fadeIn('fast');
	});
	
	$(".listefournisseur_admin li a").bind("mouseout", function(){ 
		id = 'span_'+$(this).attr('id');
		$("#"+id).fadeOut('fast');
	});
	

	
	if (typeof(showMap) != "undefined") {
		showMap();
	}





	$("a[href^=http://]").attr("target", "_blank")
	
	
	// Champs admin indice (rien d'autre que des chiffres)
	$("#txt_indice").bind("keypress", function(e){
	
		if (e.keyCode != 8 && e.keyCode != 46) {
			val = String.fromCharCode(e.charCode);
			if (val != parseInt(val))
			return false;
		}
	});
	
	// update image if needed
	$("#txt_indice").bind("blur", function(){ 
		if ($("#admin .image select").val() == "default") {
			image = imgFromIndice($("#txt_indice").val());
			$("#admin .image img").attr("src", "inc.timthumb.php?src=/images/cafes/"+image+"&w=200&h=135&zc=1")
		}
	});
	
	
	// display image preview
	$("#admin .image select").bind("change", function(){
		if (this.value == "default") {
			image = imgFromIndice($("#txt_indice").val());
		} else {
			image = this.value
		}
		$("#admin .image img").attr("src", "inc.timthumb.php?src=/images/cafes/"+image+"&w=200&h=135&zc=1")
	});
	
	
	// hide cafe si on cree une categorie
	$("#admin #opt_parent").bind("change", function(){
		/*if (this.value == "new") {
			//$('#infos_nouveau_cafe').css("opacity",0.5);
			$('#infos_nouveau_cafe').hide()
			$('#hd_soumission').val("cat");
		} else {
			$('#infos_nouveau_cafe').show();
			$('#hd_soumission').val("cafe");
		}*/
	
		if ($("option:selected",this).parent().attr("label") == "Cafés en grains") {
			$("#admin #rdo_grain").attr("checked", true);
		} else if ($("option:selected",this).parent().attr("label") == "Cafés emballés") {
			$("#admin #rdo_emballe").attr("checked", true);
		}
	});
	
	$('#admin ul li a img').bind('mouseenter', function(){ $(this).css("opacity", 0.5); });
	$('#admin ul li a img').bind('mouseleave', function(){ $(this).css("opacity", 1); });
	
	$(".delete").click(function(){
		var answer = confirm("Attention, si vous supprimer une catégorie comprenant des enfants, les enfants seront perdus.\n\n Voulez vous continuer?")
		return answer;
		//return false;
	});
	
	
	
	
	
	
	$('#flashvideo').flash({
		src: 'player.swf?file=medias/cafenapoleon.flv&autostart=1',
		width: 345,
		height: 275
	});

	/*$("#new_cafe").click(function(){
		$('#infos_nouveau_cafe').show();
		$('#hd_soumission').val("cafe");
		$("#opt_parent option:nth(1)").attr("selected", true)
		$(".newC").hide();
		return false;
	});
	
	$("#new_cat").click(function(){
		$('#infos_nouveau_cafe').hide();
		$('#hd_soumission').val("cat");
		$(".newC").show();
		return false;
	});
	*/

});














