$(function(){
    tailleImageGrande = 600;
    
    $('.centrage img').mouseenter(function(){
        //tailleImageGrande = $('#photo').parent().css('width');
        $('#photo img').attr('src',$(this).attr('src'));
        $('#photo a').attr('href',$(this).attr('src'));
        if(parseInt($(this).attr('width'))>parseInt($(this).attr('height'))){
            $('#photo img').attr("width",tailleImageGrande+"px");
            height = Math.round((parseInt($(this).attr('height'))*tailleImageGrande)/parseInt($(this).attr('width')));
            $('#photo img').attr("height",height+'px');
            $('#photo img').css('margin-left','0');
            $('#photo img').css('margin-top',Math.round((tailleImageGrande-height)/2)+'px');
        }else{
            $('#photo img').attr("height",tailleImageGrande+"px");
            width = Math.round((parseInt($(this).attr('width'))*tailleImageGrande)/parseInt($(this).attr('height')));
            $('#photo img').attr("width",width+'px');
            $('#photo img').css('margin-top','0');
            $('#photo img').css('margin-left',Math.round((tailleImageGrande-width)/2)+'px');
        }
    });
    
   $('img.centrer').bind("load",function(){
        tailleImage = parseInt($(this).parent().css('width'));
        var tmp_img = new Image();
        tmp_img.src=$(this).attr('src');
        real_width = tmp_img.width;
        real_height = tmp_img.height;
        if(real_width >real_height ){
            //alert($(this).css("width"));
            $(this).attr("width",tailleImage+"px");
            //alert($(this).css("width"));
            height =  Math.round(real_height*tailleImage/real_width);
            //alert(height);
            $(this).attr("height",height+'px');
            $(this).css('margin-left','0');
            $(this).css('margin-top',Math.round((tailleImage-height)/2)+'px');
        }else{
            $(this).attr("height",tailleImage+"px");
            width = Math.round(real_width*tailleImage/real_height);
            //alert(width);
            $(this).attr("width",width+'px');
            $(this).css('margin-top','0');
            $(this).css('margin-left',Math.round((tailleImage-width)/2)+'px');
        }
    
    });  
    
   // $('a.zoombox').zoombox();
});
