// MAM-Agency Scripts
jQuery.noConflict();
//jQuery.easing.def = "easeOutQuad";

jQuery(document).ready(function($){

  $(".navigation img").mouseover(function(e){
    $(this).attr('src', $(this).attr('src'));
    $(this).css('margin-top', '-20px'); // correction d'un bug IE6?
  }).mouseout(function(){ // IE6
    if($(this).hasClass('on')) $(this).css('margin-top', '-40px');
    else $(this).css('margin-top', '0');
  });
  
  // les plus de la table des noms
  var blank = $("#list img:first").attr('src'); // on récupère le nom
  if(blank != null) var pluss = blank.replace(/blank/i, 'static');

  $("#list a")
    .bind("mouseenter", function(e){
      $(this).css('background-image', 'url('+blank+')');
      $("img", this).stop().fadeTo(50, .2).fadeTo(400, 1);
    }).bind("mouseleave", function(e){
      $("img", this).stop().fadeTo(50, .6).fadeTo(300, 0);
    })
    .find("img").fadeTo(10, 0).attr('src', pluss);
    
  // RIDEAU EN JS PUR
  //
  // dois virer l'animation sur les liens Lightwindow
  // genre .not('.lw') voir ci-dessous
  //
  // ANIMATION
  var speed = 700;
  // au chargement de la page
  $('#indicator').hide();
  $('#topcurtain').animate({
    height: '1px'
  }, speed, 'easeOutQuad');
  $('#downcurtain').animate({
    height: '1px',
    top: '567px'
  }, speed, 'easeOutQuad', function() {
    $('#curtain').hide();
  });
  // pour les liens
 $('a.closecurtain').click(function(){ 
    var hrefLoc = $(this).attr('href');
    regex = /^http:\/\//i;
    if(!regex.test(hrefLoc)) { // ne sert plus
      $('#curtain').show();
      $('#bio').css('overflow', 'hidden'); // bug FF...
      $('#topcurtain').animate({
        height: '216px'
      }, speed, 'easeOutQuad');
      $('#downcurtain').animate({
        height: '216px',
        top: '344px'
      }, speed, 'easeOutQuad', function(){ 
        window.location = hrefLoc; 
        $('#indicator').show();
      }); 
      return false; 
    } 
  }); 
  
  // FORMULAIRE
  $('#ctcform').submit(function(){
    var error = false;
    var inred = 'contact-obligatoire';
    var nom = jQuery.trim($('form #nom').val());
    var email = jQuery.trim($('form #email').val());
    var zmess = jQuery.trim($('form #zemessage').val());
    $('b.'+inred).remove();
    if(nom == '') {
      error = true;
      $('form #nom').parents('td').append('<b class="'+inred+'"><br />Vous devez indiquer votre nom</span>');
    } else {
      error = false;
      if(email == '') {
        error = true;
        $('form #email').parents('td').append('<b class="'+inred+'"><br />Vous devez indiquer votre email</span>');
      } else {
        regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
        if(!regex.test(email)) {
          error = true;
          $('form #email').parents('td').append('<b class="'+inred+'"><br />Vous devez indiquer un email valide</span>');
        } else {
          error = false;
          if(zmess == '') {
            error = true;
            $('form #zemessage').parents('td').append('<b class="'+inred+'"><br />Laissez-nous un petit message...</span>');
          } else {
            error = false;
          }
        }
      }
    }
    if(!error) return true;
    else return false; 
  });
});