$(document).ready(function(){
	myNav = {
		obj:false,
		parent:false,
		rub:false,
		url:{
			root:document.location.href,
			param:false
		},
		init:function(z) {
			this.obj = $(z);
			this.active();			
		},		
		active:function() {		
			var ref = this;
			
			// masque tous les sous menus
			this.obj.each(function() {	
				if(!!$(this).next().length) {ref.hide($(this).next()); };
			});	
			
			// evénement au click
			this.obj.click(function() { 
				ref.set_show($(this));
				if(this.href.split(ref.url.root)[1] == "#" || this.href.split(ref.url.root)[1] == "") return false;
			});	
			
			// préselection de la nav			
			(this.get_param()) ? this.init_nav():'';
		},
		init_nav:function() { // préselection de la nav
			if(this.url.param[1]){
				var myLink = this.url.param[0].value+""+this.url.param[1].value;
				if(!!$("#"+myLink)) this.set_show($("#"+myLink));
			}			
			/*
			// préselection du contenu sur la droite
			chargeListArticle(this.url.param[0].value,this.url.param[1].value,'');
			*/
		},
		get_param:function() { // récupére les paramétres dans l'url
			
			var tmpParam0 = document.location.href.split("?");
			
			this.url.param = (tmpParam0.length>1)? new Array(): false;
		
			(!!this.url.param) ? this.url.root = tmpParam0[0]: '';
			if(!!tmpParam0[1]) {
				for(var i=1; i<tmpParam0.length; i++) {
					var tmpParam1 = tmpParam0[i].split("&");
					
						for(var j=0; j<tmpParam1.length; j++) {
							var myParam = tmpParam1[j].split("=");
							this.url.param[this.url.param.length] = {
								name:myParam[0]+"",
								value:myParam[1]+""
							};
						}						
					
				}
				return (!!this.url.param);
			} else return false;
		},
		set_show:function(obj) {
			var ref = this;
			
			// on regroupe les liste a afficher
			ref.rub = new Array();
			obj.next().each(function() { ref.rub[ref.rub.length] = this;});
			ref.get_parent(obj).each(function() { ref.rub[ref.rub.length] = this;});
			
			// on active chaque sous niveau concerné
			$("#contentMenu ul").removeClass("active");
			for(var i=0; i<ref.rub.length; i++) {
				
				ref.show(ref.rub[i]);
			};
		},
		get_parent:function(obj){
			return obj.parents("ul");
		},
		hide:function(obj) {
			if(!!obj.className) {
				if(obj.className.indexOf("active") != -1) {
					obj.className = obj.className.replace("active","")
				}
			}
		},
		show:function(obj) {
			if(obj.className.indexOf("active") == -1) {
				if(obj.className == "") obj.className = "active";
				else obj.className += " active";
			}
		}
		
	};
	
	myNav.init("#contentMenu li > a");
	
});
