var VISITA = {
	init : function()
	{
		if (document.getElementById('opciones_visita'))
		{
			var opc = document.getElementById('opciones_visita').getElementsByTagName('a');
			for (cont = 0; cont<opc.length; ++cont)
			{
				document.getElementById(opc[cont].id).onmouseover = function()
				{
					if (this.id != 'active')
					document.getElementById(this.id.replace('op_','img_')).src = document.getElementById(this.id.replace('op_','img_')).src.replace('_off','_on');
				}
				document.getElementById(opc[cont].id).onmouseout = function()
				{
					if (this.id != 'active')
					document.getElementById(this.id.replace('op_','img_')).src = document.getElementById(this.id.replace('op_','img_')).src.replace('_on','_off');						
				}
				document.getElementById(opc[cont].id).onclick = function()
				{
					if (this.id != 'active')
					{
						VISITA.poneracero();
						document.getElementById(this.id.replace('op_','img_')).src = document.getElementById(this.id.replace('op_','img_')).src.replace('_off','_on');
						document.getElementById(this.id.replace('op_','capa_')).className = 'dblock';
						document.getElementById(this.id.replace('op_','capalnk_')).className = 'dblock';
						var links = document.getElementById(this.id.replace('op_','capalnk_')).getElementsByTagName('a');
						VISITA.iniciarLinks();
						document.getElementById('img_'+links[0].id).className = 'dblock';
						document.getElementById(links[0].id).id = 'lnksel';
						document.getElementById(this.id).id = 'active';
					}
					return false;						
				}
			}
		}
		if (document.getElementById('links_opciones_visita'))
		{
			var opc = document.getElementById('links_opciones_visita').getElementsByTagName('a');
			for (cont = 0; cont<opc.length; ++cont)
			{
				document.getElementById(opc[cont].id).onclick = function()
				{
					VISITA.ocultarImagenes();
					VISITA.iniciarLinks();
					document.getElementById('img_'+this.id).className = 'dblock';
					document.getElementById(this.id).id = 'lnksel';
				}
			}
			
		}
	},
	poneracero : function()
	{
		var opc = document.getElementById('contenidohisto').getElementsByTagName('div');
		for (cont = 0; cont<opc.length; ++cont)
		{
			document.getElementById(opc[cont].id).className = 'dnone';
		}
		var opc2 = document.getElementById('links_opciones_visita').getElementsByTagName('div');
		for (cont = 0; cont<opc2.length; ++cont)
		{
			document.getElementById(opc2[cont].id).className = 'dnone';
		}
		var opc3 = document.getElementById('opciones_visita').getElementsByTagName('a');
		for (cont = 0; cont<opc3.length; ++cont)
		{
			opc3[cont].id = 'op_visita'+parseInt(cont+1);
			document.getElementById(opc3[cont].id.replace('op_','img_')).src = document.getElementById(opc3[cont].id.replace('op_','img_')).src.replace('_on','_off');
		}
		VISITA.ocultarImagenes();
	},
	ocultarImagenes : function()
	{
		var opc = document.getElementById('img_fami').getElementsByTagName('img');
		for (cont = 0; cont<opc.length; ++cont)
		{
			document.getElementById(opc[cont].id).className = 'dnone';
		}		
	},
	iniciarLinks : function()
	{
		var opc = document.getElementById('links_opciones_visita').getElementsByTagName('a');
		for (cont = 0; cont<opc.length; ++cont)
		{
			document.getElementById(opc[cont].id).id = 	'op_visitavirutal'+parseInt(cont+1);
		}
	}
}


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