// JavaScript Document
var nbgal;
function allezhop(nb) {
	nbgal = nb;
	$(document).ready(function() { 
			slideShow(); 
	});
}
function slideShow() {	
	for ( var i= 0; i <= nbgal; i++ ) {	
		
		$('#galerie'+i+' img').css({opacity: 0.0});
		$('#galerie'+i+' img:first').css({opacity: 1.0});
		$('#legende'+i+' p').css({opacity: 0.0});
		
		var current = $('#galerie'+i+' img:first');
		current.load(function() {
			var id = $(this).parent().attr('id').substr(7,2);
			var height = $(this).height();
			var posFleche = (height - 40) *0.5;
			$('#play'+id).css({marginTop : posFleche});	
			$('#legende'+id).css({marginTop : height});						
			if ( height >= 190 ) {
				$(this).css({marginLeft: 65});				
			}			
			$('#legende'+id+' p:first').css({opacity: 1.0});			
			if ($(this).next().length > 0 ) {
				setInterval('gallery('+id+')',3000);
			}
		});
	}
}

function gallery(qui) {
	
	var current = ($('#galerie'+qui+' img.show')?  $('#galerie'+qui+' img.show') : $('#galerie'+qui+' img:first'));
	var currentlegende = ($('#legende'+qui+' p.show')?  $('#legende'+qui+' p.show') : $('#legende'+qui+' p:first')); 
	
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#galerie'+qui+' img:first') :current.next()) : $('#galerie'+qui+' img:first'));
	var nextlegende = ((currentlegende.next().length) ? ((currentlegende.next().hasClass('caption'))? $('#legende'+qui+' p:first') :currentlegende.next()) : $('#legende'+qui+' p:first'));  
	var height = next.attr('height');
	$('#legende'+qui+'').css({marginTop : height});
	if ( height == 190 ) {
		next.css({marginLeft:65});
	}
	var posFleche = (height - 40) *0.5;
	$('#play'+qui).css({marginTop : posFleche});	
	next.css({opacity: 0.0})	
	.addClass('show')
	.animate({opacity: 1.0}, 500);
	
	nextlegende.css({opacity: 0.0})	
	.addClass('show')
	.animate({opacity: 1.0}, 500); 
	
	current.animate({opacity: 0.0}, 500)
	.removeClass('show');
	
	currentlegende.animate({opacity: 0.0}, 500)
	.removeClass('show');
		 
}
