//jQuery.noConflict( );

$( document ).ready( function( ) {
	// RESET FORMULAIRE 
	$( '#reset' ).click( function( ){
		////////////PENSER A GERER AUTOMATIQUEMENT TOUS LES TYPE DE CHAMPS//////////////
		$( this ).closest( 'form' ).find( 'input[type=text]' ).val( '' );
		$( this ).closest( 'form' ).find( 'textarea' ).val( '' );
		return false;
	});
	
	// LIENS - NOUVEL ONGLET
	$( 'a.new_window' ).click( function( ){
		window.open( $( this ).attr( 'href' ) );
		return false;
	});
	$( 'a.new_window' ).each( function( ){
		$( this ).attr( 'title', $( this ).attr( 'title' ) + ' dans un nouvel onglet' );
		if ( ! $( this ).hasClass( 'no_ico_new_window' ) ) {
			$( this ).append( '<span class="ico_new_window">&nbsp;</span>' );
		}
	});
	
	// LIEN - BACK
	$( 'a.go_back' ).click( function( ){
		history.back( );
		return false;
	});
	
	// Permet l'appel au plugin "jdMenu"( met en forme le menu )
	if ( typeof( $.fn.jdMenu ) != 'undefined' ) {
		$( '#menu_nav .level_3' ).addClass( 'jd_menu jd_menu_vertical' );
	}

	// Soumet automatiquement un formulaire à la selection d'une option d'un select enfant
	$( 'select.auto_submit' ).change( function( ){
		if ( $( this ).find( 'option:selected' ).val( ) != '' ) {
			$( this ).closest( 'form' ).submit( );
		}
	});
	// Ajoute a ces select une option lorsque aucun resultat n'est trouve, et la selection
	if ( $( 'table#collaborators' ).find( 'td' ).length == 0 ) {
		$( 'select.auto_submit' ).prepend( '<option class="make_choise" value="">Faites votre sélection</option>' );
		$( 'select.auto_submit' ).find( 'option' ).eq( 0 ).attr( 'selected', 'selected' );
	}
	
	// Supprime le bt submit des formulaires a soummettre automatiquement
	$( 'select.auto_submit' ).closest( 'form' ).find( 'input[type="submit"]' ).remove( );

	// ACCORDEON
	// Met en place un systeme d'accordeon sur les "heading" => cache/ montre les textes et les images
	$( '.page_type_article' ).find( 'h3, h4, h5, h6' ).click( function( ){
		$( this ).siblings( '.paragraph_img' ).slideToggle( 'normal' );
		
		$( this ).siblings( '.paragraphs' ).children( '.paragraph' ).each( function( ){
			if ( $( this ).children( 'h3, h4, h5, h6' ).length == 0 ) {
				$( this ).children( '.paragraph_text, .paragraph_img' ).slideToggle( 'normal' );
			}
		});
		
		$( this ).toggleClass( 'open' );
	});

	$( '.page_type_article' ).find( '.paragraph_text' ).closest( '.paragraphs' ).siblings( 'h3, h4, h5, h6' ).addClass( 'accordeon_title' );
	$( '.page_type_article' ).find( '.paragraph_img' ).siblings( 'h3, h4, h5, h6' ).addClass( 'accordeon_title' );
	$( '.page_type_article' ).find( 'h3, h4, h5, h6' ).closest( '.paragraph' ).find( '.paragraph_text, .paragraph_img' ).hide( );
	//FIN - ACCORDEON
});
