
var useragent = navigator.userAgent;
useragent = useragent.toLowerCase();
//alert(useragent)
if (useragent.indexOf('iphone') != -1 || useragent.indexOf('symbianos') != -1 || useragent.indexOf('skyfire') != -1 || useragent.indexOf('ipad') != -1 || useragent.indexOf('ipod') != -1 || useragent.indexOf('android') != -1 || useragent.indexOf('blackberry') != -1 || useragent.indexOf('samsung') != -1 || useragent.indexOf('nokia') != -1 || useragent.indexOf('windows ce') != -1 || useragent.indexOf('sonyericsson') != -1 || useragent.indexOf('webos') != -1 || useragent.indexOf('wap') != -1 || useragent.indexOf('motor') != -1 || useragent.indexOf('symbian') != -1 ) {
	$(document).ready(function(){
	
		$("li.niv1").each(function(){
		
			if($(this).children("ul").html() != null)
			{
				slLien = $(this).children("span").children("a").attr("href")
				slNom = $(this).children("span").children("a").html();
				slClass = $(this).children("span").children("a").attr("class")
				n = $(this).children("ul").children("li.niv2").length;
				slCurrent ="";					
				if(document.URL == slLien)
				{
					slCurrent = "current"
				}					
			
				
				$(this).children("span").children("a").attr("rel","").attr("href","javascript:void(0)")					
				$(this).children("ul").prepend("<li class='niv2 premier "+ slCurrent +"'><span><a href='"+ slLien +"' class='"+ slClass +"'>"+ slNom +"</a></span></li>")	
			
				if(n==1)
				{	
					var value = $(this).children("ul").children("li").eq(1).attr("class")
					newValue = value.replace("premier", "dernier"); 
				}
				else
				{
					var value = $(this).children("ul").children("li").eq(1).attr("class")						
					newValue = value.replace("premier", " "); 
					$(this).children("ul").children("li").eq(1).attr("class",newValue)	
				}
								
			}
		})
		
		
		$("li.niv2").each(function(){
		
			if($(this).children("ul").html() != null)
			{
				slLien = $(this).children("span").children("a").attr("href")
				slNom = $(this).children("span").children("a").html();
				slClass = $(this).children("span").children("a").attr("class")
				n = $(this).children("ul").children("li.niv2").length;
				slCurrent ="";					
				if(document.URL == slLien)
				{
					slCurrent = "current"
				}					
			
				
				$(this).children("span").children("a").attr("rel","").attr("href","javascript:void(0)")					
				$(this).children("ul").prepend("<li class='niv3 premier "+ slCurrent +"'><span><a href='"+ slLien +"' class='"+ slClass +"'>"+ slNom +"</a></span></li>")	
			
				if(n==1)
				{	
					var value = $(this).children("ul").children("li").eq(1).attr("class")
					newValue = value.replace("premier", "dernier"); 
				}
				else
				{
					var value = $(this).children("ul").children("li").eq(1).attr("class")						
					newValue = value.replace("premier", " "); 
					$(this).children("ul").children("li").eq(1).attr("class",newValue)	
				}
								
			}
		})
		
		 $('#conteneur').click(function() {
			 
			$("li.niv2").each(function(){
				$(this).parent("ul").css("left","-999em")
			})
		 });
		
		 $('li.niv1').click(function(event){
			 event.stopPropagation();
		 });

		
		$("li.niv1").click(function(){
			$("li.niv2").each(function(){
				$(this).parent("ul").css("left","-999em")
			})
			$(this).children("ul").css("left","auto")
		
		})
		
		
		
	 })
}



function closeSousMenu(){
	$("li.niv2").each(function(){
		$(this).parent("ul").css("left","-999em")
	})
	
}
