//////////////////////////////////////////////////////////////////////
//

$(document).ready(function()
{
	$('.glo_search a').click(function()
	{
		glossaire_search();
		return false;
	});

	$('.glo_menu a').click(function()
	{
		glossaire_get_words( $(this).html() );
		return false;
	});
	
	
	if (w)
	{
		glossaire_search ();
	}
	else
	{
		glossaire_get_words ('A');
	}
});


//////////////////////////////////////////////////////////////////////
//

function glossaire_search ()
{
	var request = $(".fld_search").val();
	// alert(request);
	if ( request )
	{
		var data_str = 'as_ajax=1&do=search&fld_search='+ request;
		$.ajax({
			cache: false,
			type: "POST",
			url: "include/glossaire-actions.php",
			data: data_str, 
			success: function(feedback)
			{
				feedback = feedback.split('|');
				glossaire_reset_letters('');
				$('.glo_wordofday h1').fadeOut(500, null);
				$('.glo_wordofday .cnt').html(feedback[0]);
				$('.glo_words').html(feedback[1]);
				glossaire_words_addclick();
				var first_word_id = $('.glo_words a:first').attr('id');
				glossaire_get_definition (first_word_id);
			}
		});		
	}
}

//////////////////////////////////////////////////////////////////////
//
function glossaire_get_words (letter)
{	
	glossaire_reset_letters(letter);
	
	var data_str = 'as_ajax=1&do=get_words&letter='+ letter;
		
	$.ajax({
		cache: false,
		type: "POST",
		url: "include/glossaire-actions.php",
		data: data_str, 
		success: function(feedback)
		{
			$('.glo_words').html(feedback);
			glossaire_words_addclick();
			var first_word_id = $('.glo_words a:first').attr('id');
			glossaire_get_definition (first_word_id);
		}
	});		
}


function glossaire_words_addclick ()
{
	$('.glo_words a').click(function (){
		glossaire_get_definition (this.id);
		return false;
	});	
}
//////////////////////////////////////////////////////////////////////
//
function glossaire_get_definition (word_id)
{
	glossaire_reset_words (word_id);
	
	var data_str = 'as_ajax=1&do=get_definition&word_id='+ word_id;
		
	$.ajax({
		cache: false,
		type: "POST",
		url: "include/glossaire-actions.php",
		data: data_str, 
		success: function(feedback)
		{
			$('.glo_definition').html(feedback);
			$('.glo_definition').css('display', 'none');
			$('.glo_definition').fadeIn(500, null);
		}
	});		
}

//////////////////////////////////////////////////////////////////////
//
function glossaire_reset_letters (letter)
{
	$('.glo_menu a').removeClass('current');
	$('.glo_menu #letter_'+letter).addClass('current');
}

//////////////////////////////////////////////////////////////////////
//
function glossaire_reset_words (word_id)
{
	$('.glo_words a').removeClass('current');
	$('.glo_words #'+word_id).addClass('current');
}

//////////////////////////////////////////////////////////////////////
//



//////////////////////////////////////////////////////////////////////
//
/*
function envoyer_la_page_open()
{
	Shadowbox.open({
        player:     'iframe',
        title:      ' ',
        content:    'admin_/modules/fonctions/1_envoyer-la-page/envoyer-la-page.php',
        height:     413,
        width:      420
    });
}

//////////////////////////////////////////////////////////////////////
//

function envoyer_la_page_submit_missing()
{
	// alert('envoyer_la_page_submit_missing');
	$('.feedback').removeClass('success');
	$('.feedback').addClass('failure');
	$('.feedback').html('Veuillez remplir correctement tous les champs');
}

//////////////////////////////////////////////////////////////////////
//

function envoyer_la_page_submit_success(feedback)
{
	// alert('envoyer_la_page_submit_success');
	$('.feedback').removeClass('failure');
	$('.feedback').addClass('success');
	$('.feedback').html(feedback);
}

//////////////////////////////////////////////////////////////////////
//

function envoyer_la_page_submit()
{
	// alert('envoyer_la_page_submit');
	
	if ( $('#nom').val() && $('#prenom').val() && $('#email').val() && $('#nom_ami').val() && $('#prenom_ami').val() && $('#email_ami').val() && $('#message').val() )
	{
		var data_str = $(".envoyer-a-un-ami :input").serialize();
		// alert(data_str);
		// requete ajax
		$.ajax({
			cache: false,
			type: "POST",
			url: "envoyer-la-page-submit.php?do=envoyer",
			data: data_str, 
			success: function(feedback)
			{
				// alert(feedback);
				// $('.sendtofriend').fadeOut(200, null);
				feedback = feedback.split('|');
				
				if (feedback[0] == 1)
				{
					envoyer_la_page_submit_success(feedback[1]);
				}
				else
				{
					envoyer_la_page_submit_missing();
				}
			}
		});		
	}
	else
	{
		envoyer_la_page_submit_missing();
	}
	
	// window.location = 'http://www.google.com';
	
}

//////////////////////////////////////////////////////////////////////
// Fermeture de l'iframe ouverte via Shadowbox
function envoyer_la_page_close()
{
	window.parent.Shadowbox.close();
}

*/