
/* +++++++++++++++++++++++++++++++++++
   ++[FONCTIONS DE NAVIGATION      ]++
   ++++++++++++++++++++++++++++++++ */

window.addEvent('domready', function()
{
  $$('#Nav .color1 a').each(function(el)
  {
	el.FXbg         = new Fx.Tween(el,{duration: 600});
	el.FXfont       = new Fx.Tween(el,{duration: 250});
	
	//$ Boutons sous-menu couleur 1
	el.addEvents(
	{
	'mouseover' :function(){
			this.FXbg.cancel();
			this.FXfont.cancel();
			this.FXbg.start('background-color','#8cc81f');
			this.FXfont.start('color','#ffffff');
		},
	'mouseout' :function(){
			this.FXbg.cancel();
			this.FXfont.cancel();
			this.FXbg.start('background-color','#ffffff');
			this.FXfont.start('color','#8cc81f');
		}
	});
  });
  
  $$('#Nav .color2 a').each(function(el)
  {
	el.FXbg         = new Fx.Tween(el,{duration: 600});
	el.FXfont       = new Fx.Tween(el,{duration: 250});
	
	//$ Boutons sous-menu couleur 1
	el.addEvents(
	{
	'mouseover' :function(){
			this.FXbg.cancel();
			this.FXfont.cancel();
			this.FXbg.start('background-color','#fb037e');
			this.FXfont.start('color','#ffffff');
		},
	'mouseout' :function(){
			this.FXbg.cancel();
			this.FXfont.cancel();
			this.FXbg.start('background-color','#ffffff');
			this.FXfont.start('color','#fb037e');
		}
	});
  });
  
  $$('#Nav .col').each(function(el)
  {
    var aLink         = el.getElements('.off');
    var bLink         = aLink[0];
    var aLayer        = el.getElements('.srub');
    var aAnimLayer    = el.getElements('.layer-srub');
    var aMask         = el.getElements('.mask');

    //$ Animation sur le bouton
    el.FXButton       = new Fx.Tween(bLink,{duration: 250});

    //$ S'il n'y a pas de menu
    if(aLayer.length == 0)
    {
      //$ Méthode lorsque la souris passe sur le bouton
      el.overButton   = function(){this.FXButton.cancel();this.FXButton.start('background-position','0px 15px');}

      //$ Méthode lorsque la souris sort du le bouton
      el.outButton    = function(){this.FXButton.cancel();this.FXButton.start('background-position','0px 0px');}
    }
    else
    {
      //$ Récupération des informations
      var bLayer      = aLayer[0];
      var bMask       = aMask[0];
      var bAnimLayer  = aAnimLayer[0];

      //$ Initialisation de l'état ouverture/fermeture
      el.bCanClose    = false;

      //$ Changer l'état ouverture/fermeture
      el.stopClose    = function(){this.bCanClose = false;}
      el.startClose   = function(){this.bCanClose = true;}

      //$ Evenement sur la vague
      bMask.addEvents(
      {
        'mouseover' :function(e){e.stop();this.overButton();}.bind(el),
        'mouseout': function(e){e.stop();this.outButton();}.bind(el)
      });

      //$ Préparation de l'animation de la vague
      bMask.myFx      = new Fx.Morph(bMask);
      el.FXMask       = new Fx.Tween(bMask,{duration: 500});
      el.bLayer       = bLayer;

      //$ Evenement sur le menu
      bAnimLayer.addEvents(
      {
        'mouseover' :function(e){e.stop();this.overButton();}.bind(el),
        'mouseout': function(e){e.stop();this.outButton();}.bind(el)
      });

      //$ Préparation de l'animation du layer
      bAnimLayer.myFx = new Fx.Morph(bAnimLayer);
      el.FXLayer      = new Fx.Tween(bAnimLayer,{duration: 500});
      el.bAnimLayer   = bAnimLayer;
	  el.FXLayer.addEvent('onComplete', function(e){
	     if(this.bAnimLayer.getStyle('top').toInt() == -99){
			 this.bLayer.setStyle('display','none');
		 } 
	  }.bind(el));


      //$ Méthode lorsque la souris passe sur le bouton
      el.overButton = function()
      {
        //$ Arrêter la fermeture
        this.stopClose();

        //$ Animation sur le bouton
        this.FXButton.cancel();
        this.FXButton.start('background-position','0px 15px');
		
		this.bLayer.setStyle('display','block');
		
        //$ Animation de la vague
        this.FXMask.cancel();
        this.FXMask.start('top','0px');

        //$ Animation du layer
        this.FXLayer.cancel();
        this.FXLayer.start('top','-15px');
      }

      el.closeMenu  = function()
      {
        //$ Si on peut fermer
        if(this.bCanClose == true)
        {
          //$ Animation sur le bouton
          this.FXButton.cancel();
          this.FXButton.start('background-position','0px 0px');

          //$ Animation de la vague
          this.FXMask.cancel();
          this.FXMask.start('top','-14px');

          //$ Animation du layer
          this.bLayer.setStyle('display','block');
          this.FXLayer.cancel();
          this.FXLayer.start('top','-99px');
        }
      }

      //$ Méthode lorsque la souris sort du le bouton
      el.outButton  = function()
      {
        this.startClose();
        this.closeMenu.delay(300,this);
      }
    }

    //$ Evenement sur le bouton
    bLink.setStyle('background-position','0px 0px').addEvents(
    {
      'mouseover' :function(e){e.stop();this.overButton();}.bind(el),
      'mouseout': function(e){e.stop();this.outButton();}.bind(el)
    });
  });

/* +++++++++++++++++++++++++++++++++++
   ++[/FONCTIONS DE NAVIGATION     ]++
   ++++++++++++++++++++++++++++++++ */
});

