// JavaScript Document

var animationFrise = {

  drapeauStatique: 0,
   
  testeAnimation: function (param) {
      if ( param == 'Bienvenue') {
          if ( this.drapeauStatique == 0 ) {
              $('frise_gauche').style.background = "url(pochoirs/frise_gauche_anime100.gif) repeat-y left";
              $('frise_droite').style.background = "url(pochoirs/frise_droite_anime100.gif) repeat-y right";
             
              this.drapeauStatique = 1;
                           
          }
          else {
              $('frise_gauche').style.background = "url(pochoirs/frise_gauche_blanc.gif) repeat-y left";
              $('frise_droite').style.background = "url(pochoirs/frise_droite_blanc.gif) repeat-y right";

              this.drapeauStatique = 0;          
          }         
      }
      return true;
  } 
}

var compteurStatique = {
/* Objet pour la gestion des photos grand format:
   te tableau contient les images TRES grand format.
   Tant que le tableau contient une valeur, le paragraphe "right" reste large.
   Dès que le tableau est vide on réduit le paragraphe "right" à l'origine. 
*/

  tabFenetre: new Array(), // empile les noms d'image
  tabFenetreGF: new Array(),  // empile les noms d'image Grand Format
 
  testeImage: function (image, larg_low, haut_low, larg, haut, largeur_max, largeur_min) {

      var index = this.tabFenetre.indexOf(image);
      var indexGF = this.tabFenetreGF.indexOf(image);
                 
      var imghaut = "imghaut"+image ;
      var imgbas = "imgbas"+image ;      
      if ( index == -1 ) {
      // si l'image n'est pas encore recencée (donc actuellement en petit format) 
        this.tabFenetre.push(image);                                          
        
        if (larg >= 463 ) {                          
          $('right').hide(); 
          $('left').morph('width:734px;');
          $('coin_bas_droit').morph('margin-left:598px;');
          this.tabFenetreGF.push(image);        
        } 
        $(image).morph('width:'+larg+'px; height:'+haut+'px;');
        $(imghaut).morph('width:'+largeur_max+'px;'); 
        $(imgbas).morph('width:'+largeur_max+'px;');        
      }
      else {
      // si l'image est déjà recencée (donc déjà grand format)
        this.tabFenetre[index] = null; 
        this.tabFenetre = this.tabFenetre.compact();        
        $(image).morph('width:'+larg_low+'px; height:'+haut_low+'px;'); 
        $(imghaut).morph('width:'+largeur_min+'px;'); 
        $(imgbas).morph('width:'+largeur_min+'px;'); 
        if (larg >= 463 ) { 
          this.tabFenetreGF[indexGF] = null; 
          this.tabFenetreGF = this.tabFenetreGF.compact();         
          if (! (this.tabFenetreGF.length) ) {
            $('left').morph('width:520px;');
            $('coin_bas_droit').morph('margin-left:383px;');
            Element.show.delay(0.8, 'right');               
          }           
        }       
      }         
  },
  
  init: function () {
    this.tabFenetre.clear();
    this.tabFenetreGF.clear();        
    $('left').style.width="520px" ;
    $('right').show();
  }
    
};

function mainPage (page) {

	var url = 'charge_page.php?page='+page;
	new Ajax.Request(url, {
		asynchronous:true,  
      method: 'post', 
		onLoading: function() { Effect.Appear('iconeChargePage'); },
		onFailure: function() {
		        alert('Une Erreur AJAX s\'est produite, veuillez r&eacute;essayer svp...');
		},		  
  	 	onComplete: function(transport) {	    		      
			   var repondu = transport.responseText;
         $('page').innerHTML = repondu;               
         $('titreSousMenu').innerHTML = " : " + page;                  

         Effect.Fade('iconeChargePage');                     
      }		      	
	}); 
}

function mainMenu (titre) {

  function recursif (Json, indice) {	
      for (var i=indice ; i < Json.length ; i++) {
          var page = Json[i];  
          
          var test = 0;
          if (page.valeur[0]==undefined) test=1; // Firefox
          if (test!=1 && page.valeur[0].valeur==undefined) test=2; // Firefox

          if ( test==1 || test==2) {         
              $('listeSousMenu').innerHTML += '<ul><li><a href="#" onClick="mainPage(\''+page.valeur+'\'); animationFrise.testeAnimation(\''+page.valeur+'\')">'+page.titre+'</a></li></ul>';
/*   copie ok: $('listeSousMenu').innerHTML += '<li><a href="#" id="'+page.valeur+'" onClick="mainPage(\''+page.valeur+'\')">'+page.titre+'</a></li>'; */                  
          }
          else { 
              recursif(page.valeur,0);
          }          
      }
      return true;
  }

	var url = 'charge_sous_menu.php?page='+titre;
	new Ajax.Request(url, {
		asynchronous:true,  
      method: 'post', 
		onLoading: function() { Effect.Appear('iconeChargeSousMenu'); },
		onFailure: function() {
		        alert('Une Erreur AJAX s\'est produite, veuillez r&eacute;essayer svp...');
		},		  
  	 	onComplete: function(transport) {	    		      
        var repondu = transport.responseText;
       	var objJson = eval ('('+ repondu +')');
        if (objJson) {				
            $('listeSousMenu').innerHTML = '';
            var sousTitre = objJson[0];
            $('titreMenu').innerHTML = sousTitre.titre;	    
            recursif(objJson,1);
           // $('listeSousMenu').innerHTML += '';            
        }           
        Effect.Fade('iconeChargeSousMenu');
    }                  	      	
	});        
}
