/* 
	© fmv Group
	
*/

$(document).ready(function(){

	

	// scroll event
	
	
	// $("#left_hand").hide();
	// $("#right_hand").hide(); 
   
   
   $(window).scroll(function () { 

		var pageScrl = $(document).scrollTop() + 30; 
		$("#left_hand").stop().fadeIn("normal").animate({top:pageScrl+'px'},600);
		$("#right_hand").stop().fadeIn("normal").animate({top:pageScrl+'px'},600);
		
		/* if(pageScrl == 30){
			$("#left_hand").fadeOut("normal");
			$("#right_hand").fadeOut("normal");
		} */
    
	});

	// auto grow
	
	$("textarea").ata(function(){
	
		
	
	});
	
	/* contact form */
	
	
	var selected = $("#option1").text();
	$("#option1").hide();
	
	$('.select span:first').html(selected);
	

	
	$('.select').click(function(){
		
		$(this).children('.dropPane').slideDown("fast");
	
	},600);	
	
	$('.select').mouseleave(function(){
	
		$(this).children('.dropPane').slideUp("fast");
	
	});
	
	$('.dropPane li').click(function(e){
	
		
		
		$('.select').children('.dropPane').hide();
		var newSelected = $(this).text();
		$('.select span:first').html(newSelected);
		
		$('.dropPane li').show();
		$(this).hide();
		
		
		var newSelected = $(this).attr("id");
		if(newSelected == "option1"){
			$('.line').show();
			$("#contactby").val("option1");
		}
		if(newSelected == "option2"){
			$('.line').show();
			$('.email_action').hide();
			$("#contactby").val("option2");
		}		
		if(newSelected == "option3"){
			$('.line').show();
			$('.phone_action').hide();
			$("#contactby").val("option3");
		}
	
		e.stopPropagation();
		
	});
	
	// spam protect
	

	var $email = $("#email");  
	var address = $email.text()
		.replace(/\s*\publishing\s*/, '@')   
			.replace(/\s*\[dot\]\s*/g, '.');  
				$email.html('<a href="mailto:' + address + '">'  
				 + address +'</a>');  
				 
});


// 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(){
	   
				var nom = $("#nom").val();
				var prenom = $("#prenom").val();
				var contactby = $("#contactby").val();
				var email = $("#email").val();
				var tel = $("#tel").val();
				var from = $("#from").val();
				var to = $("#to").val();
				var message = $("#message").val();
				
			
				var query = 'nom='+nom+'&prenom='+prenom+'&contactby='+contactby+'&email='+email+'&tel='+tel+'&from='+from+'&to='+to+'&message='+message;
				$("#load").fadeIn("fast");
			
				
				$.post('ajax/mail.php',query,function(data){
				
					$('#callback').html(data);
					$("#load").fadeOut("fast");
					
				});
				
				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);

