window.onload=montre;
function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}


var clsed=false;
var temp="";
var currentPos=0;
	
//****************
//Creation du menu
//****************

function parse_it()
{
	temp = "";
	var x=0;
	//alert(n);

	for(x=0;x<sections.length;x+=2)
	{
		if (actions[x])
		{
			//si il y a des sous-sections
			if(sections[x] < sections[x+2])
			{
				clsed = actions[x+2];
				if (clsed) 
					temp+= "<li><a href=\"javascript:change_visible("+x+");\" style='text-decoration:none; font-weight: bold;color:#87051b;background: url(http://demo.k3-media.com/constructionpremiere/ui/img/ico-minus.gif) no-repeat 0 50%;'>" + sections[x+1].substring(1,sections[x+1].length)+ "</a></li>" 
				else
				 	temp+="<li><a href=\"javascript:change_visible("+x+");\" style='text-decoration:none;color:#000000;background: url(http://demo.k3-media.com/constructionpremiere/ui/img/ico-plus.gif) no-repeat 0 50%;'>" + sections[x+1].substring(1,sections[x+1].length)+"</a></li>";
			}
			
			if(sections[x+1].indexOf("*") ==-1)
			{

				if(actions[x+1] != "")
				{
					if(sections[x+1].indexOf(selection) != -1)
						temp += "<ul class='clients'><li class='clients'><a class='active' href='" + actions[x+1] + "'>" + sections[x+1] + "</a></li></ul>";
					else
						temp += "<ul class='clients'><li class='clients'><a href='" + actions[x+1] + "'>" + sections[x+1] + "</a></li></ul>";
					
				}else{
					if(sections[x+1].indexOf(selection) != -1)
						temp += "<ul class='clients'><li class='ghosty'>" + sections[x+1] + "</li></ul>";
					else
						temp += "<ul class='clients'><li class='ghosty'>" + sections[x+1] + "</li></ul>";
				}
			}
		}
	}

	write_it(temp);
}

//******************************
// met tous les elements d'une 
// section visible ou pas
//******************************

function change_visible(startPos)
{

	//closeAll();

	currentPos=startPos+2;
	var startPos = sections[startPos];
	
	clsed = actions[currentPos];
	(clsed) ? clsed=false : clsed=true;
		
	while(sections[currentPos] != startPos && currentPos <sections.length)
	{
		if(clsed)
		{
			if(sections[currentPos]==startPos+1)
				actions[currentPos] = true;
		}
		else
		{
			if(sections[currentPos]==0)
				clsed=true;
			actions[currentPos]=clsed;
		}
		currentPos+=2;
	}
		
	parse_it();
}

function closeAll()
{
	for(x=0;x<actions.length;x+=2)
	{
		if(sections[x] > 0)
		{
			actions[x] = false;
		}	
	}
	
}

//*********** 
// ecrit
//***********

function write_it(temp)
{	
		
	if(document.getElementById)
		document.getElementById("my_menu").innerHTML=temp;
}
