
(function($){
	var encours = false;
	var params = {
		pixel: 15,
		timeOut: 1.5,
		maxHeight: 0
	};
	$.fn.jbAccordeon = function(uparams){
		var accordeon = $(this);
		var lastOpen = null;

		params.maxHeight = accordeon.height();

		$('.head', accordeon).each(function(){
			params.maxHeight = params.maxHeight - $(this).outerHeight();
			$(this).parent()
				.css('overflow','hidden')
				.css('height', $(this).outerHeight())
				.addClass('jb'+$(this).outerHeight());
		});

		params = $.extend(params,uparams);

		$('.head', accordeon).mouseover(function(){
			if (encours == true)
				return false;
			if ($(this).is('.selected'))
				return false;

			$(this).addClass('selected');
			encours = true;

			var courant = $(this).parent();

			if (lastOpen != null){
				$('.head', lastOpen).removeClass('selected');
				var origineH = lastOpen.attr('class').substring(2);
				lastOpen.animate({'height': origineH},{
					duration: 1000, 
					easing: 'easeOutBounce'
				});
			}

			var finalH = courant.height();
			courant.animate({'height': params.maxHeight},
				1000,
				'easeOutBounce', 
				function(){
					//alert('Fin du deroulement');
					encours = false;
				}
			);

			if (lastOpen != null){
				lastOpen.prev('a.head').removeClass('selected');
			}
			lastOpen = courant;
			return true;
		});
	};
})(jQuery);
