$( function(){


    //visionneuse ajax
    $.fn.image = function(src, f){
        return this.each(function(){
          $(this).each(function(){
                  this.src = src;
                  this.onload = f;
          });
        });
    }

    $(".image").attr("visibility","hidden").fadeTo(0,0.1).image( $("#visionneuse .image").attr("src"), function(){
        $(this).fadeTo("fast",1);
        })





    var lastImage = $(".list").length-1; //n¡ de la derniere image
    
    var url = document.location.search;
    if (url.match('image=')){
        var indice = url.indexOf('image=')+6;
        var cur = url.substring(indice,url.length);
        var current = parseInt(cur);
    }else{
        var current = 0;
    }
    
    function affiche (img){
        $(".image").fadeTo("slow",0.1,function(){
            $(this).image($(".list:eq("+img+")").attr("href"), function(){
                 $(this).fadeTo("fast",1);
        });
            })
        current = img;
        $(".compteur").html(img+1+"/"+$(".list").length);
    }
    
    
    $(".suiv").click(function(){
        if(current == lastImage){
            var suiv = 0;
        }else{
            var suiv = current+1;
        }
        affiche(suiv);
        return false;
        });
    
    $(".prec").click(function(){
        if (current == 0){
            var prec = lastImage;
        }else{
            var prec = current-1;
        }
        affiche(prec);
        return false;
        });
    
    //survols

    
    $(".goto img").hover(function(){
        $(this).hide().attr("src","images/presentationS.png").fadeIn("70");
    }, function(){
        $(this).fadeOut("fast", function(){
            $(this).attr("src","images/presentation.png").show();   
            });
    });
    $(".acceuil img").hover(function(){
        $(this).attr("src","images/accueilS.png");
    }, function(){
        $(this).attr("src","images/accueil.png");   
    });
    $(".prec img").hover(function(){
        $(this).attr("src","images/precS.png");
    }, function(){
        $(this).attr("src","images/prec.png");   
    });
    $(".suiv img").hover(function(){
        $(this).attr("src","images/suivS.png");
    }, function(){
        $(this).attr("src","images/suiv.png");   
    });
    $("#savoirfaire img").hover(function(){
        $(this).attr("src","images/savoirFaireS.jpg");
    }, function(){
        $(this).attr("src","images/savoirFaire.jpg");   
    });    
    $("#portfolio img").hover(function(){
        $(this).attr("src","images/portfolioS.jpg");
    }, function(){
        $(this).attr("src","images/portfolio.jpg");   
    });        
    $("#aPropos img").hover(function(){
        $(this).attr("src","images/aProposS.jpg");
    }, function(){
        $(this).attr("src","images/aPropos.jpg");   
    });    
    //Devis
    $(".pour").hide();
    $(".devis input").toggle(function(){
        $(".pour").slideDown("slow",function(){
            $("#ffdemande_de_devis").attr("checked", "checked");
            });
    },function(){
        $(".pour").slideUp("fast",function(){
            $("#ffdemande_de_devis").attr("checked", "");
            });
            });

    // Menu
    $(".sectionheader ul").hide();
    $(".sectionheader p").hover(function(){
        //$(".sectionheader ul:visible").slideUp("slow");
        $(this).next().slideDown("slow")
    });

});