/**
 * Options disponibles
 * - speed: vitesse du défilement en ms ou exprimé en chaîne à la jquery, par défaut: normal
 * - style: Type de menu déroulant ("accordion, "simple"): en accordéon, seul l'élément sélectionné 
 *   et son ascendance dans l'arboresence restent visible.
 */
(function($) {
	$.fn.lAccordion = function(settings) {
		var config = {};
		settings = $.extend(true,config,settings);
		return $.lAccordion.impl.init(this,settings);
	};
	
	$.lAccordion = function(elem,settings) {
		return $(elem).lAccordion(settings);
	};
	
	$.lAccordion.impl = {
		that: this,
		e: null,
		settings: null,
		style: null,
		
		init: function(e,settings)
		{
			var that = this;
			this.e = e;
			this.settings = settings;
			this.style = settings.style ? settings.style : "accordion";
			
			var uri = this.getUri();
			
			e.find("ul").hide();
			
			var links = e.find("li > a");
			links.each( function() {
				var $this = $(this);
				var href = $this.attr('href');
				if( href == "#" ) {
					$this.attr('href',"javascript:void(0)");
				} else {
					if( uri == href ) {
						$this.addClass('selected');
						$this.parents('ul').show();
						$this.parents('li').children('a').addClass('selected');
					}
				}
			} );
			
			links.click( function(event) {
				if( that.style == "accordion" ) {
					if( $(this).next("ul:visible").length != 0 ) {
						$(this).next("ul").slideUp(that.settings.speed);
			        } else {
			        	$(this).parent().parent("ul").find("ul").slideUp(that.settings.speed);
			        	$(this).find("ul").hide();
			        	$(this).next("ul").find("ul").hide();
			        	$(this).next("ul").slideDown(that.settings.speed);
			        }
				} else {
					if( $(this).next("ul:visible").length != 0 ) {
						$(this).next("ul").slideUp(that.settings.speed);
			        } else {
			        	$(this).next("ul").slideDown(that.settings.speed);
			        }
				}
			} );
		},
		
		getUri: function()
		{
			var url = document.URL.substr(7);
			var uri = url.substr(url.indexOf('/'));
			var diese = uri.indexOf('#');
			if( diese > -1 ) {
				uri = uri.substr(0,uri.indexOf('#'));
			}
			
			return uri;
		}
	};
	
	

} )(jQuery);

















