var slideshow_index = 0;
var slideshow_max = 0;

function slideshow() {
	$('#bgimage img:eq('+slideshow_index+')').fadeIn( 2000 , function() {
		// go to next image...
		// only if more than one
		if( slideshow_max <= 0 )  {
			// only one image stop here
			return null;
		}
		// go to next...
		// but make it wait x seconds
		$(this).animate( {top:'+0'} , 2000 , null , function() {
			// fadeout
			$(this).fadeOut( 2000 , function() {
				slideshow_index = slideshow_index+1 > slideshow_max ? 0 : slideshow_index+1;
				// loop!
				slideshow();
			} );
		} );
	} );
}

$(document).ready(function(){

	// set menu hover interaction
	$('#menu1 img, #menu2 img , #menu4 img').hover(
		function() {
			var isrc = $(this).attr('src');
			$(this).attr( 'src' , isrc.replace( 'images/' , 'images/o/' ) );
		} ,
		function() {
			var isrc = $(this).attr('src');
			$(this).attr( 'src' , isrc.replace( 'images/o/' , 'images/' ) );
		}		
	);

	// preload menu images
	$('#menu1 img, #menu2 img, #menu4 img').each( function() {
 			var isrc = $(this).attr('src');
			$("<img>").attr( 'src' , isrc.replace( 'images/' , 'images/o/' ) );
		}
	);
	
	// set DHTML menu item
	//$("#menu1 a, #menu2 a").hover( menu_hide , function(){} );
	//$("#menu1 a:eq(2)").hover( menu_show , function(){} );
	//$("#menu3").hover( menu_show , menu_hide );
	
	// get number of images to use in slideshow
	slideshow_max = $('#bgimage img').length - 1;
});

var menu_timer = null;

function menu_show() {
	$('#menu3').show();		
	menu_timer = null;
}

function menu_hide() {
	menu_timer = window.setTimeout( menu_hide_delay , 400 );
}

function menu_hide_delay() {
	if( menu_timer ) {
		$('#menu3').hide();	
	}
}

function infolettre() {
	$("#infolettreanim").show().animate({ "top": '360px' }, 1500 );
}

function infolettre_close() {
	$("#infolettreanim").fadeOut(600);
}

