var isload=false;
$(document).ready(function(){ if(!isload) $("#contentLeft > .padding").hide(); });function repositionneImg(){
$("#photo_ic .photoIC").each(function(){
	var w2 = $(this).parent().width(); $(this).width(w2);
  var h = $(this).height('').height(); var h2 = $(this).parent().height();
  if(h<h2){
    var top = Math.floor((h2-h)/2); $(this).css('margin-top',top);
  }else{
    $(this).height(h2);
  }
});
}

function checkNavPhoto(){

	var el = $("#boxPhotoImage img");
	if(el.is(':hidden')){
		$("#boxPhotoPrev > img").addClass('disabled');
		$("#boxPhotoNext > img").addClass('disabled');
		return;
	}
	var current=el.attr('src');
	var els = $(".imgbox"), find=null;
	for(i=0;i<els.length;i++){
		if( find!=null ) continue;
		if( $(els[i]).attr('href') == current ){
			find=i;
		}
	}

	var prev = $(els[find-1]);
	if(find==null || find-1<0 || prev.length==0 || prev.attr('href')=='javascript:;'){
		$("#boxPhotoPrev > img").addClass('disabled');
	}else{
		$("#boxPhotoPrev > img").removeClass('disabled');
	}
	var next = $(els[find+1]);
	if(find==null || find+1>=els.length || next.length==0 || next.attr('href')=='javascript:;'){
		$("#boxPhotoNext > img").addClass('disabled');
	}else{
		$("#boxPhotoNext > img").removeClass('disabled');
	}

}


function nextPhoto(){
	var el = $("#boxPhotoImage img");
	checkNavPhoto();
	if(el.is(':hidden')) return;
	var current=el.attr('src');
	var els = $(".imgbox"); var find=0;
	els.each(function(){
		if(find==1){
			var href = $(this).attr('href');
			if(href=="javascript:;") return;
			$("#boxPhoto").addClass('load'); 
			$("#boxPhotoImage > img").fadeOut(250,function(){
				var el=$(this); el.attr('src',href);
			});
			find=2;
		}else if(find==0){
			var href = $(this).attr('href');
			if( href == current ) find=1;
		}
	});
	checkNavPhoto();
}
function prevPhoto(){
	var el = $("#boxPhotoImage img");
	checkNavPhoto();
	if(el.is(':hidden')) return;
	var current=el.attr('src');
	var els = $(".imgbox"); var prev=null; var find=0;
	els.each(function(){
		if( find==1 ) return;
		var href = $(this).attr('href');
		if( href == current ){ 
			var href = prev; if(href=="javascript:;" || href==null) return;
			$("#boxPhoto").addClass('load'); 
			$("#boxPhotoImage > img").fadeOut(250,function(){
				var el=$(this); el.attr('src',href);
			});
			find=1;
		}
		prev=href;
	});
	checkNavPhoto();
}
window.onresize = retaillePhotoBox;
function retaillePhotoBox(){

  var el = $("#boxPhoto");
  var w = el.width(); var h = el.height();

    if( el.is(':visible') ){
	  $("#boxPhotoBack").css('left','-5000px');
	  var left = ($(window).width()-960)/2 *-1;
	  $("#boxPhotoBack")
		.show()
		.css('left',left)
		.width( $(window).width() )
		.height( $(window).height() )
		.click( closeBox );
  }
  
  var el = $("#boxPhotoImage > img");
  var LargeurPhoto = (w - $("#boxPhotoLeft").width() );
  var HauteurPhoto = (h - 30);
  el.parent().css('right',0);
  el.width(LargeurPhoto).height('');

  if(el.height()>HauteurPhoto){
    el.height(HauteurPhoto).width('');
    var right = (LargeurPhoto - el.width())/2;
    el.parent().css('right',right);
  }

}
function closeBox(){ $("#boxPhoto").fadeOut(700); $("#boxPhotoBack").hide(); };
var animOA = function(){

  repositionneImg();
  retaillePhotoBox();

  // BOX
  $("#boxPhotoImage > img").bind('load',function(){ 
	retaillePhotoBox(); 
	$(this).fadeIn(500, function(){ 
		$("#boxPhoto").removeClass('load'); 
		retaillePhotoBox(); 
		checkNavPhoto();	}); 
  });
  $("#boxPhotoClose").css('cursor','pointer').click(closeBox);
    $(document).ready(function(){
	$("#boxPhotoPrev").css('cursor','pointer').click(prevPhoto);
	$("#boxPhotoNext").css('cursor','pointer').click(nextPhoto);
  });
    $(document).keyup(function(e){
    	if(e.keyCode=="27") closeBox();
    if(e.keyCode=="37"){ prevPhoto(); }
    if(e.keyCode=="39"){ nextPhoto(); }
	  });
  $("a.imgbox").not('.nophoto').click(function(){
    var href = $(this).attr('href');
    var el = $("#boxPhotoImage > img");
    if( el.attr('src')!=href ){
      $("#boxPhoto").addClass('load');
      el.fadeOut(400,function(){
        $(this).attr('src',href);
        $("#boxPhoto").fadeIn('750',retaillePhotoBox);
      });
    }else $("#boxPhoto").fadeIn('750',retaillePhotoBox);
    return false;
  });



  
        var el0 = $("#actuTrait"); var w0 = 65; var h0 = 163;
    el0.width('1px').height('3px').animate({width:'26px'},300).animate({height:h0},300).animate({width:w0},300);
    
        var el = $("#TitreImage");
    
    var el2 = $("#contentLeft > .padding");
    var el3 = $("#titreIc2");
    var h = el.height(); var w = el.width();
    el2.show(); scrollBar();
    var h2 = el2.height(); var w2 = el2.width();
    el2.hide().width('1px'); el3.hide();
    el.height('1px').width(w).animate({height:h},500,function(){
      el2.animate({width:w2},500, function(){
        $("#scrollBar").css({position:'relative',display:'block'});
                el3.fadeIn(500);
                repositionneImg();
      });
    });

  
  isload=true;
  repositionneImg();

};

var loadAnimImg = function(){
	animOA();
	if( jQuery.browser.msie && jQuery.browser.version>=8 ){ 
		setTimeout(retaillePhotoBox,500);
		setTimeout(retaillePhotoBox,600);
		setTimeout(retaillePhotoBox,700);
		setTimeout(retaillePhotoBox,800);
		setTimeout(retaillePhotoBox,900);
	}
};
addOnLoad('loadAnimImg');
