

$(document).ready(function() {
	
	$('#h_objectif').val('');
	$('#h_age').val('');
	$('#h_gender').val('');
	
	
	$('.openlist_button').click(function() {
		var idName = $(this).attr('id');
		$('.select_list').slideUp(50);
		
		if ($('.'+idName).hasClass('hidden-select')) {
			$('.'+idName).slideDown(200);
			$('.select_list').addClass('hidden-select');
			$('.'+idName).removeClass('hidden-select');
			
		}else{
			$('.'+idName).slideUp(50);
			$('.'+idName).addClass('hidden-select');
		}

	});
	
	$('.select_list li').click(function() {
		var idParent = $(this).parent().prev().attr('id');
		var valueSelect = $(this).html();
		
		$('#'+idParent+'_span').html(valueSelect);
		$('input.'+idParent+'_value').val(valueSelect);
		
		$('.select_list').slideUp(50);
		$('.select_list').addClass('hidden-select');
	});
	
	// Home Carousel
	$('#visible-slider-text').html($('#slider-text_1').html());
	$('#home-carousel li img').css('visibility', 'visible');
	
	$('#home-carousel').jcarousel({
		scroll: 1,
		auto: 5,
		wrap: 'circular',
		initCallback: homeslider_carousel_initCallback,
		itemVisibleInCallback: {
			onBeforeAnimation: arriveFocus
		},
		itemVisibleOutCallback: {
			onBeforeAnimation: removeFocus
		}
	});
	
	$('.homeslider-controls a').click(function() {
		$('.homeslider-controls a').removeClass('selected_circle');
		$(this).addClass('selected_circle');
	});

});

function homeslider_carousel_initCallback(carousel) {
    $('.homeslider-controls a').bind('click', function() {
        carousel.scroll($.jcarousel.intval($(this).attr('rel')));
        return false;
    });
};

function arriveFocus(carousel, li, index, state){
	var car_size = $('.homeslider-controls a').size();
	if(index > car_size){
		var new_index = index % car_size;
		if (new_index==0) new_index = car_size;
	}
	else
		new_index = index;
	
	$('#circle_'+new_index).addClass('selected_circle');
	$('#slider-text_'+new_index).delay(250).fadeIn(500);
};


function removeFocus(carousel, li, index, state){
	var car_size = $('.homeslider-controls a').size();
	if(index > car_size){
		var new_index = index % car_size;
		if (new_index==0) new_index = car_size;
	}
	else
		new_index = index;
		
	$('#circle_'+new_index).removeClass('selected_circle');
	$('#slider-text_'+new_index).fadeOut(250);
};


function numbersOnly(event) {
        var keyCode;
        if (document.all){
                keyCode = event.keyCode;
        }else{
                keyCode = event.which;
        }
		if (keyCode > 28 && (keyCode < 45 || keyCode > 57)) {
                return event.returnValue = false;
		}
        return true;
}




