var panneauOuvert = 0;
var total_oeuvre = '';
var nombre_courant = '';
//randomNumber = Math.floor(Math.random() * 10);

function animation() {
    tailleImage();
    if (artiste == 0) {
        $('#bloc_image_dessus').cycle({
            fx: 'scrollLeft',
            speed: 400,
            timeout: 3000,
            before:tailleImage,
            after:tailleImage
          //  startingSlide: randomNumber
        });
        $('#bloc_image_dessous').cycle({
            fx: 'scrollRight',
            speed: 400,
            timeout: 3000
          //   startingSlide: randomNumber
        });

        $('#bloc_image_dessus').cycle('pause');
        $('#bloc_image_dessous').cycle('pause');
    } else {
        $('#bloc_image_full').cycle({
            fx: 'scrollHorz',
            speed: 400,
            timeout: 0,
            before:tailleImage,
            after:tailleImage,
            next: '#next-oeuvre',
            prev: '#prev-oeuvre'
        });
        $('#englobe-legende-title').cycle({
            fx: 'fade',
            speed: 400,
            timeout: 0,
            next: '#next-oeuvre',
            prev: '#prev-oeuvre'
        });
        $('#englobe-legende_slide').cycle({
            fx: 'fade',
            speed: 400,
            timeout: 0,
            next: '#next-oeuvre',
            prev: '#prev-oeuvre',
            height : ''
        });
        $('#englobe-legende-lieu').cycle({
            fx: 'fade',
            speed: 400,
            timeout: 0,
            next: '#next-oeuvre',
            prev: '#prev-oeuvre'
        });
        $('#prev-oeuvre').click(function() {
            total_oeuvre = parseInt($('#nombre-total-oeuvre').html());
            nombre_courant = parseInt($('#id_courant_oeuvre').html());
            $(".voir_plus_legende").each(function() {
                if ($(this).hasClass('open')) {
                    $(this).parent().find('.mini_description_slide').css({'display' : 'block'});
                    $(this).parent().find('.description_slide').css({'display' : 'none'});
                    $('#englobe-legende_slide').animate({height: 40},300);
                    $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende.gif');
                    $(this).removeClass('open');
                }
            });
            if (nombre_courant > 1) {
                $('#id_courant_oeuvre').html(nombre_courant - 1);
            } else {
                $('#id_courant_oeuvre').html(total_oeuvre);
            }
        });
        $('#next-oeuvre').click(function() {
            total_oeuvre = parseInt($('#nombre-total-oeuvre').html());
            nombre_courant = parseInt($('#id_courant_oeuvre').html());
            $(".voir_plus_legende").each(function() {
                if ($(this).hasClass('open')) {
                    $(this).parent().find('.mini_description_slide').css({'display' : 'block'});
                    $(this).parent().find('.description_slide').css({'display' : 'none'});
                    $('#englobe-legende_slide').animate({height: 40},300);
                    $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende.gif');
                    $(this).removeClass('open');
                }
            });
            if (nombre_courant == total_oeuvre) {
                $('#id_courant_oeuvre').html(1);
            } else {
                $('#id_courant_oeuvre').html(nombre_courant + 1);
            }
        });

    }
    hallo();
    $("#legende").hide();


    $("#bt_plus").toggle(function(){
        panneauOuvert = 1;
        tailleImage();
        hauteurContent = $(window).height() - 90;
        $('#content').animate({top: hauteurContent},300, function() {
            if (artiste == 0) {
                $('#bloc_image_dessus').cycle('resume');
                $('#bloc_image_dessous').cycle('resume');
            } else {
                $("#legende").fadeIn(200);
            }
        });
        $('#bt_plus').find('img').attr('src', 'static/images/v2/animation/arrow_top_off.png');
    },function(){
        tailleImage();
        hauteurContent = $(window).height() / 2;
        $('#content').animate({top: hauteurContent},300);
        if (page_artiste) {
            $('#bt_plus').find('img').attr('src', 'static/images/v3/artiste/arrow_bottom_off.png');
        } else if (page_lieu) {
            $('#bt_plus').find('img').attr('src', 'static/images/v3/lieu/arrow_bottom_off.png');
        } else {
            $('#bt_plus').find('img').attr('src', 'static/images/v2/animation/arrow_bottom_off.png');
        }
        panneauOuvert = 0;
        if (artiste == 0) {
            $('#bloc_image_dessus').cycle('pause');
            $('#bloc_image_dessous').cycle('pause');
        } else {
            $("#legende").fadeOut(200);
        }
    });

    $("#bt_plus_roll").mouseover(function () {
        if(panneauOuvert == 0) {
            $(this).attr('src', 'static/images/v2/animation/arrow_bottom_on.png');
        } else {
            $(this).attr('src', 'static/images/v2/animation/arrow_top_on.png');
        }
    });

    $("#bt_plus_roll").mouseout(function () {
        if(panneauOuvert == 0) {
            if (page_un_artiste) {
                $(this).attr('src', 'static/images/v3/artiste/arrow_bottom_artiste_'+language_js+'_off.png');
            }else if (page_artiste) {
                $(this).attr('src', 'static/images/v3/artiste/arrow_bottom_'+language_js+'_off.png');
            } else if (page_un_lieu) {
                $(this).attr('src', 'static/images/v3/lieu/arrow_bottom_'+language_js+'_'+id_lieu+'_off.png');
            } else if (page_lieu) {
                $(this).attr('src', 'static/images/v3/lieu/arrow_bottom_'+language_js+'_off.png');
            } else {
                $(this).attr('src', 'static/images/v2/animation/arrow_bottom_off.png');
            }
        } else {
            $(this).attr('src', 'static/images/v2/animation/arrow_top_off.png');
        }
    });

  /*  $(".voir_plus_legende").toggle(function(){
        $(this).parent().find('.mini_description_slide').css({'display' : 'none'});
        $(this).parent().find('.description_slide').css({'display' : 'block'});
        $(this).parent().parent().animate({height: 370},300);
        $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende-on.gif');
        $(this).addClass('open');
    },function(){
        $(this).parent().find('.mini_description_slide').css({'display' : 'block'});
        $(this).parent().find('.description_slide').css({'display' : 'none'});
        $(this).parent().parent().animate({height: 59},300);
        $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende.gif');
        $(this).removeClass('open');
    });*/

    $(".voir_plus_legende").click(function(){
        var heightAnimate = '';
        if ($(this).hasClass('open')) {
            $(this).parent().find('.mini_description_slide').css({'display' : 'block'});
            $(this).parent().find('.description_slide').css({'display' : 'none'});
            $('#englobe-legende_slide').animate({height: 40},300);
            $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende.gif');
            $(this).removeClass('open');
        } else {
            $(this).parent().find('.mini_description_slide').css({'display' : 'none'});
            $(this).parent().find('.description_slide').css({'display' : 'block'});
            if ($(this).parent().find('.description_slide').height() > 370) {
                heightAnimate = 370;
            } else {
                heightAnimate = parseInt($(this).parent().find('.description_slide').height()) + 20;
            }
            if (heightAnimate < 40) {
                heightAnimate = 40;
            }
            $('#englobe-legende_slide').animate({height : heightAnimate},300);
            $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende-on.gif');
            $(this).addClass('open');
        }
    });

    $(".voir_plus_legende").hover(function() {
        if ($(this).hasClass('open')) {
            $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende-over-on.gif');
        } else {
            $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende-over.gif');
        }
    },function() {
        if ($(this).hasClass('open')) {
            $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende-on.gif');
        } else {
            $(this).attr('src', 'static/images/v3/artiste/voir-plus-legende.gif');
        }
    });

    $("#voir-galerie-artiste img").click(function(){
        if (panneauOuvert == 0) {
            $('html, body').animate({scrollTop:0}, 300);
            setTimeout(function(){
               // hauteurContent = $(window).height() - 90;
                //$('#content').animate({top: hauteurContent},300);
               // $('#bt_plus').find('img').attr('src', 'static/images/v2/animation/arrow_top_off.png');
                //$("#bt_plus").toggle();
                //hauteurLogo = $(window).height() - 346;
                //$('#logo').animate({top: hauteurLogo},300);
                /*setTimeout(function(){
                    $("#legende").fadeIn(200);
                },300);
                panneauOuvert = 1;*/
                $("#bt_plus").click();

            },400);
        } else {
            $('html, body').animate({scrollTop:0}, 400);
        }
    });

}

