/*
    Human Message pour jQuery
    par Tommy Bergeron
    
    Inspiré de:
    http://code.google.com/p/humanmsg/
    http://humanized.com/weblog/2006/09/11/monolog_boxes_and_transparent_messages/
*/

//Opacité de les messages
var msgOpacity = .9;
//Délai après mouvement
var delai_mouvement = 2000;
//Délai sans mouvement
var delai_sans_mouvement = 5000;


function bindEvents() {
	$('body').click(removeMsg)
		     .keypress(removeMsg);
}

function removeMsg() {
	$('body').unbind('click', removeMsg)
	         .unbind('keypress', removeMsg);

	if ($('#humanMsg').css('opacity') == msgOpacity) {
		$('#humanMsg').animate({ opacity: 0 }, 500, function() { $(this).hide() });
    }
}

function afficher_message (msg, class_name) {
    var t1 = '';
    var t2 = '';
    
	if (msg == '') return false;
	
	clearTimeout(t2);
	
	$("body").append('<div id="humanMsg" class="'+class_name+'"><p></p></div>');
	
	$('#humanMsg p').html(msg);
	
	$('#humanMsg').show().animate({ opacity: msgOpacity }, 200, function() {
		if ($('#humanMsg').css('display') == 'none') {
			$('#humanMsg').animate({ bottom: 40 }, 200, 'linear', function() {
				$('#humanMsg').animate({ bottom: 0 }, 300, 'easeOutBounce', function() { $(this).css({ bottom: 0 }) });
			})
		}
	});

	t1 = setTimeout("bindEvents()", delai_mouvement);
	t2 = setTimeout("removeMsg()", delai_sans_mouvement);
}