$(document).ready(function(){
	
	$('a[href^=http://]').not('a[href*='+window.location.host+']').attr('target', '_blank');
	$('a[href$=.pdf]').attr('target', '_blank');
	
	
	$("#search_submit").click(function(){
		$("#search_form").submit();
	});

	$.wt_carrousel();
	
	//##################################################################
	//###  Fonctions du menu de gauche  ################################
	
	var current_url = document.location.href.split('/');
	real_url = current_url[current_url.length - 1];
	//console.log(current_url);
	//console.log(real_url);
	
	$.wt_accordion({
		container : 'lc_menu_sections', // ID du container
		activeContent : $("#active_accordion").val(), // Accordeon ouvert par defaut
		speed : 400 // vitesse de l'effet slideToggle ( slow, medium, speed )
	});
	
	$(".sAccordion-content li a[href="+real_url+"]").each(function(){
			$(this).css('font-weight', 'bold');
			grand_father = $(this).parent().parent();
			grand_father.show();
			grand_father.parent().find('a:first').css('font-weight', 'bold').addClass('sAccordion-open-actif');
			//$(this).parent().parent().parent().find("a").addClass('sAccordion-open-actif');
	});
	
	$("a[href="+real_url+"]").each(function(){ $(this).css('font-weight', 'bold');});
	
	$("a[href='#']").click(function(){return false;});
	
	
	//##################################################################
	//###  Caroussel simili-flash accueil  #############################
	
	$("#etablir_caroussel img:first").css({'z-index': '3', 'display': 'block'});
	
	function changepicture(){
		var acc_car = $("#etablir_caroussel").children('img:visible');
		acc_car.stop(true, true).fadeOut(2000, function(){
			$(this).attr('style', '');
		}).next().fadeIn(2000,function(){
			$(this).prev().clone().appendTo("#etablir_caroussel");
			$(this).prev().remove();
		});
	}
	
	window.setInterval(changepicture, 3000);
	
	//##################################################################
	//###  Lightbox WebTelecom  ########################################
	
	/*wt_lightbox('.image_clickable');*/
	
	//##################################################################
	//###  Tooltip WebTelecom  #########################################
	
	init_tooltip();
	
	//##################################################################
	//###  Section plan du site  #######################################
	
	$("div.s_plandusite a[href='javascript:;']").css({
		'font-weight':'bold',
		'color':'grey',
		'cursor':'default'
	}).hover(function(){
		$(this).css('text-decoration','none');
	});
	
	//##################################################################
	//###  Input focus in and out  #####################################
	
	$(".text_input").focusin(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('').removeClass('empty_tf');
		}
	});
	
	$(".text_input").focusout(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr('title')).addClass('empty_tf');
		}
	});
	
	//##################################################################
	//###  AJAX Météo  #################################################
	
	/*
	$.ajax({
		type: 'POST',
		url: 'meteo_seeker.php',
		dataType: 'html',
		success: function(html, textStatus){
			$("#meteo_wrapper").html(html);
		},
		error: function(xhr, textStatus, errorThrown){
			alert('An error occurred! ' + (errorThrown ? errorThrown : xhr.status));
		}
	});
	*/
	
	//##################################################################
	//###  Nous joindre  ###############################################
	var anim_en_cours = false;
	$(".lc_header_nousjoindre").click(function(){
		if(anim_en_cours == false)
		{
			anim_en_cours = true;
			var target_div = $(this).attr('targetdiv');
			$(".lc_header_nousjoindre.nj_active").removeClass('nj_active');
			$(this).addClass('nj_active');
			$(".coord_container:visible").fadeOut(500, function(){
				$(target_div).fadeIn(500, function(){
					anim_en_cours = false;
				});
			});
		}
		
	});
	
	$("#nl_submit_button").click(function(){
		ValiderInfoLettre();
	});
});

function affDetail(no){
	
	if (window.document.getElementById("detail_"+no).style.display == 'block'){
		window.document.getElementById("detail_"+no).style.display = 'none';
		//$("#detail_"+no+":visible").show();
		window.document.getElementById("btnDetail_"+no).innerHTML = '&raquo;&nbsp;D&eacute;tails';		
	}else{
		window.document.getElementById("detail_"+no).style.display = 'block';
		window.document.getElementById("btnDetail_"+no).innerHTML = '&raquo;&nbsp;Fermer';		
	}
}

function affAutresDates(no){
	if (window.document.getElementById("AutresDates_"+no).style.display == 'block'){
		window.document.getElementById("AutresDates_"+no).style.display = 'none';
		window.document.getElementById("btnAutresDates_"+no).innerHTML = '&raquo;&nbsp;Toutes les dates';		
	}else{
		
		sendRequest("gestion/calendrier_dates.asp", "AutresDates_"+no, "noDate="+no);
		window.document.getElementById("AutresDates_"+no).style.display = 'block';
		window.document.getElementById("btnAutresDates_"+no).innerHTML = '&raquo;&nbsp;Fermer';
	}	
}

function ValiderInfoLettre(){
	if (isEmail(document.getElementById("email").value)){
		/*postData = '';
		postData += 'langue='+document.getElementById("hidden_infolettre_langue").value;
		postData += '&adresse='+document.getElementById("email").value;*/
		
		var email = $('#email').val();
		var langue = $('#hidden_infolettre_langue').val();
		var type_nl = $("input[name='type_nl']:checked").val();
		
		nbr_input = $("input[name='type_nl']:checked");
		//alert(nbr_input.length);
		
		if(nbr_input.length <= 0){
			alert('Veuillez choisir votre provenance.');
		}else{
			var tmp;
		
			$.ajax({
				type: 'POST',
				url: 'newsletter.php',
				data: {email: email, langue: langue,type_nl: type_nl},
				dataType: 'html',
				success: function(html, textStatus){
					//tmp = html;
					alert(html);
				},
				error: function(xhr, textStatus, errorThrown){
					alert('An error occurred! ' + (errorThrown ? errorThrown : xhr.status));
				}
			});
		}
		
		//tmp = getRequest('newsletter.php', postData);
		//alert(tmp);
		
		//alert("abonnement");
		//document.location.href="default.asp?no=14915&email="+getID("input_infolettre").value;
	}else{
		alert($("#hidden_infolettre_err").val());
	}
	
	return false;
}



