/**
 * Selects the current tabs for dotclear2 with Gandi Hosting
 * Don't forget to modify your css style file !
 * Benjamin Bellamy - 2006
 **/

// current URL :
var url=window.location.href;
var cat_label="/category/";
var post_label="/post/";
var cat_found=false;

// If the current page is category page :
if(url.indexOf(cat_label,0)>0)
{
	cat_found=true;
}
// If the current page is category page :
else if(url.indexOf(post_label,0)>0)
{
	// we are looking for a <a href=".../category/..."> within a <p class="post-info">
	var p=document.getElementsByTagName("p");
	// for each <p>
	for(var i=0;i<p.length && !cat_found;i++)
	{
		// if its class is "post-info" :
		if(
			p[i].getAttribute("className")=="post-info"
			||
			p[i].getAttribute("class")=="post-info"
			)
		{
			// for each node in <p>
			for(var j=0;j<p[i].childNodes.length && !cat_found;j++)
			{
				// if it's a <a href> :
				if(p[i].childNodes[j].nodeName.toLowerCase()=="a")
				{
					// if there's a "/category/" in the url :
					if(p[i].childNodes[j].href.indexOf(cat_label,0)>0)
					{
						url=p[i].childNodes[j].href;
						cat_found=true;
					}
				}
			}
		}
	}
}
// if we found a category (sometimes we won't, as in homepage, searchpage...)
if(cat_found)
{
	var cat_div=null;
	// we are looking for a <div class="categories">
	var div=document.getElementsByTagName("div");
	// for each <div>
	for(var j=0;j<div.length && cat_div==null;j++)
	{
		// if its class is "post-info" :
		if(
			div[j].getAttribute("className")=="categories"
			||
			div[j].getAttribute("class")=="categories"
			)
		{
			cat_div=div[j];
		}
	}
	if(cat_div!=null)
	{
		var node_ul=null;
		// we're looking for a <ul> :
		for(var j=0;j<cat_div.childNodes.length && node_ul==null;j++)
		{
			if(cat_div.childNodes[j].nodeName.toLowerCase()=="ul")
			{
				node_ul=cat_div.childNodes[j];
			}
		}
		// if we found it (if we did not, it's a bug) :
		if(node_ul)
		{
			// for each child node, ie. for each <li>
			for(var i=0;i<node_ul.childNodes.length;i++)
			{
				// we assume the first child is a <a href> abd we compare its url to the one we found previously :
				if(node_ul.childNodes[i].firstChild.href.toLowerCase()==url.toLowerCase())
				{
					// we set <li> class :
					node_ul.childNodes[i].className="current";
					// we set <a href> class :
					//node_ul.childNodes[i].firstChild.className="current";
				}
			}
		}
	}
}