
var APIS = {
	init : function ()
	{		
		var so = new FlashObject("http://www.apis.es/flash/cabecera.swf ", "Apis", "100%", "200", "version8", null);
		so.addVariable("lang", "es");
		so.addParam("menu", "false");
		so.addParam("wmode", "transparent");
		so.write("cabecera");
		
		$('a[rel="external"]').attr('target', '_blank');
		
		/*
		//Asignamos a todos los links cuyo "rel" sea "external", el "target='_Blank'"
		
		var enlaces = document.getElementsByTagName('a');	
		
		for(var i = 0; i < enlaces.length; ++i)	
			if(enlaces[i].rel == 'external')
				document.getElementsByTagName('a')[i].target = '_blank';	

		//Fin -> convertir "<a rel='external'>" a "<a target='_Blank'>"
		*/
		
		PIE.init();
		if (document.getElementById('formularioContacto') != null)
		{
			CONTACTO.init();
		}
		if (document.getElementById('contenidoRecetas') != null)
		{
			RECETAS.init();
		}
		if (document.getElementById('contenidoComunicacion') != null)
		{
			COMUNICACION.init();
		}
		if (document.getElementById('capaMenuApis') != null)
		{
			var rutaUrl = document.location.href;
			if (rutaUrl.indexOf('Apis')>0)
			{				
				document.getElementById('capaMenuApis').style.display = 'block';
				document.getElementById('capaMenuFruco').style.display = 'none';
			}			
			
			if (rutaUrl.indexOf('Fruco')>0)
			{				
				document.getElementById('capaMenuApis').style.display = 'none';
				document.getElementById('capaMenuFruco').style.display = 'block';
			}
			
			document.getElementById('apismi').onclick = function()
			{
				document.getElementById('capaMenuApis').style.display = 'block';
				document.getElementById('capaMenuFruco').style.display = 'none';
				return false;
			}
			document.getElementById('frucomi').onclick = function()
			{
				document.getElementById('capaMenuApis').style.display = 'none';
				document.getElementById('capaMenuFruco').style.display = 'block';
				return false;
			}
		}
		if (document.getElementById('controlCalidad') != null)
		{
			document.getElementById('controlCalidad').onclick = function()
			{
				if (document.getElementById('capacontrolCalidad').style.display == 'block')
				{	
					document.getElementById('capacontrolCalidad').style.display = 'none';
				}
				else
				{
					document.getElementById('capacontrolCalidad').style.display = 'block';
				}
				return false;
				
			}
			document.getElementById('tecnologiapunta').onclick = function()
			{
				if (document.getElementById('capatecnologiapunta').style.display == 'block')
				{	
					document.getElementById('capatecnologiapunta').style.display = 'none';
				}
				else
				{
					document.getElementById('capatecnologiapunta').style.display = 'block';
				}
				return false;
				
			}
		}
		if (document.getElementById('capaFlashEmpresa') != null)
		{
			var so2 = new FlashObject("../flash/empresa1.swf ", "Apis", "100%", "239", "version8", null);
			so2.addVariable("lang", "es");
			so2.addParam("menu", "false");
			so2.addParam("wmode", "transparent");
			so2.write("capaFlashEmpresa");
		}
		if (document.getElementById('capaFlashFabrica') != null)
		{
			var so2 = new FlashObject("../flash/empresa2.swf ", "Apis", "100%", "500", "version8", null);
			so2.addVariable("lang", "es");
			so2.addParam("menu", "false");
			so2.addParam("wmode", "transparent");
			so2.write("capaFlashFabrica");
		}
	}
}

var PIE = {
	init : function()
	{
		var logos_pie = document.getElementById('pie').getElementsByTagName('img');
		for (var lm=0; lm<logos_pie.length; ++lm){
			if (logos_pie[lm].id!='off'){
				logos_pie[lm].onmouseover = function()
				{
					document.getElementById(this.id).src = 'http://www.apis.es/img/footer/'+this.id+'_over.gif';	
				}
				logos_pie[lm].onmouseout = function()
				{
					document.getElementById(this.id).src = src = 'http://www.apis.es/img/footer/'+this.id+'.gif';	
				}
			}
		}
	}
}

var CONTACTO = {
	init : function()
	{
		var objselec = document.getElementById('cmbDestinatario');
		objselec.onchange = function()
		{
			if (objselec.selectedIndex=='0')
			{
				document.getElementById('cv').style.visibility = 'visible';
			}
			else
			{
				document.getElementById('cv').style.visibility = 'hidden';
			}
		}
	}
}

