
$(document).ready( function(){

	/* img horizontale */
	imghorizontale = $("a.defaultsmallimg").attr("class");
	if(imghorizontale!=undefined){	
	$("a.defaultsmallimg").addClass("smallimg");
	$("a.defaultsmallimg").removeClass("defaultsmallimg");
	$("a.smallimg").width(114);
	$("a.smallimg").each(function(){
		classimg = $(this).children("img").attr('class');
		var largueur = -1, hauteur = -1;
		var o = /(?:^| )dimension_(\d+)-(\d+)(?: |$)/.exec(classimg);
		if (o) {
			largueur = parseInt(o[1], 10);
			hauteur = parseInt(o[2], 10);
		}
		facteur = 114/largueur;
		calcul = Math.round(hauteur*facteur);
		hauteurparent = $(this).parent().outerHeight();
		if(hauteurparent <= calcul){
			nouvellehauteur = calcul+15;
			$(this).parent().height(nouvellehauteur);
		}
		$(this).css("height",calcul);
	});
	$("a.smallimg").toggle(function(){
		classimg = $(this).children("img").attr('class');
		var largueur = -1, hauteur = -1;
		var o = /(?:^| )dimension_(\d+)-(\d+)(?: |$)/.exec(classimg);
		if (o) {
			largueur = parseInt(o[1], 10);
			hauteur = parseInt(o[2], 10);
		}
		facteur = 114/largueur;
		calcul = Math.round(hauteur*facteur);					
		$(this).parent().animate({paddingTop: hauteur, marginLeft: 236, paddingLeft: 0},1000);		
		$(this).animate({height: hauteur, width: largueur},1000);
		lealt = $(this).children("img").attr('alt');
		if (lealt != 'agrandir'){
			longueur1 = lealt.lastIndexOf(' - agrandir');
			contenualt = lealt.substring(0, longueur1);
			newalt = contenualt+' - réduire';
			oldalt = contenualt+' - agrandir';
			$(this).children("img").attr('alt',newalt);
			$(this).children("img").attr('title',newalt);
		} else{
			newalt = 'réduire';
			oldalt = 'agrandir';
			$(this).children("img").attr('alt',newalt);
			$(this).children("img").attr('title',newalt);		
		}
			
	},function(){
		$(this).parent().animate({paddingTop: 0, marginLeft: 114, paddingLeft: 122},1000);
		$(this).animate({left: 0, height: calcul, width: 114},1000);
		$(this).children("img").attr('alt',oldalt);
		$(this).children("img").attr('title',oldalt);
	});}
	
	/* img verticale */
	imgverticale = $("a.verticalsmallimg").attr("class");
	if(imgverticale!=undefined){
	$("a.verticalsmallimg").addClass("smallimg2");
	$("a.verticalsmallimg").removeClass("verticalsmallimg");
	$("a.smallimg2").width(114);
	
	$("a.smallimg2").each(function(){
		classimg = $(this).children("img").attr('class');
		var largueur = -1, hauteur = -1;
		var o = /(?:^| )dimension_(\d+)-(\d+)(?: |$)/.exec(classimg);
		if (o) {
			largueur = parseInt(o[1], 10);
			hauteur = parseInt(o[2], 10);
		}
		facteur = 114/largueur;
		calcul = Math.round(hauteur*facteur);
		$(this).height(calcul);
		hauteurparent = $(this).parent().outerHeight();
		if(hauteurparent <= calcul){
			nouvellehauteur = calcul+15;
			$(this).parent().height(nouvellehauteur);
		} else{
			$(this).parent().height(hauteurparent);
		}
		$(this).css("height",calcul);
	});
	$("a.smallimg2").toggle(function(){
		classimg = $(this).children("img").attr('class');
		var largueur = -1, hauteur = -1;
		var o = /(?:^| )dimension_(\d+)-(\d+)(?: |$)/.exec(classimg);
		if (o) {
			largueur = parseInt(o[1], 10);
			hauteur = parseInt(o[2], 10);
		}
		facteur = 114/largueur;
		newlargueur = largueur+10;
		calcul = Math.round(hauteur*facteur);
		hauteurparent = $(this).parent().outerHeight();
		if(hauteurparent <= hauteur){
			nouvellehauteur = hauteur+15;
		} else{
			nouvellehauteur = hauteurparent;
		}					
		$(this).parent().animate({ paddingLeft: newlargueur, height: nouvellehauteur},1000);		
		$(this).animate({height: hauteur, width: largueur},1000);
		lealt = $(this).children("img").attr('alt');
		if (lealt != 'agrandir'){
			longueur1 = lealt.lastIndexOf(' - agrandir');
			contenualt = lealt.substring(0, longueur1);
			newalt = contenualt+' - réduire';
			oldalt = contenualt+' - agrandir';
			$(this).children("img").attr('alt',newalt);
			$(this).children("img").attr('title',newalt);
		} else{
			newalt = 'réduire';
			oldalt = 'agrandir';
			$(this).children("img").attr('alt',newalt);
			$(this).children("img").attr('title',newalt);		
		}
			
	},function(){
		if(hauteurparent <= calcul){
			nouvellehauteur = calcul+15;
		} else{
			nouvellehauteur = hauteurparent;
		}
	
		$(this).parent().animate({marginLeft: 114, paddingLeft: 122, height: nouvellehauteur},1000);
		$(this).animate({left: 0, height: calcul, width: 114},1000);
		$(this).children("img").attr('alt',oldalt);
		$(this).children("img").attr('title',oldalt);
	});}
	
	
});