/**/
$(document).ready(function() {
  $('div#informations-close').css('left',$('div#menu').position().left + $('div#menu1').position().left + $('div#menu1').width() + 20);
  $('div#informations-close').corner('bottom 5px');

  $('li#aussi').click(function() {
    show_arrow($(this));
    $('div#informations').find('div.body').load('informations/'+lang+'/aussi.php',function() {
      $('html,body').animate({scrollTop: 0}, 500);
      $('div#informations').slideDown('slow',function() {
        btncards();
      });
      equipeCarousel();

    });
  });

  $('li#newsletter').click(function() {
    show_arrow($(this));
    $('div#informations').find('div.body').load('informations/'+lang+'/newsletter.php',function() {
      $('html,body').animate({scrollTop: 0}, 500);
      $('div#informations').slideDown('slow',function() {
        btncards();
      });
      equipeCarousel();

    });
  });

  $('li#equipe').click(function() {
    show_arrow($(this));
    $('div#informations').find('div.body').load('informations/'+lang+'/equipe.php',function() {
      $('html,body').animate({scrollTop: 0}, 500);
      $('div#informations').slideDown('slow',function() {
        btncards();
      });
      equipeCarousel();
        
    });
  });
  $('li#contact').click(function() {
    show_arrow($(this));
    $('div#informations').find('div.body').load('informations/'+lang+'/contact.php',function() {
      $('html,body').animate({scrollTop: 0}, 500);
      $('div#informations').slideDown('slow',function(){
         btncards();
      });
     
    });
  });
  $('a#fcontact').click(function() {
    show_arrow($(this));
    $('div#informations').find('div.body').load('informations/'+lang+'/contact.php',function() {
      $('html,body').animate({scrollTop: 0}, 500);
      $('div#informations').slideDown('slow',function(){
         btncards();
      });
    });
  });
  $('li#liens').click(function() {
    show_arrow($(this));
    $('div#informations').find('div.body').load('informations/'+lang+'/liens.php',function() {
      $('html,body').animate({scrollTop: 0}, 500);
      $('div#informations').slideDown('slow',function(){
         btncards();
      });
    });
  });
  $('li#biblio').click(function() {
    show_arrow($(this));
    $('div#informations').find('div.body').load('informations/'+lang+'/biblio.php',function() {
      $('html,body').animate({scrollTop: 0}, 500);
      $('div#informations').slideDown('slow',function(){
         btncards();
      });
    });
  });
  
  $('div#informations-close').click(function() {
    
    $('div#informations').slideUp('slow',function() {
        $('div#informations').find('div.body').empty();
      btncards();
    });

  })
  $('li.menu1').mouseenter(function() {
    show_arrow($(this));
  });
  $('li.menu1').mouseleave(function() {
    $('img#menu1arrow').hide();
  });
  
  $('div#boxes div.box').mouseenter(function() {
    var img = $(this).find('img.title');
    if (img.attr('rel')) {
      img.attr('src','images/acceuil/titre-'+img.attr('rel')+'-g.jpg');
    }
    $(this).find('img.plus').attr('src','images/acceuil/plus-g.jpg');
    $(this).addClass('over');
    $(this).css('cursor','normal');
  });
  $('div#boxes div.box').mouseleave(function() {
    var img = $(this).find('img.title');
    if (img.attr('rel')) {
      img.attr('src','images/acceuil/titre-'+img.attr('rel')+'.jpg');
    }
    $(this).find('img.plus').attr('src','images/acceuil/plus.jpg');
    $(this).removeClass('over');
    $(this).css('cursor','normal');
  });
});

function show_arrow(element) {
  var left = (element.position().left + (element.width() / 2) + $('img#menu1arrow').width()) + 'px';
  var top = (element.position().top - element.height()) + 'px';
  $('img#menu1arrow').css( { "left": left, "top": top } );
  $('img#menu1arrow').fadeIn('fast');
}

function btncards() {
  if (!$('div#cards').length) return false;
  var r = ($('div#cards').position().left + $('div#cards').width() + 25);
  var l = ($('div#cards').position().left - $('img#agleft').width() - 25);
  var t = ($('div#cards').position().top + $('div.card').height() / 2);
  $('div#card-right').css('left',r);
  $('div#card-right').css('top',t);
  $('div#card-left').css('left',l);
  $('div#card-left').css('top',t);
}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