var RECETAS = {
	init : function()
	{
		var objmenuPrincipal = document.getElementById('menuInterior').getElementsByTagName('div');
		var nombreEnlace = new Array();
		for (var cont = 0; cont <objmenuPrincipal.length; ++cont)
		{
			nombreEnlace[cont] = objmenuPrincipal[cont].id.substring(4,objmenuPrincipal[cont].id.length);
		}
		
		for (var cont = 0; cont<nombreEnlace.length; ++cont)
		{
			document.getElementById(nombreEnlace[cont]).onclick = function()
			{
				var objmenuPrincipal = document.getElementById('menuInterior').getElementsByTagName('div');
				for (var cont = 0; cont<objmenuPrincipal.length; ++cont)
				{
					document.getElementById(objmenuPrincipal[cont].id).style.display = 'none';
				}
				document.getElementById('capa'+this.id).style.display = 'block';
				return false;
			}
		}
		
		var objmenuRecetas = new Array();
		for (var cont = 0; cont <objmenuPrincipal.length; ++cont)
		{
			var objmenu = document.getElementById(objmenuPrincipal[cont].id).getElementsByTagName('a');
			for (var cont2 = 0; cont2 < objmenu.length; ++cont2)
			{
				objmenuRecetas.push(objmenu[cont2]);
			}			
		}
		
		for (var cont = 0; cont <objmenuRecetas.length; ++cont)
		{
			objmenuRecetas[cont].onclick = function()
			{
				RECETAS.todosNoOn();
				var objImg = document.getElementById(this.id).getElementsByTagName('img');
				objImg[0].src = 'http://www.apis.es/img/menuInterior/' + objImg[0].id + '_on.gif';
				RECETAS.ocultarTodas();
				RECETAS.mostrarCapa(objImg[0].id);
				return false;
			}
		}
	},
	todosNoOn : function()
	{
		var objmenuPrincipal = document.getElementById('menuInterior').getElementsByTagName('div');
		var objmenuRecetas = new Array();
		for (var cont = 0; cont <objmenuPrincipal.length; ++cont)
		{
			var objmenu = document.getElementById(objmenuPrincipal[cont].id).getElementsByTagName('a');
			for (var cont2 = 0; cont2 < objmenu.length; ++cont2)
			{
				objmenuRecetas.push(objmenu[cont2]);
			}			
		}
		for (var cont = 0; cont <objmenuRecetas.length; ++cont)
		{			
			var objImg = document.getElementById(objmenuRecetas[cont].id).getElementsByTagName('img');
			objImg[0].src = 'http://www.apis.es/img/menuInterior/' + objImg[0].id + '.gif';
		}
	},
	mostrarCapa : function (capa)
	{
		document.getElementById('capa_'+capa).style.display = 'block';
	},
	ocultarTodas : function ()
	{
		var objmenuPrincipal = document.getElementById('menuInterior').getElementsByTagName('div');
		var objmenuRecetas = new Array();	
		document.getElementById('capaIntroduccion').style.display = 'none';
		for (var cont = 0; cont <objmenuPrincipal.length; ++cont)
		{
			var objmenu = document.getElementById(objmenuPrincipal[cont].id).getElementsByTagName('a');
			for (var cont2 = 0; cont2 < objmenu.length; ++cont2)
			{
				objmenuRecetas.push(objmenu[cont2]);
			}			
		}
		for (var cont = 0; cont <objmenuRecetas.length; ++cont)
		{
			var objCapa = document.getElementById(objmenuRecetas[cont].id).getElementsByTagName('img');
			document.getElementById('capa_'+objCapa[0].id).style.display = 'none';
		}
		
	}
}

