//--------------------------------------------------------------------
//-------------------------Librairie accueil JS-----------------------
//--------------------------------------------------------------------

var pos_ct = 2;
var pos_pro = 2;
var timer_cadre;
var cadre_actif;
var cadre_inactif;
//-------------------------   Initialisation de la page d'accueil   ------------------------------
function init_accueil() {
  
  $(".cadre_pliant div#txt_pro2, .cadre_pliant div#txt_ct2").hide();
  
  $(".cadre_pliant").hover(function() {
    
    var class_hover = $(this).attr("id")+"_hover";
    if(!$(this).hasClass(class_hover) ) $(this).addClass(class_hover);

    var tab_type = $(this).attr("id").split("_");
    cadre_actif = tab_type[1];
    
    if(timer_cadre != "undefined") clearTimeout(timer_cadre);
    timer_cadre = setTimeout("montre_cadre()", 250); 
      
    },function() {
      
      var class_hover = $(this).attr("id")+"_hover";
      if($(this).hasClass(class_hover) ) $(this).removeClass(class_hover);

      var tab_type = $(this).attr("id").split("_");
      cadre_inactif = tab_type[1];
    
      if(timer_cadre != "undefined") clearTimeout(timer_cadre);
      timer_cadre = setTimeout("masque_cadre()", 250); 
      
    }
  );
  
  init_highlight_form();
 
  maj_partenaires();
  //Initialisation de la visionneuse de média
  init_visu_creation();
  
  //-----------------Clique sur les partenaires
  $("#partenaires").click(function() {
    window.location.href = "index.php?p=11";
  });
  
  //-----------------Survol du bouton quickTour
  var _action = false;
  $("a#acces_demo").hover(function()  {
  
    if(!_action) {
      _action = true;
      $("img",this).fadeOut("fast", function() {
        _action = false;
      }); 
    }
   },function(){

      _action = true;
      $("img",this).fadeIn("fast", function() {
        _action = false;
      });
     
   });
  //Connexion
  var options_pseudo = { 
    target:    '#erreur_login',
    dataType:  'json', 
    beforeSubmit:  function() {

     var verif_form =  verif_form_id();
     
     if(verif_form) $.blockUI({message : "<h4>"+cst_connexion+"</h4>"});
     else return false;
    }, 
    success:  function(data_json)  {
     
      switch(data_json.etat)  {
      
        case false : 
          clignote("erreur_login", data_json.message);
          $.blockUI({message : "<h4>"+data_json.message+"</h4>"});
          setTimeout($.unblockUI, 1000); 
         
        break;
        
        case true : 
          //$.blockUI();
          window.location.href = data_json.url;
        break;
      }
       
    }
  };
  $("#form_connexion").ajaxForm(options_pseudo); 

} //Fin init


//-----------------Paramètres des partenaires
var tab_partenaires = ["ressources/partenaires/mini_sacd.gif", "ressources/partenaires/mini_region.gif", "ressources/partenaires/mini_sacem.gif"];
var num_image = Math.floor(Math.random() * tab_partenaires.length);

//------------------------------------------------------------------------------------------------
//------------------- Fonction qui met à jour les images des partenaires  ------------------------
//------------------------------------------------------------------------------------------------
function maj_partenaires()  {
  
if(num_image<tab_partenaires.length) {
 // alert("num_image> "+num_image+" tab_partenaires[i] "+tab_partenaires[i]);
}
else {
  num_image = 0;
}
  //alert("num_image> "+num_image+" tab_partenaires[i] "+tab_partenaires[num_image]);
  $("#partenaires").attr("src", tab_partenaires[num_image]);
  num_image++;
  setTimeout(maj_partenaires, 3000);
}


