/*	
**	fonction modifiant l'attribut class d'un element dans le but de le rendre visible ou invisble
**	si l'on ouvre un menu cela ferme tous les autres ouverts
*/
function	show_hide(id)
{
	var MC	= menuControler.getInstance();
	
	MC.getMenu("menu_editorial").onClickCategory(id);
}

function	select_edit_menu()
{
	var url = '';
	var docUrl = '';
	var MC	= menuControler.getInstance();
	
	jQuery("#editorial_menu").children("ul").each(function(i)
	{
		jQuery(this).children("li").each(function(j)
		{
			if (jQuery(this).children("ul").length > 0)
			{
				ul = jQuery(this).children("ul:first");
				ul.children("li").each(function(k)
				{
					url = get_clean_url(jQuery(this).find("a:first").attr("href"));
					docUrl = get_clean_url(document.URL);
					if (url == docUrl)	{
						MC.getMenu("menu_editorial").onClickCategory(jQuery(this).parent().attr("id"));
						jQuery(this).attr("class", "current_page_item");
					}
				});
			}
		});
	});
}

function get_clean_url(url)
{
	var com = /.com/;
	if (url.search(com) != -1)
		return url = url.split('.com')[1];
	return url;
}

/*
**	fonction allant modifier la structure du menu editorial généré par WordPress (voir _intro.php ligne 179)
**	pour incorporer des menus déroulant pouvant donner accès aux sous-catégories des pages.
*/
function	modif_edit_menu()
{
	var	i			= 0;
	var	j			= 0;
	var	k			= 0;
	var	tmp			= 0;
	var	new_id		= "";
	var url			= "";
	var content		= "";
	var ul			= null;

	//	initialisation du menuControler
	var MC	= menuControler.getInstance();
	var M	= MC.addMenu("menu_editorial");
	M.closeOthers = true;
	//-------------------------

	jQuery("#editorial_menu").children("ul").each(function(i){
		jQuery(this).children("li").each(function(j)
		{
			jQuery(this).attr('class', '');
			if (jQuery(this).children("ul").length > 0)	{
				/*
				//	recuperation d'info de l'ancienne balise <a>
				new_id = "emenu_" + i + "_" + j;
				if (jQuery(this).children("a").length > 0)	{
					url = jQuery(this).children("a:first").attr("href");
					content = jQuery(this).children("a:first").html();
				}	else	{
					url = jQuery(this).children("span:first").children("a:first").attr("href");
					content = jQuery(this).children("span:first").children("a:first").html();
				}
				//-------------------------

				//	déplacement de l'ancienne balise <a>
				jQuery(this).children("ul:first").prepend("<li></li>");
				if (jQuery(this).children("a").length > 0)	{
					jQuery(this).children("ul:first").children("li:first").prepend(jQuery(this).children("a:first"));
				}	else	{
					jQuery(this).children("ul:first").children("li:first").prepend(jQuery(this).children("span:first"));
				}
				tmp = jQuery(this).children("ul:first").children("li:first").find("a");
				//tmp.html("Sommaire - " + tmp.html());
				tmp.html("Sommaire");
				//-------------------------

				//	ajout de la nouvelle balise <a>
				jQuery(this).prepend('<a href="javascript:show_hide(\'' + new_id + '\');" >' + content + '</a>');
				
				//	rajout de different attributs aux balises <ul>
				jQuery(this).children("ul:first").attr({
					id: new_id,
				});
				*/
				
				//	ajout de la category dans le menuControler
				ul = jQuery(this).children("ul:first");
				
				M.addCategory(jQuery(this).children("a:first"), ul);
				//-------------------------
				
				//	fermeture des menus
				ul.children("li").each(function(k)
				{
					jQuery(this).attr("class", "");
					if (get_clean_url(jQuery(this).find("a:first").attr("href")) == get_clean_url(document.URL))	{
						M.onClickCategory(jQuery(this).parent().attr("id"));
						jQuery(this).attr("class", "current_page_item");
					}
				});
				//-------------------------
			}
		});
	});	
}

/*
**	fonction afficher/cacher simplifiée 
*/
function simple_sh(node, style_attr_discovered, style_attr_hidden, style_link_discovered, style_link_hidden)
{
	var next = node.nextSibling;
	
	while (next.nodeType != Node.ELEMENT_NODE)
	{
		next = next.nextSibling;
	}
	if (next.getAttribute("class") == style_attr_discovered) {
		node.setAttribute("class", style_link_hidden);
		next.setAttribute("class", style_attr_hidden);
	} else if (next.getAttribute("class") == style_attr_hidden) {
		node.setAttribute("class", style_link_discovered);
		next.setAttribute("class", style_attr_discovered);
	} else {
		node.setAttribute("class", style_link_discovered);
		next.setAttribute("class", style_attr_discovered);
	}
}
