/* scripts pour l'affichage des pages */
$(document).ready(function() 
{
	//Plier/deplier zones de le colonne principale
	$('.titre, .switch').click(function(){
		if ($(this).hasClass('switch'))
		{
			var zone = $(this).parent(0).parent(0); 
			var titre = $(this).parent(0); 
			var switcher = $(this);
		}
		else
		{
			var zone = $(this).parent(0); 
			var titre = $(this);
			var switcher = $(this).find('.switch');
		}
		//plier/deplier le corps
		zone.find('.corps').slideToggle('normal');
		
		//zone active => plier
		if (titre.hasClass('titre_actif') || titre.hasClass('titre_user_actif'))
		{
			switcher.find('img:eq(0)')
				.attr('src', publicPath+'/images/picto-plie.png'); 			
		}
		//zone inactive => deplier
		else
		{
			switcher.find('img:eq(0)')
				.attr('src', publicPath+'/images/picto-deplie.png');
		}
		// classes actif/inactif
		if (titre.hasClass('titre_user'))
		{
			titre
				.toggleClass('titre_user_actif')
				.toggleClass('titre_user_inactif');				
		}
		else
		{
			titre
				.toggleClass('titre_actif')
				.toggleClass('titre_inactif');
		}
		return false;
	});	
	
	//fermeture des infos-bulles
	$('.info_bulle_close').click(function(){
		$(this).parent().parent().parent().fadeOut('normal');
		return false;
	});
	
	//ouverture des infosbulles d'aide
	$('a[id$=-help-link]').click(function (){
		var id = $(this).attr('id');
		var nom = id.substring(0, id.indexOf('link'));
		$('#'+nom+'bulle').fadeIn('normal');
		return false;
	});
	
	//switch des bloc recherches
	$('.switch_recherche').click(function(){
		$('#recherche_avancee').slideToggle();
		$('.switch_recherche').find('.ui-icon').toggleClass('ui-icon-plus').toggleClass('ui-icon-minus');
		var val = $('#avancee').val();
		$('#avancee').val((val == 0)?(1):(0));
		return false;
	});
	$('#btn_recherche').click(function(){
		$('#fiche_recherche_form').submit();
	});
	
	/* ouverture des dialog*/
	$('a[id$=-open]').click(function(){
		var id = $(this).attr('id');
		var idDialog = id.substring(0, id.indexOf('-open'));
		$('#'+idDialog).dialog('open'); 
		return false;
	});
	
	//chargements des calendriers par défaut
	$.datepicker.setDefaults($.extend({showMonthAfterYear: false, showOn: 'button', buttonImage: publicPath+'/images/calendar.gif', buttonImageOnly: true}));
	
	//chargements des waremarks pour formulaires
	$.updnWatermark.attachAll();
});
