 $(document).ready(function() {
/*
    if ( $.browser.msie ) {
        $("div#contentsFrame").show();
    } else {
        $("div#contentsFrame").fadeIn('4000');
    }
*/

    if ($("div.vignetteRond").length){


        //$("div.vignetteRond a").hide();

        $("div.vignetteRond").hover(
            function(){
                // non IE
               // $(this).children("a").fadeIn('3000');

               // IE
               $(this).children("a").css({'visibility':'visible'}); //how();
            },
            function(){
                // non IE
                //$(this).children("a").fadeOut();

                // IE
                //$(this).children("a").hide();
                $(this).children("a").css({'visibility':'hidden'}); //how();
            }

        );
    }

    if ($("div#info").length){

      //if ( $.browser.msie ) {


        $("div#info").hover(
            function(){
                $("div#projetInfo").css({'visibility':'visible'}); //show();
                //$("div#projetInfo").addClass("afficher");
            },
            function(){
                $("div#projetInfo").css({'visibility':'hidden'}); //hide();
                //$("div#projetInfo").removeClass("afficher");
            }
        );


      //} else {

//        $("div#info").hover(
//            function(){
//                $("div#projetInfo").fadeIn('5000');
//                $("div#projetInfo").addClass("afficher");
//            },
//            function(){
//                $("div#projetInfo").fadeOut();
//                $("div#projetInfo").removeClass("afficher");
//            }
//        );
//
//      }

        
       // pour iPad (pas de hover)
       /*
        $("div#info").click(
            function(){
                if ($("div#projetInfo").hasClass("afficher")){
                    $("div#projetInfo").fadeOut();
                    $("div#projetInfo").removeClass("afficher");
                } else {
                    $("div#projetInfo").fadeIn('7000');
                    $("div#projetInfo").addClass("afficher");
                }
                
            }
        );
        */
    }

     if ($("div#imageProjet").length){

        $('div#imageProjet').preloader(
            {loader: 'images/preloader.gif'}
        );
     }
     
     if ($("div#imageProjet").length){

        $("div.img-container").hide();
        $("div.img-container.img-1").show();

     }

     if ($("div#projetNav").length){

        $("img#next_img").click(
            function(){

                image_en_cours = image_en_cours+1;
                image_maxi = $("span#counter").attr("class");

                // securite mais n'arrive jamais car on cache le bouton
                if (image_en_cours > parseInt(image_maxi)){
                    image_en_cours = 1;
                    $("img#next_img").show();
                    $("img#prev_img").hide();
                }
                // afficher les 2 boutons
                if (image_en_cours > 1){
                    $("img#next_img").show();
                    $("img#prev_img").show();
                }
                // cacher le bouton suivant pour la derniere image
                if (image_en_cours == image_maxi){
                    $("img#next_img").hide();
                    $("img#prev_img").show();
                }
                $("div.img-container").hide();
                $("div.img-container.img-"+image_en_cours).fadeIn('9000');

                if (image_en_cours >= 10){
                    $("div#counter_container").css('paddingLeft', '6px');
                } else {
                    $("div#counter_container").css('paddingLeft', '10px');
                }
                $("span#counter").text(image_en_cours);

            }
        );


        $("img#prev_img").click(
            function(){

                image_en_cours = image_en_cours-1;
                image_maxi = $("span#counter").attr("class");

                // securite mais n'arrive jamais car on cache le bouton
                if (image_en_cours == 0){
                    image_en_cours = image_maxi;
                    $("img#next_img").hide();
                    $("img#prev_img").show();
                }
                // afficher les 2 boutons
                if (image_en_cours < image_maxi){
                    $("img#next_img").show();
                    $("img#prev_img").show();
                }
                // premiere image, on cache bouton precedent
                if (image_en_cours == 1){
                    $("img#next_img").show();
                    $("img#prev_img").hide();
                }


                $("div.img-container").hide();
                $("div.img-container.img-"+image_en_cours).fadeIn('9000');

                if (image_en_cours >= 10){
                    $("div#counter_container").css('paddingLeft', '6px');
                } else {
                    $("div#counter_container").css('paddingLeft', '10px');
                }
                $("span#counter").text(image_en_cours);
                
            }
        );



     }


// ACCUEIL

     if ($("div#imageAccueil").length){

        $("div.img-container").hide();
        $("div.img-container.img-1").fadeIn('9000');

        image_maxi = $("span#counter").attr("class");

        var delai_image = 4000;
        var delai_entre_2_images = 4000;

        // demarrer a 2 car image 1 deja affichee
        for (var i=2; i<=image_maxi; i++){
            
            setTimeout("afficher_image("+i+")",delai_image);
            delai_image = delai_image + delai_entre_2_images;
        }

     }


// PUBLICATIONS

    if ($("div.publiInfo_btn").length){


    // non IE
/*
        $("div.publiInfo_btn").hover(
            function(){
                $(this).next(".publiInfo").fadeIn('7000');
                $(this).next(".publiInfo").addClass("afficher");
            },
            function(){
                $(this).next(".publiInfo").fadeOut();
                $(this).next(".publiInfo").removeClass("afficher");

            }
        );
  */
 // IE => mettre tout en dur

         $("div#publiInfo_btn_0").hover(
            function(){
                $("#publiInfo_0").css({'visibility':'visible'}); //show();
            },
            function(){
                $("#publiInfo_0").css({'visibility':'hidden'}); //hide();

            }
        );
         $("div#publiInfo_btn_1").hover(
            function(){
                $("#publiInfo_1").css({'visibility':'visible'}); //show();
            },
            function(){
                $("#publiInfo_1").css({'visibility':'hidden'}); //hide();

            }
        );
         $("div#publiInfo_btn_2").hover(
            function(){
                $("#publiInfo_2").css({'visibility':'visible'}); //show();
            },
            function(){
                $("#publiInfo_2").css({'visibility':'hidden'}); //hide();
            }
        );

    }

// LISTE DES PUBLICATIONS ET DES EXPOSITIONS

    if ($(".liste_desc").length){
        $('.liste_desc').jScrollPane({
            //showArrows: true

        });
    }




 });


var image_en_cours = 1;
var image_maxi = 1;


function afficher_image(img_index){
    //alert ("attente terminee");
    $("div.img-container").hide();
    $("div.img-container.img-"+img_index).fadeIn('9000');
}
