(function( $ ){
	
	var el, active, months, settings;
	
	el = null;
	active = null;
	months = [ ];
	settings = { };
	
	function init() {
		
		months = el.children( 'li' );
		active = months.first();
		
		el.find( 'a.next' ).click( next );
		el.find( 'a.prev' ).click( prev );
		el.find( 'td.evenement a' ).hoverIntent( over, out );
		
		render();
	}
	
	function render() {
		
		months.hide();
		active.show();
		
		el.find( 'a.prev, a.next' ).show();
		
		if (active.is(':first-child')) el.find( 'a.prev' ).hide();
		if (active.is(':last-child')) el.find( 'a.next' ).hide();
	}
	
	function prev() {
		
		var prev;
		
		prev = active.prev();		
		active = ( prev.length === 1 ) ? prev : months.last();
		
		render();
		
		return false;
	}
	
	function next() {
		
		var next;
		
		next = active.next();
		active = ( next.length === 1 ) ? next : months.first();
		
		render();
		
		return false;
	}
	
	function over() {
		
		$(this).siblings( '.tooltip' ).show( 500 );
	}

	function out() {
		
		$(this).siblings( '.tooltip' ).hide( 500 );
	}

	$.fn.agenda = function( options ) {
		
		return this.each( function() {        
			
			if ( options ) { 
				$.extend( settings, options );
			}
			
			el = $(this);
			
			init();	
		});
	};

})( jQuery );
