$(document).ready(function() {
  
  // Hide iPhone Toolbar
  setTimeout(function() {
		window.scrollTo(0,0);
	},250); 
	
	// Supprimer du panier
	$('a.delete').click(function() {
	 switch(langue) {
	   case 'fr': var message = 'Êtes-vous sûr de vouloir effacer cette espèce?'; break;
	   case 'en': var message = 'Are you sure you want to delete this species?'; break;
	 }
	 return confirm(message); 
  });
  
  // Accueil popups
  $('body#bindex #main #blocks a').hover(
    function(){
      var p = $(this).position();
      var article = $(this).find('article');
      article.css({opacity:0, visibility:'visible', left: p.left + 'px', top: p.top + 9 - article.outerHeight() + 'px'})
        .animate({top: '-=10', opacity: '1'}, 250);
    },
    function(){
      $(this).find('article')
      .animate({top: '+=120', opacity: '0'}, {duration:250, callback:function(){ $(this).css('visibility', 'hidden')}});
    }
  );
  
  // Tris
  $('body#brev #pays,body#brev #tri').change(function(){
    var pays = $('#pays').val();
    var tri = $('#tri').val();
    window.location = page + '?pays=' + pays + '&tri=' + tri;
  });
  
  // Galerie
  $('body#bgal a.genre').click(function() {
    var $this = $(this);
    $('a.genre').removeClass('active');
    $('#galerie,#especes').empty();
    $this.addClass('active');
    var id = $this.attr('id').split('-');
    if ($this.hasClass('phytesia')) {
      $.get(basepath + "ajax/galerie-phytesia.php?genre=" + id[1] + "&titre=" + $this.attr('rel') + "&langue=" + langue, function(data){
        $("#galerie").html(data);
        window.location='#galerie';
      });
    } else {
      $.get(basepath + "ajax/galerie-especes.php?genre=" + id[1] + "&titre=" + $this.attr('rel') + "&langue=" + langue, function(data){
        $("#especes").html(data);
      });
    }
    return false;
  });
  
  $('body#bgal a.espece').live('click', function() {
    var $this = $(this);
    $('a.espece').removeClass('active');
    $this.addClass('active');
    var id = $this.attr('id').split('-');
    $.get(basepath + "ajax/galerie-photos.php?espece=" + id[1] + "&titre=" + $this.attr('rel') + "&langue=" + langue, function(data){
      $("#galerie").html(data);
      window.location='#galerie';
    });
    return false;
  });
  
  // Culture hover
  $('body#bcul .stade a').hover(
    function() {
      $(this).siblings('img').fadeIn(250);
    },
    function() {
      $(this).siblings('img').fadeOut(250);
    }
  );
	
});
