// Javascript initialization.
window.onload = init;

//
// Affichage des cartes de randonnées.
function changeDisplay(obj){
	if(obj.style.display != 'block'){
	    obj.style.display = 'block';
	}else{
	    obj.style.display = 'none';
	}
}

//
// Show the commune object.
function showTips(idCommune, nomCommune){

	var element = "_root." + idCommune;
	var xcommune = document.map.TGetProperty(element, "0");
	var ycommune = document.map.TGetProperty(element, "1");
	var ncommune = document.map.TGetProperty(element, "13");

	document.map.SetVariable("_root.alt.message", nomCommune);
	document.map.TSetProperty("_root.alt", "0", xcommune);
	document.map.TSetProperty("_root.alt", "1", ycommune);
	document.map.TSetProperty("_root.alt", "7", "1");
}

//
// Hide the commune object.
function hideTips(data){
	document.map.TSetProperty("_root.alt", "7", "0");
	document.map.SetVariable("_root.alt.message", "");
}

/*
// Code below has been added 3 years later.
*/

// Show the subnavigation.
function switch_nav(){
	var nav    = document.getElementById("navigation");
	var subnav = nav.getElementsByTagName("h2");
	var subnavul = nav.getElementsByTagName("ul");

	// Parse and compare h2/ul Array show/hide ul in comparison of h2/ul.
	for(var i=0; i < subnav.length; i++){
		var linked = subnav[i].getElementsByTagName("a");
		for(j=0; j < linked.length; j++){
			if(linked[j].getAttribute("name") == this.name){
				if(subnavul[i].style.display != "block"){
					linked[j].setAttribute("class","current");
					subnavul[i].style.display = "block";
				}else{
					subnavul[i].style.display = "none";
					linked[j].setAttribute("class","");
				}
				return false;
			}
		}
	}
}

// Initialize the subnavigation.
function init(){
	var nav = document.getElementById("navigation");
	if(!nav) return;

	var subnav = nav.getElementsByTagName("h2");
	if(!subnav) return;

	// Add EventListner to any h2.a
	for(var i=0; i < subnav.length; i++){
		var trigger = subnav[i].getElementsByTagName("a");
		for(var j=0; j < trigger.length; j++){
			trigger[j].onclick = switch_nav;
		}
	}
}
