/* 
	© fmv Group
	
*/

$(document).ready(function(){

	/* Services slider init */
	
	$('.service:first').show();
	
	
	/* Main menu jFade effect */
	
	$("ul#main li").not("#current").not(".sub").jFade({
		trigger: "mouseover",
		property: 'background',
		start: '7E848F',
		end: '5F646D',
		steps: 20,
		duration: 25
	}).jFade({
		trigger: "mouseout",
		property: 'background',
		start: '5F646D',
		end: '7E848F',
		steps: 20,
		duration: 10
	});
	

	// content correction
	
	var mainH = $("ul#main").outerHeight(true);
	var contentH = $("div.main_box").outerHeight(true) - 100 ;

		if(mainH > contentH){
			
			$("div.main_box").css({height:mainH+50+'px'});
			
		}

	$("#logo").mouseenter(function(){
		$(this).find('span').fadeIn("normal");
	});	
	
	$("#logo").mouseleave(function(){
		$(this).find('span').fadeOut("normal");
	});
	


	// 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>');  
				 
				 
				 

	// 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;	});



});


// 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(){
	   
			$('.outterInput').removeClass('error');
			$('.errorFlag').hide();
			
			if(isEmpty("#name")){

				var oI = $('#name').parents('.outterInput');
				var oW = oI.outerWidth();
				
				$(oI).addClass('error');	
			
				$(oI).find('.errorFlag').show().animate({left:oW+20+'px'},100).animate({left:oW+'px'},100).animate({left:oW+20+'px'},100).animate({left:oW+'px'},100);
				
				return false;

			}
			else{
			
			
				if(isEmpty("#email_champs")){

							if(isEmpty("#tel_champs")){
									
									var oI = $('#email_champs').parents('.outterInput');
									var oI2 = $('#tel_champs').parents('.outterInput');
									
									var oW = oI.outerWidth();
									
									$(oI).addClass('error');
									$(oI2).addClass('error');	
									
									$(oI).find('.errorFlag').css({bottom:'-44px'}).show().animate({left:oW+20+'px'},100).animate({left:oW+'px'},100).animate({left:oW+20+'px'},100).animate({left:oW+'px'},100);
									
									return false;
								
								}

							}
							else{
							
								
								if(isEmpty("#message")){
									
									var oI = $('#message').parents('.outterInput');
									var oW = oI.outerWidth();
									
									$(oI).addClass('error');	
								
									$(oI).find('.errorFlag').css({bottom:'80px'}).show().animate({left:oW+20+'px'},100).animate({left:oW+'px'},100).animate({left:oW+20+'px'},100).animate({left:oW+'px'},100);
									
									return false;
								
								}
								else{
										return true;
								}
							}
			
			}

		
		}

/* 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);
