function set_photo_size(photo_id)
{
  //alert($(window).height());

  if(photo_id.substring(0,5) == 'goto_')
  {
    $('#'+photo_id).attr('href', 'photos/photo_' + photo_id.substring(5) + '_resize_h-' + ((Math.floor($(window).height()/50) - 1)*50) + '.jpg');
  }
}

function OpenMaxWindow(requested_url)
{
  winWidth = screen.width;
  winHeight = screen.height;

  MaxWindow = window.open(requested_url,'MaxiWindow','toolbar=no,location=no,scrollbars=yes,resizable=yes,width='+winWidth+',height='+winHeight+',left=0,top=0');
  MaxWindow.focus();
}

// Optimisation selon http://www.lejournaldublog.com/jquery-les-bonnes-pratiques/
$(document).ready(function(){
  //$('#showcase a').lightBox();   
   
  
  // Modification du font-familly pour Windows
  
  
  
  // Homepage
  $('#page.homepage > div p a:last-child').click(function ()
  { 
    OpenMaxWindow($('#page.homepage > div p a:last-child').attr('href'));
  });  
    
  // Page "contact"
  if($('#Map').length > 0)
  {
    $('#GoogleMap').offset({left:-1000});
    
    $('#Map').toggle(function(){
        $('#GoogleMap').offset($('#MapContainer').offset());
      }, function() {
        $('#GoogleMap').offset({left:-1000});
      });
  }

  // Affichage d'une photo (photo.php)
  if($('#showcase_photo').length > 0)
  { 
    $('#showcase_photo').hide();
    
    // On ajoute un listener sur le rechargement d'image
    $('div.figure img').load(function() {
      // La photo a été (re)chargée
      
      // Et on affiche le cadre photo
      $('#showcase_photo').fadeIn();
      
      // ==> On adapte les DIV
      $('div.figure').width($('div.figure img').width());            
      $('div.figure').css('margin-left', -1 * ($('div.figure').width()/2));
      
      $('#photo_legend').width($('div.figure img').width());
      
      // On reforce les largeurs (même si elles ne changent pas, puisque en %)
      // pour forcer le recalcul !
      $('#photo_description').width('48%');
      $('#showcase_navigation').width('20%');
      $('#showcase_position').width('15%');
      $('#showcase_goback').width('15%');
      
      // Et lui aussi
      $('#hover_navigation').height('90%');
      $('#hover_navigation').width('100%');
      
      // On cache le truc
      $('#photo_hauteur_max').hide();
    });    
    
    // Bonne échelle de photo
    if($('div.figure img').attr('id').substring(0,6) == 'photo_')
    {      
      // On charge la hauteur max existante pour cette photo
      var hauteur_max = $('#photo_hauteur_max').text();

      // On calcule la hauteur à employer
      var hauteur = Math.max(300, Math.min(1400, ((Math.floor($(window).height()/50) - 1)*50)));

      // On spécifie la bonne image
      if(hauteur_max != undefined && hauteur_max != '' && hauteur_max != 0)
      {
        if(hauteur < hauteur_max)
        {
          $('div.figure img').attr('src', 'photos/photo_' + $('div.figure img').attr('id').substring(6) + '_resize_h-' + hauteur + '.jpg');
        }
      }
      else
      {
        // Pas de taille maximum connue
        // ==> On laisse l'image d'origine
      }      

      // alert('[' + hauteur + ' / ' + hauteur_max + ']');
    }
    
    // Navigation
    $(document).keydown(function (e)
    {
      if(e.keyCode == 37 && $("#previous").attr("href").length > 0)
      {
        window.location = $("#previous").attr("href");
      }
      if(e.keyCode == 39 && $("#next").attr("href").length > 0)
      {
        window.location = $("#next").attr("href");
      }
    });    
  }   
});


