// JavaScript Document
$(function() {
		   
	$(".vimeo").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 700,
			'height'		: 394,
			'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?autoplay=1&clip_id=$1'),
			'type'			: 'swf'
		});
 
		return false;
	});



	$('.cycle').cycle('fade');
	
	$('#golf a,#quartier a,#pecaudy a').hover(function () {
	    $(this).effect("bounce", { times:1, distance:10 }, 500);
	}); 	
	
	
	$("#header #menu li a").click(function(){
		switch($("#header #menu li a").index(this))
		{
		case 0:
		  $("#slider").animate({left:"-1000px"});
		  break;
		case 1:
		  $("#slider").animate({left:"-2000px"});
		  break;
		case 2:
		  $("#slider").animate({left:"-3000px"});
		  break;
		case 3:
		  $("#slider").animate({left:0});
		  break;
		default:
		  return
		}
		
		$("#header #menu li a:lt(4)").css("font-weight","normal");
		$(this).css("font-weight","bold");
		
	});
	
	$("#footer #menu li a").click(function(){
		$("#header #menu li a:lt(4)").css("font-weight","normal");
		switch($("#footer #menu li a").index(this))
		{
		case 0:
		  $("#slider").animate({left:0});
		  $("#header #menu li a:eq(3)").css("font-weight","bold");
		  break;
		case 1:
		  $("#slider").animate({left:"-1000px"});
		  $("#header #menu li a:eq(0)").css("font-weight","bold");
		  break;
		case 2:
		  $("#slider").animate({left:"-2000px"});
		  $("#header #menu li a:eq(1)").css("font-weight","bold");
		  break;
		case 3:
		  $("#slider").animate({left:"-3000px"});
		  $("#header #menu li a:eq(2)").css("font-weight","bold");
		  break;
		default:
		  return
		}
		
		
		
	});	
	
	
    $('a.email').each(function(i) {
        var text = $(this).text();
        var address = text.replace(" at ", "@");
        $(this).attr('href', 'mailto:' + address);
            $(this).text(address);
    });
	
	$('input,textarea[title!=""]').hint();



	//if submit button is clicked
	$('#button').click(function () {
								 
		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var phone = $('input[name=phone]');
		var comment = $('textarea[name=message]');

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if (name.val()=='' || name.val()==name.attr("title")) {
			name.addClass('highlight');
			return false;
		} else name.removeClass('highlight');
		
		if (phone.val()=='' || phone.val()==phone.attr("title")) {
			phone.addClass('highlight');
			return false;
		} else email.removeClass('highlight');

		if (email.val()=='' || email.val()==email.attr("title")) {
			email.addClass('highlight');
			return false;
		} else email.removeClass('highlight');
		
		if (comment.val()=='' || comment.val()==comment.attr("title")) {
			comment.addClass('highlight');
			return false;
		} else comment.removeClass('highlight');
		
		//organize the data properly
		var data = 'name=' + name.val() + '&phone=' + phone.val() + '&email=' + email.val() + '&message='  + encodeURIComponent(comment.val());
		
		//disabled all the text fields
		$('.text').attr('disabled','true');
		
		//show the loading sign
		$('#form').fadeTo("slow", 0.8); 

			
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "/includes/process.php",	
			
			//GET method is used
			type: "GET",

			//pass the data			
			data: data,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {				
				//if process.php returned 1/true (send mail success)
				if (html==1) {					
					//hide the form
					$('form').fadeOut('slow');					
					
					//show the success message
					$('#done').fadeIn('slow');
					
				//if process.php returned 0/false (send mail failed)
				} else 
				alert('Désolé, un erreur est survenue. Veuillez réessayer plus tard.');
				$("#form").fadeTo("slow",1);
			}		
		});
		
		//cancel the submit button default behaviours
		return false;
	});	


});

