// Après chargement de la page
$(function() {
	
	
	$("#alerte_email").click(function(e) {
		
		$('#contact_cadre_formulaire_alerte_email form#formulaire_alerte_email').css('display', 'block');
		
		$('#contact_cadre_formulaire_alerte_email div#am-contact-encours').hide();
			
		$('#contact_cadre_formulaire_alerte_email div#am-contact-ok').hide();
		
		$("#contact_cadre_formulaire_alerte_email").lightbox_me({
			centered: false,
			overlayCSS : {background: '#fff', opacity: .6},
			modalCSS : {top: 250},
			onClose	: function() {
				$("#am-choix-recherche-type").fadeOut('slow');
				$("#am-choix-recherche-prix").fadeOut('slow');
				$("#am-choix-recherche-loc").fadeOut('slow');				
				$('#formulaire_alerte_email').validationEngine('hide');
			}
        });
		e.preventDefault();
	});
	
	
	$("#formulaire_alerte_email").validationEngine({
		ajaxFormValidation: true,
		onBeforeAjaxFormValidation: AMail_beforeCall,
		onAjaxFormComplete: AMail_ajaxValidationCallback
	});
	

	function AMail_beforeCall(form, options) {
	
		$('#contact_cadre_formulaire_alerte_email form#formulaire_alerte_email').fadeOut('fast', function() {

			$('#contact_cadre_formulaire_alerte_email div#am-contact-encours').fadeIn('fast', function() {});

		});
	
	}
	
	
	function AMail_ajaxValidationCallback(status, form, json, options) {
	        
		$('#contact_cadre_formulaire_alerte_email form#formulaire_alerte_email').fadeOut('fast', function() {

			$('#contact_cadre_formulaire_alerte_email div#am-contact-encours').fadeOut('fast', function() {
			
				$('#contact_cadre_formulaire_alerte_email div#am-contact-ok').fadeIn('slfastow', function() {});

			});
			
		});
	
	}
	
	// Champs
	$("#am-recherche-type").click(function(e) {
		
		var offset = $("#menu_entete2").offset();
		
		$("#am-choix-recherche-type").lightbox_me({
			showOverlay : false,
			modalCSS : {top: offset.top + 50},
			onClose	: function() {
			
				//$("#formulaire_alerte_email").append( $("#am-choix-recherche-type") );
				
				$("#am-choix-recherche-type-bloc").append( $("#am-choix-recherche-type").html() );
							
			}
		});
		
		e.preventDefault();
		
	});
	
	$("#am-choix-recherche-type-valider").click(function(e) {
		
		$("#am-choix-recherche-type").trigger('close');
			
		e.preventDefault();
		
	});
	
	$("#am-recherche-prix").click(function(e) {
		
		var offset = $("#menu_entete2").offset();
		
		$("#am-choix-recherche-prix").lightbox_me({
			showOverlay : false,
			modalCSS : {top: offset.top + 50},
			onClose	: function() {
			
				$("#am-choix-recherche-prix-bloc").append( $("#am-choix-recherche-prix").html() );
				
			}
		});
		
		e.preventDefault();
		
	});
	
	$("#am-choix-recherche-prix-valider").click(function(e) {
		
		$("#am-choix-recherche-prix").trigger('close');
			
		e.preventDefault();
		
	});
	
	$("#am-recherche-loc").click(function(e) {
		
		var offset = $("#menu_entete2").offset();
		//var largeur = $("#canvas").width();
		
		$("#am-choix-recherche-loc").lightbox_me({
			showOverlay : false,
			modalCSS : {top: offset.top + 50},
			onClose	: function() {
			
				$("#am-choix-recherche-loc-bloc").append( $("#am-choix-recherche-loc").html() );
				
			}
		});
		
		e.preventDefault();
		
	});
	
	$("#am-choix-recherche-loc-valider").click(function(e) {
		
		$("#am-choix-recherche-loc").trigger('close');
			
		e.preventDefault();
		
	});
	
});
