/*
$(document).ready(function(){ 
	
	alert("documento cargado");
	
	//ocultamos todas las secciones
	$("//div[@class*='content']").hide();
	//mostramos la primera seccion con id "sec-1"
	$("//div[@id='sec-1']").show();
	//y le añadimos la clase "sel" al LI del menu
	$("//a[@href*='sec-1']").parent().parent().addClass("sel");

	//añadimos el evento click a los enlaces del menu que cambiarán el contenido
	$("//a[@href*='#sec']").each(function(){
		$(this).click(function(){
			//ocultamos todas
			$("//div[@class*='content']").hide();
			
			//cogemos el href del enlace clicado
			var href = $(this).attr("href");
			//le quitamos la almohadilla
			var cont_id = href.substring(href.indexOf("#")+1,href.length);	
			//y mostramos el contenido correspondiente al href
			$("//div[@id='"+cont_id+"']").show();
			
			//quitamos la clase "sel" de todos los LI
			$("#menu > li").removeClass("sel");
			//y se lo ponemos al que contiene el enlace clicado
			$(this).parent().parent().addClass("sel");
			return false;	
		} );
	} );
	
	//añadimos el evento imprimir al enlace correspondiente
	$("//a[@href*='print']").click(function(){
		window.print();
		return false;
	} );
	
});

*/
function Abrir_Ventana(theURL,winName,features) { 
  window.open(theURL,winName,features);
  }

hideDiv = function(oDiv){
	oDiv.style.display = "none";
}
showDiv = function(oDiv){
	oDiv.style.display = "";
	
	//Ñapa -> si tiene subMenu -> lo resetreo
	if(oDiv.subMenuLinks && oDiv.subMenuLinks.length>0){
		oDiv.subMenuLinks[0].onclick();	
	}
}

hideAllDivs = function(arrDivs){
	for(var e=0;e<arrDivs.length;e++){
		hideDiv(arrDivs[e]);
	}
}

hideLink = function(oLink){
	var o=oLink;
	while(o.tagName.toUpperCase()!="LI") o=o.parentNode;
	o.className = "";
}
showLink = function(oLink){
	var o=oLink;
	while(o.tagName.toUpperCase()!="LI") o=o.parentNode;
	o.className = "sel";
}

showSubMenuLink = function(oLink){
	var o=oLink;
	while(o.tagName.toUpperCase()!="LI") o=o.parentNode;
	o.className = "subSel";
}
hideSubMenuLink = function(oLink){
	var o=oLink;
	while(o.tagName.toUpperCase()!="LI") o=o.parentNode;
	o.className = "subSelNone";
}




hideAllMenuLinks = function(){
	for(var e=0;e<document.menuLinks.length;e++){
		hideLink(document.menuLinks[e]);
	}
}

hideAllLinks = function(){
	for(var e=0;e<document.menuLinks.length;e++){
		hideLink(document.menuLinks[e]);
	}
}

hideOtherLinks = function(){
	for(var e=0;e<document.otherLinks.length;e++){
		hideLink(document.otherLinks[e]);
	}
}



initOnLoad=function(){
	
	var d = document;
	var menuHolder = d.getElementById("menu");
	var allDivs = d.getElementsByTagName("div");
	var allLinks = d.getElementsByTagName("a");
	var allMenuLinks = menuHolder.getElementsByTagName("a");
	
	d.otherLinks = [];
	d.contentDivs=[];
	d.menuLinks =[];
	
	
	//Monto un array con las capas de contenidos.
	for(var i=0;i<allDivs.length;i++){
		var oDiv = allDivs[i];
		if(oDiv.className=="content" && oDiv.id.indexOf("sec-")==0){
			d.contentDivs.push(oDiv);
		}
	}
	
	
	//cabeceras
	var h1 = d.getElementById("header");
	var h2 = d.getElementById("header2");
	
	//reprogramo los links a secciones.
	for(var i=0;i<allMenuLinks.length;i++){
		var oLink = allMenuLinks[i];
		if(oLink.href.indexOf("#sec")!=-1){
			oLink.divName = oLink.href.split("#")[1];
			oLink.divObject = document.getElementById(oLink.divName);
			oLink.onclick=function(){
				
				if(this.divName == "sec-0"){
			
						showDiv(h1);
						hideDiv(h2);
						
						hideAllDivs(document.contentDivs);
						showDiv(this.divObject);
						hideAllMenuLinks();
						return false;
				}
				

				showDiv(h2);
				hideDiv(h1);
						
				hideAllDivs(document.contentDivs);
				showDiv(this.divObject);
				hideAllMenuLinks();
				showLink(this);
				
				return false;
				
			}
			d.menuLinks.push(oLink);
		}
	}
	
	
	
	
	//preparo una estructura de menus

	for(var i=0;i<d.contentDivs.length;i++){
		var oDiv = d.contentDivs[i];
		var arrAll = oDiv.getElementsByTagName("a");
		if(arrAll.length == 0) continue;
	
		oDiv.subMenuLinks = [];
		oDiv.hideSubItems = function(){
			for(var j=0;j<this.subMenuLinks.length;j++){
				hideSubMenuLink(this.subMenuLinks[j]);
			}
		}
		
		for(var e=0;e<arrAll.length;e++){
			var oLink = arrAll[e];
			if(oLink.href.indexOf("$sec")!=-1){
				oLink.divName = oLink.href.split("$")[1];
				oLink.divContainer = oDiv;
				oLink.divObject = document.getElementById(oLink.divName); //oDiv;
				oLink.divTarget = oDiv.getElementsByTagName("div")[0];
				oLink.onclick=function(){
					this.divContainer.hideSubItems();
					showSubMenuLink(this);
					
					this.divTarget.innerHTML = this.divObject.innerHTML
					return false;
				}
				oDiv.subMenuLinks.push(oLink);
					
			}
		}
		//alert(oDiv.subMenuLinks[0]);
		if(oDiv.subMenuLinks.length>0) oDiv.subMenuLinks[0].onclick();
	}
	
	
	
	/*
	//reprogramo los links a subsecciones.
	for(var i=0;i<allLinks.length;i++){
		var oLink = allLinks[i];
		if(oLink.href.indexOf("$sec")!=-1){
			oLink.divName = oLink.href.split("$")[1];
			oLink.divObject = document.getElementById(oLink.divName);
			
			//localizo a mi div padre
			var o=oLink;
			while(o.tagName.toUpperCase()!="DIV") o=o.parentNode;
			oLink.divTarget = o.getElementsByTagName("div")[0];
				
			oLink.onclick=function(){
				hideOtherLinks();
				showLink(this);
				
				this.divTarget.innerHTML = this.divObject.innerHTML
				return false;
			}
			d.otherLinks.push(oLink);
		}
		
	}
	
	//Marco el 1º de las subsecciones
	d.otherLinks[0].onclick();
	*/
	
	
	
	
	
	


	//logoFCC
	var logoHome = document.getElementById("logoFCC");
	var logoMap = document.getElementById("logoMap");
	var logoPrint = document.getElementById("printLink");
	
	//Disparo el 1º enlace
	logoHome.onclick=logoMap.onclick=function(){
		return document.menuLinks[0].onclick();

	}
	
	
	//imprimir
	logoPrint.onclick=function(){
		window.print();
		return false;
	}
	
	
	//disparo el 1º
	logoHome.onclick();
	
	/*
	hideAllDivs(document.contentDivs);
	var oDiv = document.getElementById("sec-0");
	showDiv(oDiv);
	*/
	
}








