/* 
	© fmv Group
	
*/

$(document).ready(function(){

	// spam protect
	
	var $email = $("#email");  
	var address = $email.text()
		.replace(/\s*\publishing\s*/, '@')   
			.replace(/\s*\[dot\]\s*/g, '.');  
				$email.html('<a href="mailto:' + address + '.mt">'  
				 + address +'.mt</a>');  
				 
	$("#data_bar").show();
	
	/* Services slider init */
	
	$('#accroche span').fadeIn("slow");
	$('#accroche span').slideDown("normal");
	
	$('.service:first').show();
	
	
	/* Main menu jFade effect */
	
	$("ul.main.infog li").not("#current").not(".sub").jFade({
		trigger: "mouseover",
		property: 'background',
		start: '0B2231',
		end: '1D577E',
		steps: 20,
		duration: 25
	}).jFade({
		trigger: "mouseout",
		property: 'background',
		start: '1D577E',
		end: '0B2231',
		steps: 20,
		duration: 10
	});	
	
	$("ul.main:first li").not("#current").not(".sub").jFade({
		trigger: "mouseover",
		property: 'background',
		start: '0f1d27',
		end: '8d160f',
		steps: 20,
		duration: 25
	}).jFade({
		trigger: "mouseout",
		property: 'background',
		start: '8d160f',
		end: '0f1d27',
		steps: 20,
		duration: 10
	});
	

	// content correction
	
	var mainH = $("ul.main:first").outerHeight(true) + $("ul.main.infog").outerHeight(true) + 160 ;
	var contentH = $("div.main_box").outerHeight(true) - 40 ;

		if(mainH > contentH){
			
			$("div.main_box").css({height:mainH+'px'});
			
		}

	$("#logo").mouseenter(function(){
		$(this).find('span').fadeIn("normal");
	});	
	
	$("#logo").mouseleave(function(){
		$(this).find('span').fadeOut("normal");
	});
	



	// Toogle contact
	
		$("#TooglePhone").click(function(){
		
		
			var CurrentClass = $(this).attr("class");
			if(CurrentClass == 'options'){
			
				$(this).children('.slide').animate({left:'1px'}, 450);
				$(this).addClass('off');
				$().find('#phoneData').slideDown("normal");
				$("div.main_box").css({paddingBottom:'60px'});
			
			
			}else{
			
				
				$(this).children('.slide').animate({left:'47px'}, 450);
				$(this).removeClass('off');
				$().find('#phoneData').hide();
				$("div.main_box").css({paddingBottom:'40px'});
				
			}
		
		});
		 
				 

	// Toogle reserve
	
	
		$("#reserveToogle").toggle(function(){
		   
		   $(this).addClass('clicked');
		   $("#reserve").slideDown("normal");
		   return false;
		   
		 },function(){
		    $(this).removeClass('clicked');
		    $("#reserve").slideUp("fast");
		    return false;
		   
		 });
 
	   $("#Toogle").click(function(){ $("#reserveToogle").click(); return false;	});
	   
	   
	   $("#next.step1").click(function(){
	   
			
			sendMail(1);
	   
	   });
	   
	   $('textarea').ata();
	   $('input').toggleVal();
	   $('textarea').toggleVal();
	   
	   


});


// Contact form
	   
		// Checking if a field is empty, is not return true.
		
		function isEmpty(aTextField){
			
			if ( $(aTextField).length > 0 ) {
			
			    valueText = $(aTextField).val();
				var re = /\s/g; 
				var str =  valueText.replace(re, "");
				if (str.length == 0) {
				return true;
				} else { return false; }
			}
			else{
				return false;
			}
			
		}


	   function sendMail(step){
	   
			$("#next").addClass('clicked');
			
			if(step == 1){
			
			$("input").css({fontWeight:'normal',color:'#7a828e'});
			
			var genre = $("#genre").val();
			var nom = $("input[name='nom']").val();
			var prenom = $("input[name='prenom']").val();
			var tel = $("input[name='tel']").val();
			var from = $("input[name='from']").val();
			var to = $("input[name='to']").val();
			var email = $("input[name='email']").val();
			var pays = $("#pays").val();
			var region = $("input[name='region']").val();
			var phone = $("input[name='tel']").attr("class");			
			var region = $("input[name='region']").val();
			var phone = $("#TooglePhone").attr("class");
			var activitee = $("#activitee").val();
			var attentes = $("#attentes").val();

			$.post("./ajax/step1.php",{genre:genre,nom:nom,prenom:prenom,tel:tel,from:from,to:to,email:email,pays:pays,region:region,phone:phone,activitee:activitee,attentes:attentes},
													   
				function(data){
					
					$("#eval").html(data);
					
					$("#next").removeClass('clicked');

				});
				
				return false;
			}
		
		}


/* Delayed Mouse effect */

(function($) {
 
  $.fn.delayedMouseEnter = function(callback, options) {
 
	var options = $.extend({ delay: 200 }, options);
 
	return this.not("span").each(function() {
		var obj = $(this);
		var timer = false;
		obj.mouseenter( function(event) {
			if(timer) clearTimeout(timer);
			timer = setTimeout( function() { callback.apply(obj[0], [event]); }, options.delay );
		});		
		obj.mouseleave( function(event) {
			if(timer) clearTimeout(timer);
			timer = false;
		});		
	});
  };
 
})(jQuery);

(function($) {
 
  $.fn.delayedMouseLeave = function(callback, options) {
 
	var options = $.extend({ delay: 300 }, options);
 
	return this.not("span").each(function() {
		var obj = $(this);
		var timer = false;
		obj.mouseleave( function(event) {
			if(timer) clearTimeout(timer);
			timer = setTimeout( function() { callback.apply(obj[0], [event]); }, options.delay );
		});		
		obj.mouseenter( function(event) {
			if(timer) clearTimeout(timer);
			timer = false;
		});		
	});
  };
 
})(jQuery);