function hallo() {
    tailleImage();
    if (panneauOuvert == 0) {
        // hauteur logo
        //hauteurLogo = $(window).height()/2 - 257;
        //$('#logo').css({top: hauteurLogo});
        $('#bt_plus').css({top: $(window).height() / 2 -100 });
    } else {
        // hauteur logo
        //hauteurLogo = $(window).height() - 346;
        //$('#logo').css({top: hauteurLogo});
        // position CONTENT
        hauteurContent = $(window).height() - 90;
        $('#content').css({top: hauteurContent});
        $('#bt_plus').css({top: $(window).height() / 2 -100 });
    }
}

function init() {
    window.onresize = hallo;
    hallo();
}

//JavaScript Document
function tailleImage() {
    var screenW = 0, screenH = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        screenW = window.innerWidth;
        screenH = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        screenW = document.documentElement.clientWidth;
        screenH = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 300 compatible
        screenW = document.body.clientWidth;
        screenH = document.body.clientHeight;
    }
    if (artiste == 0) {
        $('.fullscreen').each(function() {
            if (screenH/screenW <= 300/400) {
                //100% largeur
                this.style.width = screenW+"px";
                this.style.height = screenW*300/400+"px";
            } else if (screenH/screenW > 300/400) {
                //100% hauteur
                this.style.width  = screenH*400/300+"px";
                this.style.height = screenH+"px";
            }
        });
        if (screenH/screenW <= 300/400) {
            //100% largeur
            $("#bloc_image_dessus").css({width: screenW });
            $("#bloc_image_dessus").css({height: screenW*300/400 });
        } else if (screenH/screenW > 300/400) {
            //100% hauteur
            $("#bloc_image_dessus").css({width: screenH*400/300 });
            $("#bloc_image_dessus").css({height: screenH });
        }

        $('.bloc_fullscreen').each(function() {
            if (screenH/screenW <= 300/400) {
                //100% largeur
                $(this).css({width: screenW });
                $(this).css({height: screenW*300/400 });
            } else if (screenH/screenW > 300/400) {
                //100% hauteur
                $(this).css({width: screenH*400/300 });
                $(this).css({height: screenH });
            }
        });
    } else {
        var id;
        var id_entier;
        var tab = new Array();
        var compteur = 0;
        var hack_nombre_courant = parseInt($('#id_courant_oeuvre').html());
        $('.bloc_fullscreen').each(function() {
            $(this).css({width: screenW });
            id = parseInt($(this).attr('id').substring(8));
            tab[compteur] = id;
            compteur++;
        });
        $('.fullscreen').each(function() {
            if ($(this).parent().attr('id') == 'img_oeu_'+tab[(hack_nombre_courant - 1)]) { // moins car le nombre courant demarre a 1
                if ($(this).attr('src') == "") {
                    $(this).attr('src', list_img[tab[(hack_nombre_courant - 1)]]);
                }
            } else if ($(this).parent().attr('id') == 'img_oeu_'+tab[(hack_nombre_courant >= tab.length ? 0 : hack_nombre_courant)]) { // juste nombre courant car 1 d'avance
                if ($(this).attr('src') == "") {
                    $(this).attr('src', list_img[tab[hack_nombre_courant]]);
                }
            } else if ($(this).parent().attr('id') == 'img_oeu_'+tab[((hack_nombre_courant - 1) == 0 ? (tab.length - 1) : (hack_nombre_courant - 2))]) { // on verifie que ci on recule de un on ne soit pas le dernier de l liste
                if ($(this).attr('src') == "") {
                    $(this).attr('src', list_img[tab[((hack_nombre_courant - 1) == 0 ? (tab.length - 1) : (hack_nombre_courant - 2))]]);
                }
            } else {
                if ($(this).attr('src') != "") {
                    $(this).attr('src', '');
                }
            }
            $(this).css({width: screenW });
        });
    }
}

<!--
function MM_reloadPage(init) {
    //reloads the window if Nav300 resized
    if (init==true) with (navigator) {
        if ((appName=="Netscape")&&(parseInt(appVersion)==300)) {
            document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
        }
    } else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
    MM_reloadPage(true);
//-->