//------------------------------------------------------------------------------------------------
//-------------------------------   Fonction qui montre un cadre   -------------------------------
//------------------------------------------------------------------------------------------------
function montre_cadre()  {

  if(timer_cadre != "undefined") clearTimeout(timer_cadre);

  switch(cadre_actif) {
  
    case "ct" :
    
      switch(pos_ct)  {
      
        case 1 :
          //On affiche tout du bloc CT
          $(".cadre_pliant div#txt_ct1, .cadre_pliant div#txt_ct2").show("fast", function()  {
            pos_ct = 3;
          });
          //On masque tout chez le PRO
          switch(pos_pro)  {
          
            case 1 :
            case 2 :
              //$("#sortie_js").prepend("<br />--------AHHHH ER CT 1!!!------<br />");
            break;
            
            case 3 :
              $(".cadre_pliant div#txt_pro1, .cadre_pliant div#txt_pro2").hide("fast", function()  {
                pos_pro = 1;
              });
            break;
          }
        break;
        
        case 2 :
          $(".cadre_pliant div#txt_ct2").show("fast", function()  {
            pos_ct = 3;
          });
          //On masque tout chez le PRO
          switch(pos_pro)  {
          
            case 1 :
            case 3 :
              //$("#sortie_js").prepend("<br />--------AHHHH  ER CT 2!!!------<br />");
            break;
            
            case 2 :
              $(".cadre_pliant div#txt_pro1, .cadre_pliant div#txt_pro2").hide("fast", function()  {
                pos_pro = 1;
              });
            break;
          }
        break;
        
        case 3 :
          //$("#sortie_js").prepend("<br />-------- RIEN CT DEJA ACTIF ------<br />");
        break;
      }
    break;
    
    case "pro" :
      switch(pos_pro)  {
        
        case 1 :
          $(".cadre_pliant div#txt_pro1, .cadre_pliant div#txt_pro2").show("fast", function()  {
            pos_pro = 3;
          });
          //On masque tout chez le CT
          switch(pos_ct)  {
          
            case 1 :
            case 2 :
              //$("#sortie_js").prepend("<br />--------AHHHH ER PRO 1!!!------<br />");
            break;
            
            case 3 :
              $(".cadre_pliant div#txt_ct1, .cadre_pliant div#txt_ct2").hide("fast", function()  {
                pos_ct = 1;
              });
            break;
          }
        break;
        
        case 2 :
          $(".cadre_pliant div#txt_pro2").show("fast", function()  {
            pos_pro = 3;
          });
          //On masque tout chez le CT
          switch(pos_ct)  {
          
            case 1 :
            case 3 :
              //$("#sortie_js").prepend("<br />--------AHHHH  ER PRO 2!!!------<br />");
            break;
            
            case 2 :
              $(".cadre_pliant div#txt_ct1, .cadre_pliant div#txt_ct2").hide("fast", function()  {
                pos_ct = 1;
              });
            break;
          }
        break;
        
        case 3 :
          //$("#sortie_js").prepend("<br />-------- RIEN PRO DEJA ACTIF ------<br />");
        break;
      }
    break;
  }
}

//------------------------------------------------------------------------------------------------
//---------------------------   Fonction qui masque un cadre   ---------------------
//------------------------------------------------------------------------------------------------
function masque_cadre()  {

  if(timer_cadre != "undefined") clearTimeout(timer_cadre);

  switch(cadre_inactif) {
  
    case "ct" :
    
      switch(pos_ct)  {
      
        case 1 :
          $(".cadre_pliant div#txt_ct1").show("fast", function()  {
            pos_ct = 2;
          });
          //On masque moitie chez le PRO
          switch(pos_pro)  {
        
            case 1 :
            case 2 :
              //$("#sortie_js").prepend("<br />--------AHHHH  ER CT 1-2!!!------<br />");
            break;

            case 3 :
              $(".cadre_pliant div#txt_pro2").hide("fast", function()  {
                pos_pro = 2;
              });
            break;
          }
        break;
        
        case 2 :
          //$("#sortie_js").prepend("<br />-------- RIEN CT DEJA INACTIF ------<br />");
        break;
        
        case 3 :
          //On masque le bloc 2 du CT
          $(".cadre_pliant div#txt_ct2").hide("fast", function()  {
            pos_ct = 2;
          });
          //On masque moitie chez le PRO
          switch(pos_pro)  {
          
            case 1 :
              $(".cadre_pliant div#txt_pro1").show("fast", function()  {
                pos_pro = 2;
              });
            break;
            case 2 :
            case 3 :
              //$("#sortie_js").prepend("<br />--------AHHHH ER CT 2-3!!!------<br />");
            break;
          }
          
        break;
      }
    break;
    
    case "pro" :
      switch(pos_pro)  {
        
        case 1 :
          $(".cadre_pliant div#txt_pro1").show("fast", function()  {
            pos_pro = 2;
          });
          //On masque moitie chez le CT
          switch(pos_ct)  {
        
            case 1 :
            case 2 :
              //$("#sortie_js").prepend("<br />--------AHHHH  ER PRO 1-2!!!------<br />");
            break;

            case 3 :
              $(".cadre_pliant div#txt_ct2").hide("fast", function()  {
                pos_ct = 2;
              });
            break;
          }
        break;
        
        case 2 :
          //$("#sortie_js").prepend("<br />-------- RIEN PRO DEJA INACTIF ------<br />");
        break;
        
        case 3 :
          //On masque le bloc 2 du PRO
          $(".cadre_pliant div#txt_pro2").hide("fast", function()  {
            pos_pro = 2;
          });
          //On masque moitie chez le CT
          switch(pos_ct)  {
          
            case 1 :
              $(".cadre_pliant div#txt_ct1").show("fast", function()  {
                pos_ct = 2;
              });
            break;
            case 2 :
            case 3 :
              //$("#sortie_js").prepend("<br />--------AHHHH ER PRO 2-3!!!------<br />");
            break;
          }
          
        break;
      }
    break;
  }
}

//-------------------------------------Initialisation de la  visualisation d'une création (homepage)
function init_visu_creation() {

  $(".media_visionneuse").click(function() {

    var url_visu_creation = $(this).attr("href");

    var largeur = $(this).prev().prev().prev().val();
    var hauteur = $(this).prev().prev().val();
    
    var format = $(this).prev().val(); 
    var image = $("img", this).attr("src");
    
    var opts_visio = { 
        width : largeur,
        height : hauteur, 
        url_page :  url_visu_creation,
        file_format : format,
        image : image,
        activ_inscr : true
    };
  
    $(this).visionneuse(opts_visio); 
      
    return false;

  });   //Fin click
  
}

