jQuery().ready(function() {
	
	// navigation
	$('.dynsmenu').bind('mouseover', function() {
		$('.fd').hide();
		$('.dynsmenu').removeClass('on');
		$(this).addClass('on');
		$('.fd', $(this)).show();
	});
  
	$('.dynsmenu').bind('mouseout', function() {
		$('.fd').hide();
		$('.dynsmenu').removeClass('on');
	});
	
	// formulaires
	$('div.field label').each(function() {
    
    selector = '#'+$(this).attr('for');
    
		if (selector != '#' && $(selector).hasClass('required')) {
			$(this).append('<em>*</em>');
		}
	});
	
	// auto complete
	var autocomplete_params = {
		source: '/autocompletetown',
		minChars: 2,
		delay: 300
	};

	$('#search_where').autocomplete(autocomplete_params);

	$('#town_where').autocomplete(autocomplete_params);

	$('#searchByService_where').autocomplete(autocomplete_params);
	
	$('.atown').autocomplete(autocomplete_params);

	// blank links
	$("a.blank").attr('target', '_blank');

	// Prochainement
	$('.soon').qtip( {
		content : 'Prochainement',
		show : 'mouseover',
		hide : 'mouseout'
	});
	$('.soon').bind('click', function() {
		return false;
	});
	
	// multiselect
    $(".multiselect").multiselect();

	// pagination listing prestataires
	$('div.pagejs').hide();
	
	$('div.pagejs').each(function() {
		var pagejs = $('div.pagejs');
		var current = pagejs.index(this);
		var first = 0;
		var last = pagejs.size() - 1;
		var previous = ((current - 1) >= first) ? (current - 1) : last;
		var next = ((current + 1) <= last) ? (current + 1) : first;
		$(this).data('previous', pagejs.get(previous));
		$(this).data('next', pagejs.get(next));
	});
	
	$('div.pagejs:first').show();
	
	$('ul.pagination .precedent').bind('click', function() {
		var current = $('div.pagejs:visible:first');
		current.hide();
		$(current.data('previous')).show();
		return false;
	});
	
	$('ul.pagination .suivant').bind('click', function() {
		var current = $('div.pagejs:visible:first');
		current.hide();
		$(current.data('next')).show();
		return false;
	});
	
	$('div.field:odd').addClass('odd');
	$('table#agences tr:odd').addClass('bg');
	
	$('input:checkbox.longlabel').each(function (){
		$(this).parent().addClass('longlabel');
	});	
	
	$('div.module-fiche h2').each(function () {
		while((height = parseInt($(this).height()))>50) {
			$(this).css('font-size', (parseInt($(this).css('font-size'))-1)+'px');
		}
	});
	
});

