(function($){

	/* The plugin extends the jQuery Core with four methods */

        $.bounceBox = function(texte, erreur) {
                $('#box-notif').remove();
                var contenu = '<div id="box-notif">';
                        contenu += '<div class="container_25">';
                            contenu += '<div class="sprite grid_1" style="margin-left:33px;"></div>';
                            contenu += '<p class="grid_20"></p>';
                        contenu += '</div>';
                    contenu += '</div>';
                var box = $(contenu);
                $('body').append(box);
		$('#box-notif').bounceBox(texte, erreur);
	};

	/* Converting an element into a bounce box: */
	$.fn.bounceBox = function(texte, erreur){

		/*
			Applying some CSS rules that center the
			element in the middle of the page and
			move it above the view area of the browser.
		*/
                
                
		$('#box-notif').css({
			top		: -$('#box-notif').outerHeight(),
			position	: 'fixed',
			left		: '0',
                        width           : '100%'
		});

                if(erreur==true) {
                    $('#box-notif').addClass('erreurBox');
                    fermetureBox = setTimeout($j('#box-notif').bounceBoxHide, 7000);
                }else {
                    $('#box-notif').addClass('okBox');
                    fermetureBox = setTimeout($j('#box-notif').bounceBoxHide, 7000);
                }

                $('#box-notif p').html(texte);

                $('#box-notif').bounceBoxShow();
                $('#box-notif').live('click', $j('#box-notif').bounceBoxHide);

		return this;
	}

	/* The boxShow method */
	$.fn.bounceBoxShow = function(){

		/* Starting a downward animation */

		$('#box-notif').stop().animate({top:0},{easing:'easeOutBounce'});
		$('#box-notif').data('bounceShown',true);
		return this;
	}

	/* The boxHide method */
	$.fn.bounceBoxHide = function(){

		/* Starting an upward animation */

		$('#box-notif').stop().animate({top:-$('#box-notif').outerHeight()});
		$('#box-notif').data('bounceShown',false);
                clearTimeout(fermetureBox);
		return this;
	}

	/* And the boxToggle method */
	$.fn.bounceBoxToggle = function(){

		/*
			Show or hide the bounceBox depending
			on the 'bounceShown' data variable
		*/

		if($('#box-notif').data('bounceShown'))
			$('#box-notif').bounceBoxHide();
		else
			$('#box-notif').bounceBoxShow();

		return this;
	}

})(jQuery);
