var pan="#cr0";
var intervalo_scroll;
//***********************************************************************************************************************************
//***********************************************************************************************************************************
//***********************************************************************************************************************************
//***********************************************************************************************************************************
/* ======================== botones MENUS  ======================*/
// Al elegir una opcion de menu
function opcMnu(sId){
	//suma una pantalla
	pan = pan + "#" + sId;
	// muestra el boton atras
	document.getElementById('atras').style.visibility = "visible";
	
	var oElegido = document.getElementById(sId);
	var aSpan = oElegido.getElementsByTagName("span");
	
	document.getElementById("titulos").innerHTML = "<span class='titulos_elegidosCR'>" + aSpan[0].innerHTML + "</span>";
//	document.getElementById("titulos").style.border="1px solid #000000";
	
	if (document.getElementById(sId).getAttribute("type") == "mnu"){
		document.getElementById("contenidos").innerHTML = "<span class='opciones_menuCR'>" + aSpan[1].innerHTML + "</span>";
	} else if (document.getElementById(sId).getAttribute("type") == "lsta1"){
		document.getElementById("contenidos").innerHTML =  "<span class='listaCR1'>" + aSpan[1].innerHTML + "</span>";
	} else if (document.getElementById(sId).getAttribute("type") == "lsta2"){
		// muestra los botones para subir y bajar texto de las listas
		document.getElementById("arriba").style.visibility = "visible";//hidden
		document.getElementById("abajo").style.visibility = "visible";//hidden

		document.getElementById("contenidos").innerHTML =  "<span class='listaCR2'>" + aSpan[1].innerHTML + "</span>";
		
		scrolineas();
	} 
	
}


/* ======================== botón VOLVER atras ======================*/
// Al pulsar el botón volver atras
function panAtras(){
	// elimina el intervalo del scroll de lista
	clearInterval(intervalo_scroll);

	// oculta los botones para subir y bajar texto de las listas
	document.getElementById("arriba").style.visibility = "hidden";//visible
	document.getElementById("abajo").style.visibility = "hidden";//visible
	
	// ROB 21/07/10
	// pone el div 'contenidos' en la posicion de 90px que sale en el CSS, por si se ha movido (PETITS EXPLORADORS contes)
	// hace que al ir atras vaya a la pantalla correcta del menu
	var contTop = document.getElementById('contenidos').style.top;
	if((contTop!='90px') && (contTop!='')){
		var panPEx = pan.toString().split("#");

		pan="";
		for(i=1; i < 6; i++){
			pan += ("#" + panPEx[i]);
		}
		document.getElementById('contenidos').style.top='90px';
	}
	contTop="";

	if(pan != "#cr0"){
		var destino = "";
		var trozo = "";
		trozo = pan.split("#");
		pan = "";
		for (var i =0 ;i < (trozo.length - 1) ; i++){
			if(i>0){
				pan += ("#" + trozo[i]);
			}
		}

		trozo = pan.split("#");
		destino = trozo[trozo.length -1];
		
		//location.href=("#" + destino);
		var aSpan = document.getElementById(destino).getElementsByTagName("span");
		// titulos
		document.getElementById("titulos").innerHTML = "<span class='titulos_elegidosCR'>" + aSpan[0].innerHTML + "</span>";

		// si ha llegado a la primera pantalla
		if(destino=="cr0") {
			document.getElementById("contenidos").innerHTML =  "<span class='menu_principalCR'>" + aSpan[1].innerHTML + "</span>";
			// oculta el boton si llega al inicio y muestra el menu inicial
			document.getElementById('atras').style.visibility = "hidden";
		} 
// volviendo atras nunca se va a encontrar una lista
/*else if(document.getElementById(destino).getAttribute("type")=="lsta1"){
	document.getElementById("contenidos").innerHTML =  "<span class='listaCR'>" + aSpan[1].innerHTML + "</span>";
} else if(document.getElementById(destino).getAttribute("type")=="lsta2"){
	document.getElementById("contenidos").innerHTML =  "<span class='listaCR'>" + aSpan[1].innerHTML + "</span>";
}*/
		else if(document.getElementById(destino).getAttribute("type")=="mnu"){
			document.getElementById("contenidos").innerHTML =  "<span class='opciones_menuCR'>" + aSpan[1].innerHTML + "</span>";
		}
		
	} else {
		// oculta el boton si llega al inicio y muestra el menu inicial
		document.getElementById('atras').style.visibility = "hidden";
		document.getElementById("contenidos").innerHTML =  "<span class='menu_principalCR'>" + aSpan[1].innerHTML + "</span>";

	}

}

