var VISITA = {
	init : function()
	{
		if (document.getElementById('capa_opcimg_inf'))
		{
			var opc_img = document.getElementById('capa_opcimg_inf').getElementsByTagName('a');
			for (cont = 0; cont < opc_img.length; ++cont)
			{
				document.getElementById(opc_img[cont].id).onmouseover = function()
				{
					if (document.getElementById(this.id+'_img'))
						document.getElementById(this.id+'_img').src = document.getElementById(this.id+'_img').src.replace('Off.','On.');
				}
				document.getElementById(opc_img[cont].id).onmouseout = function()
				{
					if (document.getElementById(this.id+'_img'))
						document.getElementById(this.id+'_img').src = document.getElementById(this.id+'_img').src.replace('On.','Off.');
				}
				document.getElementById(opc_img[cont].id).onclick = function()
				{
					VISITA.poneracero();
					if (document.getElementById('imagen_inicio_histo'))
						document.getElementById('imagen_inicio_histo').className = 'dnone';
					if (document.getElementById('txt_vis0'))
						document.getElementById('txt_vis0').className = 'dnone';
					document.getElementById(this.id.replace('op_','txt_')).className = 'dblock';
					document.getElementById(this.id+'_img').src = document.getElementById(this.id+'_img').src.replace('Off.','On.');
					document.getElementById(this.id+'_img').id = 'active';
					document.getElementById(this.id.replace('op_','lnk_')).className = 'dblock';
					VISITA.cargarEnlaces(this.id);
					
					/*if (document.getElementById('opc_flechas'))
					{
						document.getElementById('opc_flechas').className = 'dblock';
						VISITA.cargarFlechas(this.id);
					}*/
					return false;					
				}
			}
		}
	},
	cargarFlechas : function(opcion)
	{
		var opc = document.getElementById(opcion.replace('op_','lnk_')).getElementsByTagName('a');		
		for (cont = 0; cont<opc.length; ++cont)
		{
			if (document.getElementById(opc[cont].id).className == 'active')
			{
				document.getElementById('flechaIzq').className = 'flecha_'+(opc[cont].id.replace('lnk_img_vis',''));
				document.getElementById('flechaDcha').className = opcion;
				document.getElementById('flechaIzq').onclick = function()
				{
					var selec = document.getElementById('flechaIzq').className.replace('flecha_','');
					--selec;
					selec = 'lnk_img_vis'+selec;
					VISITA.ocultarImg();
					VISITA.iniciarLnk();
					document.getElementById(selec).className = "active";
					document.getElementById(selec.replace('lnk_','')).className = 'dblock';
					VISITA.cargarFlechas(document.getElementById('flechaDcha').className);
					return false;					
				}
				document.getElementById('flechaDcha').onclick = function()
				{
					var selec = document.getElementById('flechaIzq').className.replace('flecha_','');
					++selec;
					selec = 'lnk_img_vis'+selec;
					VISITA.ocultarImg();
					VISITA.iniciarLnk();
					document.getElementById(selec).className = "active";
					document.getElementById(selec.replace('lnk_','')).className = 'dblock';
					VISITA.cargarFlechas(document.getElementById('flechaDcha').className);
					return false;		
				}
			}
		}
		
	},
	cargarEnlaces : function(opcion)
	{
		var opc = document.getElementById(opcion.replace('op_','lnk_')).getElementsByTagName('a');
		document.getElementById(opc[0].id).className = 'active';
		document.getElementById(opc[0].id.replace('lnk_','')).className = 'dblock';
		for (cont = 0; cont<opc.length; ++cont)
		{
			document.getElementById(opc[cont].id).onclick = function()
			{
				VISITA.ocultarImg();
				VISITA.iniciarLnk();
				document.getElementById(this.id).className = "active";
				document.getElementById(this.id.replace('lnk_','')).className = 'dblock';
				if (document.getElementById('opc_flechas'))
				{
					VISITA.cargarFlechas(opcion);
				}
				return false;
			}
		}
		
	},
	sacarCapa : function()
	{
		var salida = new Array();
		var op_capas = document.getElementById('capa_opclnk_inf').getElementsByTagName('div');
		for (var cont = 0; cont<op_capas.length; ++cont)
		{
			var op_lnk = document.getElementById(op_capas[cont].id).getElementsByTagName('a');
			for (var cont2 = 0; cont2<op_lnk.length; ++cont2)
			{
				if (document.getElementById(op_lnk[cont2].id).className = 'active')
				{
					salida[0] = op_capas[cont].id;
					salida[1] = op_lnk[cont2].id;
					return salida;
				}
			}			
		}
		
	},
	ocultarImg : function()
	{
		
		var op_lnk = document.getElementById('img_histo').getElementsByTagName('img');
		for (cont = 0; cont<op_lnk.length; ++cont)
		{
			document.getElementById(op_lnk[cont].id).className = 'dnone';
		}
		
	},
	iniciarLnk : function()
	{
		
		var op_lnk = document.getElementById('capa_opclnk_inf').getElementsByTagName('a');
		for (cont = 0; cont<op_lnk.length; ++cont)
		{
			document.getElementById(op_lnk[cont].id).className = "";// = 'lnk_img_vis'+parseInt(cont+1);
		}
		
	},
	poneracero : function()
	{
		VISITA.ocultarImg();
		VISITA.iniciarLnk();
		var op_img = document.getElementById('capa_opcimg_inf').getElementsByTagName('img');
		for (cont = 0; cont<op_img.length; ++cont)
		{
			document.getElementById(op_img[cont].id).src = document.getElementById(op_img[cont].id).src.replace('On.','Off.');
			document.getElementById(op_img[cont].id).id = 'op_vis'+parseInt(cont+1)+'_img';
		}
		
		var op_lnk = document.getElementById('capa_opclnk_inf').getElementsByTagName('div');
		for (cont = 0; cont<op_lnk.length; ++cont)
		{
			document.getElementById(op_lnk[cont].id).className = 'dnone';
		}
		
		var op_lnk = document.getElementById('cont_visita').getElementsByTagName('div');
		for (cont = 0; cont<op_lnk.length; ++cont)
		{
			document.getElementById(op_lnk[cont].id).className = 'dnone';
		}
	}
}


/* 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(); } );
