$(document).ready(function() {    
    
    /*$('.test1')
        .css( {backgroundPosition: "0 0"} )
        .mouseover(function(){
            $(this).stop().animate({backgroundPosition:"0 -545px)"}, {duration:500})
        })
        .mouseout(function(){
            $(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:200, complete:function(){
                $(this).css({backgroundPosition: "0 0"})
            }})
        })   */   
   
    chgBGConfig('#bt_grand', 58, 348, 30);
    chgBGConfig('#bt_petit_1', 55, 330, 30);
    chgBGConfig('#bt_petit_2', 55, 330, 30);
                     
    /*chgBGAuto('.test3', 56, 336, 100, 50, 0, 0, 0);  */  
    
    //applique un lien à l'élément parent d'une balise a
    $('.bt_grand').click(function() { $(this).find('a').each(function(){ window.location = this.href; }); }); 
});  

//charge la fonction d'animation des boutons
/*
element : element 
h : hauteur d'un morceau d'image
hmax : hauteur de l'image
vitesse : vitesse du mouvement
*/
function chgBGConfig(element, h, hmax, v) {
    $(element).hover(
        function() {
            chgBGHover(element, h, (hmax-1), v, 0, 0, 0);
        }, 
        function() {
            chgBGHover(element, h, hmax, v, -hmax, 1, 0);      
        }
    );
}

/*
fonction d'animation des boutons 

element : l'element 
h : hauteur d'un morceau d'image
hmax : hauteur de l'image
vitesse : vitesse du mouvement
position : position de départ du mvt
sens : sens du mouvement (attention a la position de départ, (-h))
tour : variable pour démarrer/arréter le mvt
*/
function chgBGHover(element, h, hmax, vitesse, position, sens, tour) {
    if(sens == 0){
        position -= h;
        if(position < -hmax) tour=1;    
    }
    if(sens == 1){
        position += h;
        if(position > 0) tour=1;
    } 
    if(tour == 0){
        $(element).stop(true,true).css({backgroundPosition: "center "+position+"px"});   
        setTimeout("chgBGHover('"+element+"', "+h+", "+hmax+", "+vitesse+", "+position+", "+sens+", "+tour+");", vitesse);         
    }  
}


/*
chamgement automatique de la position d'un bg

element : l'element  
h : hauteur d'un morceau d'image
hmax : hauteur de l'image
vitesse : vitesse du mouvement
nb_tour : nombre de tour avant l'arret du mvt 
position : position de départ du mvt
tour : sens du mvt
compteur : variable pour l'arret du mvt
   */                                    
function chgBGAuto(element, h, hmax, vitesse, nb_tour, position, tour, compteur) {
    if(tour == 0){
        position -= h;
        if(position <= -hmax) tour=1;    
    }
    if(tour == 1){
        position += h;
        if(position == 0) tour=0;
    } 
    $(element).stop(true,true).css({backgroundPosition: "0 "+position+"px"})   
    compteur += 1;
    if(compteur < nb_tour) setTimeout("chgBGAuto('"+element+"',"+h+","+hmax+","+vitesse+","+nb_tour+","+position+","+tour+","+compteur+");", vitesse); 
}



//popup div
function AJAX_div(doc, form) {
    ART_ajax(doc, 'AJAX_contenu', form);
        
    var top = $(document).scrollTop()+200; 
    $("#AJAX_contenu").animate({
        top: top+"px"
    }, 2000 );
    $("#AJAX_div").height($(document).height()); 
    $("#AJAX_div").fadeIn('slow');             
}

function closeDiv() {
    $('#AJAX_div').fadeOut('slow', function () {
        $('#AJAX_contenu').css('top', "0px"); 
    }); 
              
}


//selecteur de pays
function moveDiv(id, hgt) {
    if($('#selectDIV_'+id).css('height') != hgt+'px'){
        $('#selectDIV_'+id).animate({height: hgt+'px'}, 500);  
        $('#selectLEG_'+id).text('-'); 
    }else{
        $('#selectDIV_'+id).animate({height: '12px'}, 500); 
        $('#selectDIV_'+id).scrollTop(0);
        $('#selectLEG_'+id).text('+');
    }
}


//initialise le formulaire d'envoi des documents
function goForm(type, txt) {
    $('#'+type).html(''); 
    $('#form_document').ajaxForm({
        beforeSubmit: function() {
            $('#'+type).html(txt);
        },
        target: '#'+type
     });  
} 
