$(function () {

    // lightbox initialize
    $('#work .blocWork1 a').lightBox();
	$('#work .blocWork2 a').lightBox();
	$('#work .blocWork3 a').lightBox();
	$('#work .blocWork4 a').lightBox();
	$('#work .blocWork5 a').lightBox();
	$('#work .blocWork6 a').lightBox();
	$('#work .blocWork7 a').lightBox();
	$('#work .blocWork8 a').lightBox();
	$('#work .blocWork9 a').lightBox();
	$('#work .blocWork10 a').lightBox();
	$('#work .blocWork11 a').lightBox();
	$('#work .blocWork12 a').lightBox();
	
	//$("div.blocWork").css({ opacity: 0.7 });

    // hover div work
    $("div.blocWork,div.blocWork1,div.blocWork2,div.blocWork3,div.blocWork4,div.blocWork5,div.blocWork6,div.blocWork7,div.blocWork8,div.blocWork9,div.blocWork10,div.blocWork11,div.blocWork12").mouseover(function () {
        $(this).css("background-color", "#14d8cd");
        $(this).children(".texteTitreWork").css("color", "#eeeeee");
		//$(this).css({ opacity: 1 });
    }).mouseout(function () {
        $(this).css("background-color", "transparent");
        $(this).children(".texteTitreWork").css("color", "#14d8cd");
		//$(this).css({ opacity: 0.7 });
    });
    $('.error').hide();

    // btn submit
    $(".sendBTN").click(function () {
        $('.error').hide();
        var name = $("input#name").val();
        var email = $("input#email").val();
        var message = $("#message").val();

        // validate input name
        validateName = function () {
            if (name.length < 3) {
                $("label#error").show();
                $("label#error").html("Veuillez rentrer un nom valide.");
                $("input#name").focus();
                return false;
            }
            else {
                $('.error').hide();
                validateEmail1();
            }
        }

        // validate input email 1
        validateEmail1 = function () {
            if (email.length < 3) {
                $("label#error").show();
                $("label#error").html("Veuillez rentrer un courriel valide.");
                $("input#email").focus();
                return false;
            }
            else {
                $('.error').hide();
                validateEmail2();
            }
        }

        // validate input email 2 
        validateEmail2 = function () {
            if (isValidEmailAddress(email) != true) {
                $("label#error").show();
                $("label#error").html("Veuillez rentrer un courriel valide.");
                $("input#email").focus();
                return false;
            } else {
                $('.error').hide();
                validateMessage();
            }
        }

        // validate input message
        validateMessage = function () {
            if (message.length < 3) {
                $("label#error").show();
                $("label#error").html("Veuillez rentrer un message valide.");
                $("#message").focus();
                return false;
            } else {
                $('.error').hide();
                sendEmail();
            }
        }

        // on execute la premiere fonction de validation
        validateName();
        return false; 
		/* fermeture $(".sendBTN").click) */
    });

    ///////////////////////// Functions /////////////////////////


    // execute php send email page
	function sendEmail() {
        $.post("js/send_form_email.php", {
            name: $("#name").val(),
            email: $("#email").val(),
            message: $("#message").val()
        }, function (data) {
            if (data) {
                // show div in effect
                $(".error").html('Courriel envoyé!');
                $(".error").show();
                // clear fields
                $("input#name").attr("value", "");
                $("input#email").attr("value", "");
                $("#message").attr("value", "");
            }
        });
        return false;
    }

    // reg exp email
    function isValidEmailAddress(emailAddress) {
        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        return pattern.test(emailAddress);
    }

    /* fermeture $(function() */
});
