// JavaScript Document

$( function () {
	// retour en haut
	$('.haut').click( function() {
			//$(window).scrollTop(0);
			$.scrollTo(0,1000);
			return false; 
		}
	);
	
	// Couleur des ligne
	$('.forum-liste-sujets  tr').not('.standby').each ( function () {
		$(this).hover ( function () {
			$(this).addClass('hover');
			$(this).find('.ligne-actions').addClass('ligne-actions-on');			
		},
		function () {
			$(this).removeClass('hover');
			$(this).find('.ligne-actions').removeClass('ligne-actions-on');
		});
	});
	
	/* Gestion de la liste des reponses */
	$('.forum-liste-message-question').hover ( function () {		if ( !$(this).hasClass('nohover') )
			$(this).addClass('hover');
		$(this).find('.liste-message').addClass('visible');
		$(this).find('.hide').addClass('visible');
	},function () {		if ( !$(this).hasClass('nohover') )
			$(this).removeClass('hover');
		$(this).find('.liste-message').removeClass('visible');
		$(this).find('.hide').removeClass('visible');
	});
	
	$('.liste-reponses').find('>li').each ( function () {
		$(this).hover ( function () {
			if ( !$(this).hasClass('nohover') )
				$(this).addClass('hover');
			
			$(this).find('.liste-message').addClass('visible');
			$(this).find('.hide').addClass('visible');
		},function () {
			if ( !$(this).hasClass('nohover') )
				$(this).removeClass('hover');
			
			$(this).find('.liste-message').removeClass('visible');
			$(this).find('.hide').removeClass('visible');
		});
	});
	
	$('.edit-message').click ( function () {
		var $button = $(this);
		$(this).parents('.clearfix').eq(0).find('.modif-reponse').css('height', 'auto');
		$(this).parents('.clearfix').eq(0).find('.modif-reponse').fadeIn('fast', function () {
			$.scrollTo( $button.parents('.clearfix').eq(0).position().top, 800);
			$(this).parents('.clearfix').eq(0).find('.modif-reponse').find('.form-edit-message').show();
		});
		return false;
	});
	
	$('.form-edit-message').find('.bouton-action').click ( function () {		//GM: put the neov content in the submit_success function:		//+ replaced $(this).parents('.modif-reponse').eq(0) by form_element.find('.modif-reponse').eq(0) etc...		function submit_success(form_element,answer_json){			form_element.parents('.modif-reponse').eq(0).animate( {				height: '158px'			}, 800);			form_element.fadeOut('fast', function () {							if( answer_json.ok == 0 ){					form_element.next('.modif-message-confirm').find('p').eq(0).hide();					form_element.next('.modif-message-confirm').find('p').eq(1).hide();					form_element.next('.modif-message-confirm').prepend('<p class="ask_modif_error" style="color:red;">Erreur: '+ answer_json.message +'</p>');				}else{					form_element.next('.modif-message-confirm').find('p.ask_modif_error').eq(0).remove();					form_element.next('.modif-message-confirm').find('p').eq(0).show();					form_element.next('.modif-message-confirm').find('p').eq(1).show();				}				form_element.next('.modif-message-confirm').fadeIn();			});					}		
		/* submit form */		//GM: gm_moderation is declared in my-plugins/gm-moderation-a-priori/js/gm_moderation_a_priori.js		$.gm_moderation.submit_modification_form($(this).parents('.form-edit-message').eq(0),submit_success);		//End GM
		/* end submit form */
		
		return false;
	});
	
	$('.modif-reponse').find('.bouton-action-annuler').click ( function () {
		$(this).parents('.modif-reponse').eq(0).slideUp();		
		return false;
		
	});
	
	$('.modif-message-confirm').find('.bouton-action-annuler').click ( function () {
		$(this).parents('.modif-message-confirm').eq(0).hide();		
		return false;
		
	});
	
	$('.afficher-reponse').click ( function () {		$.scrollTo($('#forum-reponse').position().top - navHeight, 1000, {
			onAfter: function () {
				$('.forum-reponse').slideDown();
			}
		} );
		return false;
	});		$('.derniere-rep').click ( function () {		var split = $(this).attr('href').split('#');		var post_id = split[1];					if( $('#'+post_id).length ){			$.scrollTo($('#'+post_id).position().top - navHeight + 10, 1000);			return false;		}	});		$('.post_permalink').click ( function () {		var post_id = $(this).attr('href')					if( $(post_id).length ){			$.scrollTo($(post_id).position().top - navHeight + 10, 1000);			return false;		}	});		var current_url = window.location;	var post_anchor = current_url.hash.substring(1);	if( post_anchor != '' && post_anchor.match(/post-\d+/) ){		//global "navHeight" may not be known here:		var localNavHeight = $('.nav').outerHeight(true);		$.scrollTo($('#'+post_anchor).position().top - localNavHeight + 10, 1000);	}		$('div.club-annuaire').click(function(){		window.open( $('a',this).eq(0).attr('href') );	});		$('div.club-agenda').click(function(){		window.open( $('a',this).eq(0).attr('href') );	});	
});

