var seccion = 'palacete';
var VISITA = 
{
	init : function()
	{	
		VISITA.rotarImagenes(1);
		//VISITA.cargarEnlaces('palacete');
		var opcImg = document.getElementById('capaNavSubContenido').getElementsByTagName('a');
		for (cont = 0; cont<opcImg.length; ++cont)
		{
			document.getElementById(opcImg[cont].id).onmouseover = function()
			{
				VISITA.ocultarTexto();
				/* carga texto negro */
				document.getElementById('txt'+this.id.substring(3,this.id.length)).className = 'visible';
				var srcimg = document.getElementById('img'+this.id.substring(3,this.id.length)).src;
				
				VISITA.ocultaImagenMenu(false);
				/* cambia la imagen */
				if (document.getElementById(this.id).className != 'active')
				{
					srcimg = srcimg.substring(0,srcimg.lastIndexOf('.'))+'_on'+srcimg.substring(srcimg.lastIndexOf('.'),srcimg.length);
					document.getElementById('img'+this.id.substring(3,this.id.length)).src = srcimg;
				}
			}
			
			document.getElementById(opcImg[cont].id).onclick = function()
			{
				seccion = this.id.substring(3,this.id.length);
				//document.getElementById('contDcha').getElementsByTagName('img').length
				
				VISITA.ocultarTexto();
				VISITA.ocultaImagenMenu(true);
				VISITA.ocultarTextoCuerpo();
				//VISITA.ocultarEnlacesCuerpo();
				VISITA.ocultarImagenesDcha();
				/*if (this.id == 'lnkpalacete')
				{
					document.getElementById('capaEstaciones').className = 'visible';
				}
				else
				{
					document.getElementById('capaEstaciones').className = 'oculto';
				}*/				
				document.getElementById(this.id.substring(3,this.id.length)).className = 'visible';
				document.getElementById('lnk'+this.id.substring(3,this.id.length)).className = 'active';
				document.getElementById('txt'+this.id.substring(3,this.id.length)).className = 'active';
				
				var rutaImg = document.getElementById('img'+this.id.substring(3,this.id.length)).src;
				rutaImg = rutaImg.substring(0,rutaImg.lastIndexOf('.'))+'_on'+rutaImg.substring(rutaImg.lastIndexOf('.'),rutaImg.length);
				document.getElementById('img'+this.id.substring(3,this.id.length)).src = rutaImg;
				document.getElementById('img'+this.id.substring(3,this.id.length)+'_1').className = 'visible';
				//document.getElementById('capa'+this.id.substring(3,this.id.length)).className = 'visible';
				//VISITA.poner1activo('capa'+this.id.substring(3,this.id.length))
				
				//VISITA.cargarEnlaces(this.id.substring(3,this.id.length));
				return false;
			}
			
			/* VISITA VIRTUAL */
			
			/*document.getElementById('lnk360vinedo').onclick = function()
			{return false}
			document.getElementById('lnk360fermentacion').onclick = function()
			{return false}
			document.getElementById('lnk360barrica').onclick = function()
			{return false}*/
			
			/* PARA QUE APAREZCA EL TEXTO ORIGINAL */
			document.getElementById('capaNavSubContenido').onmouseout = function()
			{
				VISITA.ocultarTexto();
				VISITA.ocultaImagenMenu(false);
				var opcLnk = document.getElementById('capaNavSubContenido').getElementsByTagName('a');
				for (cont = 0; cont<opcLnk.length; ++cont)
				{
					if (document.getElementById(opcLnk[cont].id).className == 'active')
					{
						var opSel = opcLnk[cont].id.substring(3,opcLnk[cont].id.length);
						document.getElementById('txt'+opSel).className = 'visible';
					}
				}				
			}
		}
	},
	rotarImagenes : function(numero)
	{
		var imagenes = document.getElementById('contDcha').getElementsByTagName('img');
		for (cont = 0; cont<imagenes.length; ++cont)
		{
			document.getElementById(imagenes[cont].id).className = 'oculto';
		}
		if (document.getElementById('img'+seccion+'_'+numero))
		{
			document.getElementById('img'+seccion+'_'+numero).className = 'visible';
			++numero;
		}
		else 
		{
			document.getElementById('img'+seccion+'_1').className = 'visible';
			numero = 2;
		}
		setTimeout("VISITA.rotarImagenes("+numero+")","3000");
	},
	ocultarTexto : function()
	{
		var opcTxt = document.getElementById('capaNavTexto').getElementsByTagName('p');
		for (cont = 0; cont<opcTxt.length; ++cont)
		{
			document.getElementById(opcTxt[cont].id).className = 'oculto';
		}
	},
	ocultaImagenMenu : function(activo)
	{
		var opcLnk = document.getElementById('capaNavSubContenido').getElementsByTagName('a');
		for (cont = 0; cont<opcLnk.length; ++cont)
		{
			if (document.getElementById(opcLnk[cont].id).className != 'active')
			{
				var imgLnk = document.getElementById(opcLnk[cont].id).getElementsByTagName('img');
				document.getElementById(imgLnk[0].id).src = document.getElementById(imgLnk[0].id).src.replace('_on','');
			}
			else if (activo)
			{
				var imgLnk = document.getElementById(opcLnk[cont].id).getElementsByTagName('img');
				document.getElementById(imgLnk[0].id).src = document.getElementById(imgLnk[0].id).src.replace('_on','');
			document.getElementById(opcLnk[cont].id).className = '';
			}
		}
	},
	ocultarTextoCuerpo : function()
	{
		var opcCapas = document.getElementById('capasDatosContenido').getElementsByTagName('div');
		for (cont = 0; cont<opcCapas.length; ++cont)
		{
			document.getElementById(opcCapas[cont].id).className = 'oculto';
		}
	},
	ocultarEnlacesCuerpo : function()
	{
		var opcCapas = document.getElementById('capaEnlacesCuerpo').getElementsByTagName('div');
		for (cont = 0; cont<opcCapas.length; ++cont)
		{
			if ((document.getElementById(opcCapas[cont].id)) && (opcCapas[cont].id.indexOf('c360') < 0))
			document.getElementById(opcCapas[cont].id).className = 'oculto';
		}		
	},
	ocultarImagenesDcha : function()
	{
		var opcCapas = document.getElementById('contDcha').getElementsByTagName('img');
		for (cont = 0; cont<opcCapas.length; ++cont)
		{
			if (document.getElementById(opcCapas[cont].id))
			document.getElementById(opcCapas[cont].id).className = 'oculto';
		}		
	},
	cargarEnlaces : function(opcion)
	{
		var lnkCapa = document.getElementById('capa'+opcion).getElementsByTagName('a');
		for (cont = 0; cont<lnkCapa.length; ++cont)
		{
			if (lnkCapa[cont].id.indexOf('360') < 0)
			{
				document.getElementById(lnkCapa[cont].id).onclick = function()
				{
					VISITA.cambiarClaseLnk(this.id);
					document.getElementById(this.id).className = 'activo';
					VISITA.ocultarImagenesDcha();
					document.getElementById('img'+this.id.substring(3,this.id.length)).className = 'visible';
					return false;
				}
			}
		}
	},
	cambiarClaseLnk : function(opcion)
	{
		var opsLnk = document.getElementById('capa'+opcion.substring(3,opcion.lastIndexOf('_'))).getElementsByTagName('a');
		for (cont = 0; cont<opsLnk.length; ++cont)
		{
			if (opsLnk[cont].id.indexOf('360') < 0)
				document.getElementById(opsLnk[cont].id).className = '';
		}
	}/*,
	poner1activo : function(opcion)
	{
		var lnkCapa = document.getElementById(opcion).getElementsByTagName('a');
		for (cont = 0; cont<lnkCapa.length; ++cont)
		{
			if (lnkCapa[cont].id.indexOf('360') < 0)
				document.getElementById(lnkCapa[cont].id).className = '';
		}
		document.getElementById(lnkCapa[0].id).className = 'activo';
	}*/
}

/* LOAD */

function addLoadEvent(fn)
 {
	var old = window.onload;
	if(typeof window.onload != 'function')
		window.onload = fn;
	else
		window.onload = function()
		 {
			old();
			fn();
		 }
 }

addLoadEvent( function() { VISITA.init(); } );
