function slideSwitch() {
	var $active = $('#home_slideshow img.active');
	
	if ( $active.length == 0 ) $active = $('#home_slideshow img:last');
	
	var $next =  $active.next().length ? $active.next()
		: $('#home_slideshow img:first');
	
	$active.addClass('last-active');
	
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 2000, function() {
			$active.removeClass('active last-active');
	});
}

$(document).ready(function() {
	activeMenu = $('#menu_container a[class*="selected"]').attr('rel');
	
	$('a[id^="menu_"], div[id^="submenu_mask_"]').mouseover(function() {
		tmp = $(this).attr('id').split('_');
		id = tmp[tmp.length - 1];
		
		$('#menu_' + id).attr('class', 'selected');
		$('#submenu_mask_' + id).clearQueue();
		$('#submenu_mask_' + id + ' div').width($('#submenu_mask_' + id + ' div').width() + 'px');
		
		$('#submenu_mask_' + id).animate(
			{ width: $('#submenu_mask_' + id + ' div').width() + 'px', opacity:'1', queue: true }
		)
	});  
	
	$('a[id^="menu_"], div[id^="submenu_mask_"]').mouseout(function() {
		tmp = $(this).attr('id').split('_');
		id = tmp[tmp.length - 1];
		
		if ($(this).attr('rel') != activeMenu) { $('#menu_' + id).attr('class', ''); }
		
		$('#submenu_mask_' + id).animate(
			{ width: '0px', opacity: '0', queue: true }
		)  
	}); 
	
	$(function() {
		setInterval("slideSwitch()", 5000);
	});
	
	

	
	/******* Formulaire de carrière ******/
	$('.day, .month, .year').change(function() {
		id = $(this).attr('rel');
		$('#date' + id).val($('#day' + id).val() + '/' + $('#month' + id).val() + '/' + $('#year' + id).val());
	});
	
	$('.datepicker').datepicker({
		dayNames:       ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
		dayNamesMin:    ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
		monthNames:     ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
		dateFormat:		'dd/mm/yy'
	});
	
	if ($('.hiddenVehicle:eq(1) input').val() == '') { $('.hiddenVehicle').css('display', 'none'); }
	if ($('.hiddenWork:eq(1) input').val() == '') { $('.hiddenWork').css('display', 'none'); }
	
	$('#ifVehicle').change(function() {
		if ($(this).val() == 'Oui' || $(this).val() == 'Yes') { $('.hiddenVehicle').css('display', 'none'); } else { $('.hiddenVehicle').css('display', ''); }
	});
	
	$('#ifWork').change(function() {
		if ($(this).val() == 'Oui' || $(this).val() == 'Yes') { $('.hiddenWork').css('display', ''); } else { $('.hiddenWork').css('display', 'none'); }
	});
});
