$(function(){
	
	$(".logo_actu_hebdo").each(function(i,e){
		$(e).css("height",$(e).parent().height()+"px");
	});
	
	setTimeout(function(){
		$(".logo_actu_hebdo").each(function(i,e){
			$(e).css("height",$(e).parent().height()+"px");
		});
	}, 1500);

	$("a.link_gg_map").fancybox({'type':'iframe',"width":"95%","height":"95%"});
	$(".article_online .adresse a, .libelle a, a.link_gg_map").attr("target","_blank");
	$("a.inline_link").fancybox({'hideOnContentClick': true});
	
	$(".adresse_span").each(function(i,e){
		while($(e).width() < 295){
			$(e).append(".");
		}
		if($(e).height() > 20){
			$(e).parent().next("td").prepend("<br />");
		}
	});

	/*$(".link_gg_map").each(function(i,e){
		$.get('lib_bvb.php?modele=adresse&action=geocoding&id='+$(e).attr('name')+'&ajax=1', function(data) {
			$(e).attr("href",data);
		});
	});*/
	$("a.video").live('click', function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});

		return false;
	});
	
	$("input[name='localite']").click(function(){
		$("select[name='zone']").val(0);
	});
	$("select[name=thematique]").change(function(){
		$.post("lib_bvb.php?modele=activite&action=get_list", {id_thematique: ""+$(this).val()+""}, function(data){
			if(data.length >0) {
				$("select[name=activite]").html(data);
			}
		});
	});
	
	$("select[name=id_region]").change(function(){
		$("#img_region").attr("src","/htdocs/img/region/"+$(this).val()+".jpg");
	});
	
	$("select, input[type!=submit]").click(function(){
		remplir_champ_commune("");
		remplir_champ_entite("");
	});
	
/** <----------------------------- Suggestion Ville */
	function lookup_loc(inputString) {
		if(inputString.length < 2) {
			// Hide the suggestion box.
			$('#suggestions_loc').hide();
		} else {
			//alert("lancement de la recherche");
			$.post("lib_bvb.php?modele=adresse&action=get_list_ville", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#autoSuggestionsList_loc').html(data);
					$('#suggestions_loc').show("slow");
				}
			});
		}
	} // lookup
	
	function remplir_champ_commune(thisValue) {
		$('#inputString_loc').val(thisValue);
		setTimeout("$('#suggestions_loc').hide('slow');", 200);
	}
	
	$("input[name=localite]").keyup(function(){
		lookup_loc($(this).val());
	});
	
	$("input[name=localite]").blur(function(){
		if($(this).val()==""){
			remplir_champ_commune();
			$("input[name=localite]").val("(taper la localité)");
			$("input[name=localite]").css("font-style","italic");
			$("input[name=localite]").css("color","#888888");
		}
	});
	
	function getParameterByName( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return decodeURIComponent(results[1].replace(/\+/g, " "));
	}
	
	$("li.commune").live('click', function() {
		remplir_champ_commune($(this).text());
	});
	
	if($("input[name=localite]").val()==""){
		$("input[name=localite]").val("(taper la localité)");
		$("input[name=localite]").css("font-style","italic");
		$("input[name=localite]").css("color","#888888");
	}
	$("input[name=localite]").focus(function(){
		$(this).val("");
		$("input[name=localite]").css("font-style","");
		$("input[name=localite]").css("color","black");
	});
/** >---------------------------------------- Suggestion Ville */
/** <----------------------------- Suggestion Entité */
	function lookup_ent(inputString) {
		if(inputString.length < 2) {
			// Hide the suggestion box.
			$('#suggestions_ent').hide();
		} else {
			$.post("lib_bvb.php?modele=entite&action=get_list_entite", {queryString: ""+inputString+""}, function(data){
				if(data != "") {
					$('#autoSuggestionsList_ent').html(data);
					$('#suggestions_ent').show("slow");
				}
			});
		}
	} // lookup
	
	function remplir_champ_entite(thisValue) {
		$('#inputString_ent').val(thisValue);
		setTimeout("$('#suggestions_ent').hide('slow');", 200);
	}
	
	$("input[name=entite]").keyup(function(){
		lookup_ent($(this).val());
	});
	
	
	$("input[name=entite]").blur(function(){
		if($(this).val()==""){
			remplir_champ_entite();
			$("input[name=entite]").val("(taper le nom, la raison sociale, la marque)");
			$("input[name=entite]").css("font-style","italic");
			$("input[name=entite]").css("color","#888888");
		}
	});
	
	$("li.entite").live('click', function(){
		remplir_champ_entite($(this).text());
	});
	
	if($("input[name=entite]").val()==""){
		$("input[name=entite]").val("(taper le nom, la raison sociale, la marque)");
		$("input[name=entite]").css("font-style","italic");
	}
	
	$("input[name=entite]").focus(function(){
		$(this).val("");
		$("input[name=entite]").css("font-style","");
		$("input[name=entite]").css("color","black");
	});
/** >---------------------------------------- Suggestion Entité */
	
	$("input").attr('autocomplete', 'off');
});