/* ======================== botones ARRIBA ABAJO ======================*/
function scrolineas(){
	//crea primero un nuevo div sobre el que meter el texto del scroll (Rob)	
	var oNuevocontainer = document.createElement("div");
	oNuevocontainer.id= "contenedor";
	var oPadre = document.getElementById("contenidos");
	oNuevocontainer.innerHTML= oPadre.innerHTML;
	oPadre.innerHTML="";
	oPadre.appendChild(oNuevocontainer);


	// id of the container element 
	var id = "contenedor";

	// movement speed
	var speed = 5;
	
	// desired height of the container element (in pixels)
	var height = 225;
	
	var obj = document.getElementById(id);
	
	obj.up = false;
	obj.down = false;
	obj.fast = false;

	// crea un elemento div por encima del div que contiene el texto a mover
	var container = document.createElement("div");
	var parent = obj.parentNode;
	container.id="lineascroll";
	parent.insertBefore(container,obj);
	parent.removeChild(obj);

	container.style.position = "relative";
	container.style.height = height + "px";
	container.style.overflow = "hidden";
	obj.style.position = "absolute";
	obj.style.top = "0";
	obj.style.left = "0";
	container.appendChild(obj);

	
	document.getElementById("arriba").onmouseover = function(){
		obj.up = true;
		this.className = "over";
	};
	document.getElementById("arriba").onmouseout = function(){
		obj.up = false;
		this.className = "";
	};		
	document.getElementById("abajo").onmouseover = function(){
		obj.down = true;
		this.className = "over";		
	};
	document.getElementById("abajo").onmouseout = function(){
		obj.down = false;
		this.className = "";
	};		
	document.getElementById("arriba").onmousedown = document.getElementById("abajo").onmousedown = function(){
		obj.fast = true;
	};
	document.getElementById("arriba").onmouseup = document.getElementById("abajo").onmouseup = function(){
		obj.fast = false;
	};


	this.start = function(){				
		var newTop;
		var objHeight = obj.offsetHeight;
		var top = obj.offsetTop;
		var fast = (obj.fast) ? 2 : 1;
		if(obj.down){		 
			newTop = ((objHeight+top) > height) ? top-(speed*fast) : top;	
			obj.style.top = newTop + "px";
		};	
		if(obj.up){		 
			newTop = (top < 0) ? top+(speed*fast) : top;
			obj.style.top = newTop + "px";
		};
	};
	// crea el intervalo de scroll de lista
	//obj.interval = setInterval("start()",50);
	intervalo_scroll = setInterval("start()",50);;
}

/* ======================== VALIDAR CLAVE FENT CAMÍ ======================*/
var testRob ="";

