$(document).ready(function(){
    $('.obli').focusin(function(){
        $(this).attr("required","");        
    });       
    $("#nom").blur(function(){        
        if(!$("#nom").val().match(/^[a-zA-Z]+$/i)){
            var next = $("#nom").next().next(".erreur");
            next.fadeIn().text("Veuillez entrez un nom correct");
            $("#nom").css("border","2px dashed #E00D4E");
    
        }
        else{
            $("#nom").next().next(".erreur").hide().text("");
            $("#nom").css("border","2px solid #9D9D9D");
        }
    });
    $("#mail").blur(function(){
        if(!$("#mail").val().match(/^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/i)){
            $("#mail").next().next(".erreur").fadeIn().text("Veuillez entrez une adresse mail valide");
        }
        else{
            $("#mail").next().next(".erreur").hide().text("");
        }
    });
    $("#telephone").blur(function(){
        if(!$("#telephone").val().match(/^0[1-68][0-9]{8}$/i)){
            $("#telephone").next().next(".erreur").fadeIn().text("Veuillez entrez un numero de téléphone valide")
            $("#telephone").css("border","2px dashed #E00D4E");
        }
        else{
            $("#telephone").next().next(".erreur").hide().text("");
            $("#telephone").css("border","2px solid #9D9D9D");
        }
    });
    $("#message").blur(function(){
        if(($("#message").html().length) < 1){
            $("#message").next().next(".erreur").fadeIn().text("Veuillez entrez un commentaire");
        }
        else{
            $("#message").next().next(".erreur").hide().text("");
        }
    }); 
    $("formulaire-contact").bind("submit", function(){
        var bReturn = true;

        if ( jQuery.trim($("#nom").val()).length==0 ) {
            $("#nom").next().next(".erreur").fadeIn().text("Veuillez entrez un nom");
            bReturn = false;
        }
        
        if ( jQuery.trim($("#mail").val()).length==0 ) {
            $("#mail").next().next(".erreur").fadeIn().text("Veuillez entrez une adresse mail");
            bReturn = false;
        }

        if ( jQuery.trim($("#message").val()).length==0 ) {
            $("#message").next().next(".erreur").fadeIn().text("Veuillez entrez un commentaire");
            bReturn = false;
        }

        return bReturn;
    });

    var tailleMoveSlide=-694;
    var cpt = 0;
    var nb = $('#photo ul.#slideshow li').length;
   
    anim = function() {
        
        $('#photo ul.#slideshow').stop().animate({
            'left' : tailleMoveSlide*cpt
        },1500);
        
        //alert('#pagination ul li#'+cpt)
        $('#pagination ul li').each(function(i){
            $(this).addClass("other");
            // alert($(this).attr('id')+"  "+cpt);
            if($(this).attr('id') == cpt){

                $(this).addClass("active");
                $(this).removeClass("other");
                
            }
            else{
                //$('#pagination ul li#'+cpt).addClass("other");
                $(this).removeClass("active");
            //alert("ELSE--->"+$(this).attr('id')+"  "+cpt);
            }
        });
        cpt++;
        
        if(cpt>=nb) {
            cpt = 0;
        }
        t = setTimeout(anim,3000);
    };
    anim();
    $('#photo').hover(function(){
        clearTimeout(t);
        $('#photo ul.#slideshow').stop();
    },function(){
        anim();
    });

    $('#pagination ul li').click(function(e){
        var id = $(this).attr('id');
        clearTimeout(t);
        $("#photo ul.#slideshow").stop()
        .animate({
            'left': tailleMoveSlide* id
        }, 1500);
        $('#pagination ul li').each(function(){
            $(this).removeClass("active");
            $(this).addClass("other");
        });
        $(this).addClass("active");
        cpt = $(this).attr('id');
        t = setTimeout(anim,3000);
        e.preventDefault();
    });
    google.maps.event.addDomListener(window, 'load', initialisation)
});

function initialisation(){
    var centreCarte = new google.maps.LatLng(45.823177,4.950775);
    var optionsCarte = {
        zoom: 10,
        center: centreCarte,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var maCarte = new google.maps.Map(document.getElementById("map"), optionsCarte);
    var marqueurImage = new google.maps.MarkerImage('images/pic.png');
    var optionsMarqueur = {
        position: centreCarte,
        map: maCarte,
        icon: marqueurImage,
        title: "E-Boutique Lyon"
    }
    var marqueur = new google.maps.Marker(optionsMarqueur);
    var contenuInfoBulle = '<h1 id="infobulle">E-Boutique-lyon</h1>';
    var infoBulle = new google.maps.InfoWindow({
        content: contenuInfoBulle        
    })
    google.maps.event.addListener(marqueur, 'click', function() {
        infoBulle.open(maCarte, marqueur);
    });
   
}