var COMUNICACION = {
	init : function()
	{
		var swVideos = false;		
		COMUNICACION.enlacesPaginador();
		if(document.getElementById('spottv'))
		{
			var objSpot = document.getElementById('spottv');
			objSpot.onclick = function()
			{
				/*
				document.getElementById('imgspottv').src='http://www.apis.es/img/menuInterior/spottv_on.gif';
				document.getElementById('imganuncioprensa').src='http://www.apis.es/img/menuInterior/anuncioprensa.gif';*/
				document.getElementById('capaspottv').style.display = 'block';
				document.getElementById('paginador').style.display = 'block';
				document.getElementById('capaanuncio').style.display = 'none';
				document.getElementById('contenidoComunicacion').style.backgroundImage='url(http://www.apis.es/img/fondospot.jpg)';								
				return false;
			}
			
			
			swVideos = true;
		}//fin if
		
		if(document.getElementById('anuncioPrensa'))
		{
			var objSpot = document.getElementById('anuncioPrensa');
			objSpot.onclick = function()
			{				
				/*document.getElementById('imgspottv').src='http://www.apis.es/img/menuInterior/spottv.gif';
				document.getElementById('imganuncioprensa').src='http://www.apis.es/img/menuInterior/anuncioprensa_on.gif';*/
				document.getElementById('capaspottv').style.display = 'none';
				document.getElementById('paginador').style.display = 'none';
				document.getElementById('capaanuncio').style.display = 'block';								
				document.getElementById('contenidoComunicacion').style.backgroundImage='url(http://www.apis.es/img/fondoprensa.jpg)';
				return false;
			}
			
			swVideos = true;
		}//fin if
		
		if(swVideos)
		{
			var objEnlacesVideos = document.getElementById('capaspottv').getElementsByTagName('a');
			
			/* Primer video */
			COMUNICACION.cambiarColor(objEnlacesVideos[0].id);
			var so = new FlashObject("http://www.apis.es/videos/video.swf", "Apis", "100%", "100%", "version8", null);
					so.addVariable("lang", "es");
					so.addVariable("video_id", objEnlacesVideos[0].href);
					so.addParam("menu", "false");					
					so.addParam("wmode", "transparent");
					so.write("capaComunicacion");
			
			/* para el resto de videos */			
			
			COMUNICACION.cargarEnlacesFlash();
			
		}//fin if
		
		var objEnlacesImagenes = document.getElementById('capaanuncio').getElementsByTagName('a');
			
			
		for (var cont = 0; cont < objEnlacesImagenes.length; ++cont)
		{
			objEnlacesImagenes[cont].onclick = function()
			{
				COMUNICACION.cambiarColor(this.id);
				document.getElementById('capaComunicacion').innerHTML = '<a href="' + this.href + '" target="_blank"><img id="anuncio" src="' + this.href + '" alt="Anuncio de prensa" /></a>';
				return false;
			}
		}	
	},
	
	cargarEnlacesFlash : function()
	{
		var objEnlacesVideos = document.getElementById('capaspottv').getElementsByTagName('a');
		
		for (var cont = 0; cont < objEnlacesVideos.length; ++cont)
			{
				
				objEnlacesVideos[cont].onclick = function()
				{
					COMUNICACION.cambiarColor(this.id);
					var so = new FlashObject("http://www.apis.es/videos/video.swf", "Apis", "100%", "100%", "version8", null);
					so.addVariable("lang", "es");
					so.addVariable("video_id", this.href);
					so.addParam("menu", "false");					
					so.addParam("wmode", "transparent");
					so.write("capaComunicacion");
					return false;
				}
			}
	},
	
	enlacesPaginador : function()
	{
		
		var objEnlacesPaginador = document.getElementById('paginador').getElementsByTagName('a');
		
		for (var cont = 0; cont < objEnlacesPaginador.length; ++cont)
		{
			objEnlacesPaginador[cont].onclick = function()
			{
				OBJAJAX.init(this.title);
				return false;
			}
		}	
		
	},
	cambiarColor : function (id)
	{
		var objLnkVideo = document.getElementById('capaspottv').getElementsByTagName('a');
		
		for (var cont = 0; cont < objLnkVideo.length; ++cont)
		{
			document.getElementById('i'+objLnkVideo[cont].id).style.visibility = 'hidden';
			document.getElementById(objLnkVideo[cont].id).style.color = '#777';
		}
		
		var objLnkAnun = document.getElementById('capaanuncio').getElementsByTagName('a');
		
		for (var cont = 0; cont < objLnkAnun.length; ++cont)
		{
			document.getElementById('i'+objLnkAnun[cont].id).style.visibility = 'hidden';
			document.getElementById(objLnkAnun[cont].id).style.color = '#777';
		}
		
		document.getElementById(id).style.color = '#464646';
		document.getElementById('i'+id).style.visibility = 'visible';
		
	}
}

var OBJAJAX = {
	init : function (numVideo)
	{
		var xdata = Array(numVideo, '../includes/processor.php');
		AJAX_DATA.ajax_getData(xdata);
		return false;		
	}
	
}



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

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