$(document).ready(function() { 
	
	// Event submit on clikc
	$('.btSubmit').click(function(){
		$(this).parents('form').submit();
		return false;
	});
	
	$('a.ajaxLink').click(function(){
		var thisProxy = this;
		if ( !$(this).hasClass('clicked') ) {
			$(this).addClass('clicked');
			$.ajax({
				url: $(this).attr('data-counter-url'),
				success: function(){
					$(thisProxy).removeClass('clicked');
				}
			});
		}
	});
	
	// Event button big game
	$('#emailgameId').click(function(){
		var _defaultValue = 'Inscrivez votre email !';
		
		if ($(this).val() == _defaultValue) {
			$(this).val('');
		}
		
	});
	
	$('#emailgameId').blur(function(){
		var _defaultValue = 'Inscrivez votre email !';
		
		if ($(this).val() == '') {
			$(this).val(_defaultValue);
		}
		
	});
	
	// Event tool search
	$( "#searchId" ).autocomplete({
		source: function(request, response){

			var query = $('#searchId').val();
			$.ajax({
				url: '/search/process-search-ajax',
				dataType: 'html',
				data: {'term':query},
				success: function(data) {
					if (data != '') {
						// add to div
						
						$("#ajax-result-search").html(data);
						$("#ajax-result-search").show();
					} else {
						$("#ajax-result-search").hide();
					}
				}
			});
		}
	});
	
	$(document).click(function(){
		$("#ajax-result-search").hide();
		
	});
	
	$( "#searchId" ).focusout(function(){
		//$("#ajax-result-search").hide();
	});
	$('#searchId').keypress(function(){
		var value = $(this).val();
		if (value == '' || value == 'undefined' || value === null) {
			$("#ajax-result-search").hide();
		}
		
	});
	$('#searchId').mouseup(function(){
		var value = $(this).val();
		$("#ajax-result-search").hide();
		if (value == '' || value == 'undefined' || value === null) {
			$("#ajax-result-search").hide();
		}
		
	});

	
			
});