function validarClauFC() {
var clau = "hermitage";
var clauRob="ormolab";
var result = true;
testRob ="";
if (document.getElementById('acceso_Fcami').value!= clau) {
	if (document.getElementById('acceso_Fcami').value!= clauRob) {
		alert ("Clau incorrecta" + "\n" + document.getElementById('acceso_Fcami').value);
		result = false;
	} else {
		testRob ="PRUEBAROB";
	}
} 
return result;
}
/* ======================== VALIDAR CLAVE PETITS EXPLORADORS ======================*/
function validarClauPE() {
var clau = "exploradors";
var clauRob="ormolab";
var result = true;
testRob ="";
if (document.getElementById('acceso_PExplo').value!= clau) {
	if (document.getElementById('acceso_PExplo').value!= clauRob) {
		alert ("Clau incorrecta" + "\n" + document.getElementById('acceso_PExplo').value);
		result = false;
	} else {
		testRob ="PRUEBAROB";
	}
} 
return result;
}
/* ======================== VALIDAR CLAVE LLETRES LLIGADES ======================*/
function validarClauLL() {
var clau = "lligades";
var clauRob="ormolab";
var result = true;
testRob ="";
if (document.getElementById('acceso_Llelli').value!= clau) {
	if (document.getElementById('acceso_Llelli').value!= clauRob) {
		alert ("Clau incorrecta" + "\n" + document.getElementById('acceso_Llelli').value);
		result = false;
	} else {
		testRob ="PRUEBAROB";
	}
} 
return result;
}
/* ======================== VALIDAR CLAVE FITA/EN MARXA ======================*/
function validarClauFita() {
var clau = "hermitage";
var clauRob="ormolab";
var result = true;
testRob ="";
if (document.getElementById('acceso_Fita').value!= clau) {
	if (document.getElementById('acceso_Fita').value!= clauRob) {
		alert ("Clau incorrecta" + "\n" + document.getElementById('acceso_Fita').value);
		result = false;
	} else {
		testRob ="PRUEBAROB";
	}
} 
return result;
}

/* ======================== ABRIR VENTANA FENT CAMÍ ======================*/
var ventanaNueva;
function ventanaFC(sURL,sNombre)
{
	ventanaNueva=window.open(sURL,sNombre,'dependent=no,alwaysRaised=yes,left=0,top=0,location=no,menubar=no,resizable=no,status=no,titlebar=no,toolbar=no,scrollbars=no');
	if (window.focus)
		ventanaNueva.focus();
}


/* ======================== ABRIR VENTANA FENT CAMÍ VIDEOS ======================*/
var ventanaVideo;
function ventanaVideo(sURL,sNombre)
{

/********************
   var ancho = 75
   var alto = 55
   var fin = 300
   var x = 100
   var y = 100
 
   function inicio(){
    ventana = window.open(sURL, "_blank", "resizable,height=1,width=1,top=x,left=y,screenX=x,screenY=y");
    abre();
   }
 
   function abre(){
    if (ancho <= fin) {
     ventana.moveTo(x, y);
     ventana.resizeTo(ancho, alto);
     x += 5;
     y += 5;
     ancho += 15;
     alto += 15;
     timer = setTimeout("abre()", 1);
    } else {
     clearTimeout(timer);
    }
   }
 
  </script>
*/

ventanaVideo=window.open(sURL,sNombre,'dependent=no,alwaysRaised=yes,left=450,top=200,location=no,menubar=no,resizable=no,status=no,titlebar=0,toolbar=no,scrollbars=no,height=440,width=510');
	if (window.focus)
		ventanaVideo.focus();
}
/* ======================== IMAGENES CON SHADOWBOX ======================*/
// JPG
function verImgShadowBox(sTitulo,sContenido,sAncho,sAlto) {
//<a href=\'http://www.baula.com/lib/descargaFCdocs.php?arch=UD2.exe\'><b> + sTitulo + </b></a>
	var titol="<a href=\"http://www.baula.com/lib/descargaMMdocs.php?arch=" + sContenido + "\"><span style=\"margin-top:-30;font-size:10pt\">descarrega't</span> <b style=\"text-transform:uppercase;\">" + sTitulo + "</b></a>";
	Shadowbox.open({
		player:"img",
		content:("http://www.baula.com/imgs/" + sContenido),
//		content:("http://localhost/Baula/imgs/" + sContenido),
//		title:sTitulo,
		title:titol,
		width:sAncho,
		height:sAlto
	});
}


