var txt_seleccionado = '';
var op_seleccionada = '';
var img_seleccionada = '';

var PROCESO = {
	init : function()
	{		
		if (document.getElementById('flash_proc'))
		{
			var so = new SWFObject("../flash/anima_uvas.swf", "proceso_flash", "263", "263", "8", "#FFF");
			so.addParam("quality", "hight");
			so.addParam("wmode", "transparent");
			so.write("flash_proc");
		}
		
		var opc = document.getElementById('opc_proceso').getElementsByTagName('a');
		for (cont = 0; cont<opc.length; ++cont)
		{
			document.getElementById(opc[cont].id).onmouseover = function()
			{
				if (this.id != op_seleccionada)
					document.getElementById(this.id.replace('op_','img_')).src = document.getElementById(this.id.replace('op_','img_')).src.replace('_off','_on');
				PROCESO.ocultarTxtNegrita();
				document.getElementById(this.id.replace('op_','capa_txt_')).className = 'dblock';
			}
			
			document.getElementById(opc[cont].id).onmouseout = function()
			{
				if (this.id != op_seleccionada)
					document.getElementById(this.id.replace('op_','img_')).src = document.getElementById(this.id.replace('op_','img_')).src.replace('_on','_off');					
				PROCESO.ocultarTxtNegrita();
				if (txt_seleccionado != '')
					document.getElementById(txt_seleccionado).className = 'dblock';
			}
			
			document.getElementById(opc[cont].id).onclick = function()
			{
				if (document.getElementById('proceso_flash'))
				{
					document.getElementById('proceso_flash').className = 'dnone';
					document.getElementById('flash_proc').innerHTML = '<div id="capa_img_proceso1"><img id="img_proceso1_1" class="dnone" src="../img/ciclo_vital/imagen_proceso_vendimia_01.jpg" /><img id="img_proceso1_2" class="dnone" src="../img/ciclo_vital/imagen_proceso_vendimia_02.jpg" /><img id="img_proceso1_3" class="dnone" src="../img/ciclo_vital/imagen_proceso_vendimia_03.jpg" /></div><div id="capa_img_proceso2"><img id="img_proceso2_1" class="dnone" src="../img/ciclo_vital/imagen_proceso_fermen_01.jpg" /><img id="img_proceso2_2" class="dnone" src="../img/ciclo_vital/imagen_proceso_fermen_02.jpg" /><img id="img_proceso2_3" class="dnone" src="../img/ciclo_vital/imagen_proceso_fermen_03.jpg" /></div><div id="capa_img_proceso3"><img id="img_proceso3_1" class="dnone" src="../img/ciclo_vital/imagen_proceso_barrica_01.jpg" /><img id="img_proceso3_2" class="dnone" src="../img/ciclo_vital/imagen_proceso_barrica_02.jpg" /></div><div id="capa_img_proceso4"><img id="img_proceso4_1" class="dnone" src="../img/ciclo_vital/imagen_proceso_embote_01.jpg" /><img id="img_proceso4_2" class="dnone" src="../img/ciclo_vital/imagen_proceso_embote_02.jpg" /></div><div id="capa_img_proceso5"><img id="img_proceso5_1" class="dnone" src="../img/ciclo_vital/imagen_proceso_botella_01.jpg" /><img id="img_proceso5_2" class="dnone" src="../img/ciclo_vital/imagen_proceso_botella_02.jpg" /></div>';
				}
				
				/* CIRCULOS */
				op_seleccionada = this.id;
				PROCESO.inicializarCirculos();
				document.getElementById(this.id.replace('op_','img_')).src = document.getElementById(this.id.replace('op_','img_')).src.replace('_off','_on');
																		
				/* TEXTO */																		 
				txt_seleccionado = this.id.replace('op_','capa_txt_');
				PROCESO.ocultarCapas();
				document.getElementById(this.id.replace('op_','capa_')).className = 'dblock';
				
				/* IMAGENES*/
				var primera = document.getElementById(this.id.replace('op_','capa_img_')).getElementsByTagName('img');
				img_seleccionada = this.id.replace('op_','img_')+'_1';
				PROCESO.ocultarImagenes();
				document.getElementById(primera[0].id).className = 'dblock';
				
				/* FLECHAS */
				document.getElementById('flechas_proc').className = 'dblock';
				document.getElementById('flecha_sig').className = 'visible';
				document.getElementById('flecha_ant').className = 'novisible';
				PROCESO.inicializarFlechas();
				
				return false;				
			}
		}
	},
	inicializarFlechas : function()
	{
		document.getElementById('flecha_ant').onclick = function()
		{
			var op_sig = img_seleccionada.substring(img_seleccionada.lastIndexOf('_')+1,img_seleccionada.length);
			var sec = img_seleccionada.substring(img_seleccionada.lastIndexOf('_')-1,img_seleccionada.lastIndexOf('_'));
			document.getElementById('img_proceso'+sec+'_'+(--op_sig)).className = 'dblock';			
			document.getElementById(img_seleccionada).className = 'dnone';	
			img_seleccionada = 'img_proceso'+sec+'_'+(op_sig);
			PROCESO.pintarFlechas();
			return false;	
		}
		document.getElementById('flecha_ant').onmouseover = function()
		{
			document.getElementById('img_'+this.id).src = document.getElementById('img_'+this.id).src.replace('_off','_on');
		}
		document.getElementById('flecha_ant').onmouseout = function()
		{
			document.getElementById('img_'+this.id).src = document.getElementById('img_'+this.id).src.replace('_on','_off');			
		}
		
		document.getElementById('flecha_sig').onclick = function()
		{
			var op_sig = img_seleccionada.substring(img_seleccionada.lastIndexOf('_')+1,img_seleccionada.length);
			var sec = img_seleccionada.substring(img_seleccionada.lastIndexOf('_')-1,img_seleccionada.lastIndexOf('_'));
			document.getElementById('img_proceso'+sec+'_'+(++op_sig)).className = 'dblock';			
			document.getElementById(img_seleccionada).className = 'dnone';	
			img_seleccionada = 'img_proceso'+sec+'_'+(op_sig);
			PROCESO.pintarFlechas();
			return false;
		}
		document.getElementById('flecha_sig').onmouseover = function()
		{
			document.getElementById('img_'+this.id).src = document.getElementById('img_'+this.id).src.replace('_off','_on');			
		}
		document.getElementById('flecha_sig').onmouseout = function()
		{
			document.getElementById('img_'+this.id).src = document.getElementById('img_'+this.id).src.replace('_on','_off');
			
		}
	},
	pintarFlechas : function()
	{
			var op_sig = img_seleccionada.substring(img_seleccionada.lastIndexOf('_')+1,img_seleccionada.length);
			var sec = img_seleccionada.substring(img_seleccionada.lastIndexOf('_')-1,img_seleccionada.lastIndexOf('_'));
			if (!document.getElementById('img_proceso'+sec+'_'+(parseInt(op_sig)+1)))
				document.getElementById('flecha_sig').className = 'novisible';
			else
				document.getElementById('flecha_sig').className = 'visible';
			if (!document.getElementById('img_proceso'+sec+'_'+(parseInt(op_sig)-1)))
				document.getElementById('flecha_ant').className = 'novisible';
			else
				document.getElementById('flecha_ant').className = 'visible';
	},
	ocultarCapas : function()
	{
		
		var opc = document.getElementById('contenidohisto').getElementsByTagName('div');
		for (cont = 0; cont<opc.length; ++cont)
		{
			document.getElementById(opc[cont].id).className = 'dnone';
		}
		
	},
	ocultarTxtNegrita : function()
	{
		var opc = document.getElementById('txt_proceso').getElementsByTagName('div');
		for (cont = 0; cont<opc.length; ++cont)
		{
			document.getElementById(opc[cont].id).className = 'dnone';
		}		
	},
	inicializarCirculos : function()
	{
		var opc = document.getElementById('opc_proceso').getElementsByTagName('img');
		for (cont = 0; cont<opc.length; ++cont)
		{
			document.getElementById(opc[cont].id).src = document.getElementById(opc[cont].id).src.replace('_on','_off');
		}		
	},
	ocultarImagenes : function()
	{
		var opc = document.getElementById('flash_proc').getElementsByTagName('img');
		for (cont = 0; cont<opc.length; ++cont)
		{
			document.getElementById(opc[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() { PROCESO.init(); } );