/* ======================== VIDEOS CON SHADOWBOX ======================*/
// FLV
function verFlvShadowBox(sTitulo,sContenido,nAncho,nAlto) {
//<a href=\'http://www.baula.com/lib/descargaFCdocs.php?arch=UD2.exe\'><b> + sTitulo + </b></a>
	var titol="<a href=\"http://www.baula.com/lib/descargaMMdocs.php?arch=" + sContenido + "\"><span style=\"margin-top:-30;font-size:10pt\">descarrega't</span> <b style=\"text-transform:uppercase;\">" + sTitulo + "</b></a>";
	var ancho=nAncho;
	var alto=nAlto;
	if(ancho ==undefined) ancho=320; //si no hay datos de ancho
	if(alto ==undefined) alto=240; //si no hay datos de alto

	Shadowbox.open({
		player:"flv",
		content:("http://www.baula.com/centres/videosyMM/" + sContenido),
//		content:("http://localhost/Baula/" + sContenido),
//		title:sTitulo,
		title:titol,
		height:alto,
		width:ancho
	});
}
// SWF
function verSwfShadowBox(sTitulo,sContenido,nAncho,nAlto) {
//	var titol="<a href=\"http://www.baula.com/lib/descargaMMdocs.php?arch=" + sContenido + "\"><span style=\"margin-top:-30;font-size:10pt\">descarrega't</span> <b style=\"text-transform:uppercase;\">" + sTitulo + "</b></a>";
	var titol=sTitulo;
	if(ancho ==undefined) ancho=320; //si no hay datos de ancho
	if(alto ==undefined) alto=240; //si no hay datos de alto
	var ancho=nAncho;
	var alto=nAlto;
	Shadowbox.open({
		player:"swf",
		content:("http://www.baula.com/centres/videosyMM/" + sContenido),
		//content:("http://localhost/Baula/centres/videosyMM/" + sContenido),
		title:titol,
		height:alto,//height:240,
		width:ancho//width:320
	});
}
// HTML No funciona con urls, pero si con codigo HTML
function verHtmlShadowBox(sTitulo,sContenido) {
	Shadowbox.open({
		player:"html",
//		content:("http://www.baula.com/centres/videosyMM/" + sContenido),
		content:("http://localhost/Baula/centres/videosyMM/" + sContenido),
//		content:"<div><p style='color:#FFFFFF'>HHOOLLAA</p></div>",
//		content:"<div><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='340' height='255' id='prueba2v2' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='http://localhost/Baula/centres/videos/prueba2v2.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='http://localhost/Baula/centres/videos/prueba2v2.swf' quality='high' bgcolor='#ffffff' width='340' height='255' name='prueba2v2' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object></div>",
		title:sTitulo,
		height:240,
		width:320
	});
/*
	Shadowbox.setup("a.movie", {
		gallery:"My Movies",
		autoplayMovies:true
	});
*/
}
// HTML y MP3 No funciona con urls, pero si con codigo HTML
/*
function mp3ShadowBox(sTitulo,sContenido) {
	Shadowbox.open({
		player:"html",
		content:"<div><p style='color:#FFFFFF'>MP3</p></div><bgsound src='" + ("http://localhost/Baula/" + sContenido) + "' loop='-1'></div>",
		title:sTitulo,
		height:240,
		width:320,
	});
}
*/
function mp3ShadowBox(sTitulo,sContenido) {
//<a href=\'http://www.baula.com/lib/descargaFCdocs.php?arch=UD2.exe\'><b> + sTitulo + </b></a>
	var titol="<a href=\"http://www.baula.com/lib/descargaMMdocs.php?arch=" + sContenido + "\"><span style=\"margin-top:-30;font-size:10pt\">descarrega't</span> <b style=\"text-transform:uppercase;\">" + sTitulo + "</b></a>";
	Shadowbox.open({
	player: 'flv',
//	title: sTitulo,
	title:titol,
//	content:"image=http://localhost/Baula/centres/videos/fachada_Baula.jpg&file=http://localhost/Baula/centres/videos/Pista1_UD1.mp3",
	//content:("http://localhost/Baula/" + sContenido),
	content:("http://www.baula.com/centres/videosyMM/" + sContenido),
	height:240,
	width:320
	});
}
