
	var oldNavWidth = 0, oldNavHeight = 0;
	var navWidth = 0, navHeight = 0;
	var stoUpdate = 0;
	var pasaFotos = null;
	
	var submenus= [];
	var urls = [];
	var seccionActual = null;
	var subseccionActual = null;
	var seccionHover = null;
	var stoSubmenu = 0;
	
	var seccionPrevia = "home";
	
	var tMenu = 300;//Esperas menú
	
	//Respositionamiento submenús
	var xMenu = 0;
	var xSubmenu = 0;
	var offsetSubmenu = 0;
	var oldOffsetSubmenu = 0;
	
	var spHeader = 93;
	var spFooter = 80;

	var isLoading = false;
	var modoZoom = false;
	var isZooming = false;
	var isContactPage = false;
	var wFotosPreContactPage = 0;

	var preloaders = [];
	var imagesToPreload = [];
	var imagesLoaded = 0;
	
	var wFotos = 0; //Valor inicial para el ancho de las fotos, pendiente de resize

	$(document).ready(function() {
		//Tengo que ocultar el menú estandar y remaquetarlo
		setHeader();
		if (document.location.hash != "") {
			//He entrado directamente a una subseccion
			destroyHome();
			animaEntrada(function(){;
				setCurrentSection(document.location.hash);
				setResize();
				setInterval("checkAnchor()", 300);
			});
		} else {
			if ($.browser.msie) {
				//$("#pasaFotos img").hide();
			} else {
				$("#pasaFotos").hide();
			}
			pasaFotos = new PasaFotos(this,"pasaFotos",spHeader,spFooter,"animaEntrada"); //capa, margen sup, margen inf
			preloadImages(pasaFotos.srcs);
			setInterval("checkAnchor()", 300);
		}
		$("#credits .contacto").wrap('<a href="#contacto" title="Contacto" />'); //Funcionalidad del formulario
		setResize();
	});
	
	function preloadImages(urls){
		imagesToPreload = urls;
		for (var i=0; i<imagesToPreload.length; i++) {
			preloaders[i] = new Image();
			if (preloaders[i].addEventListener) preloaders[i].addEventListener('load', function() { imagePreloaded(); }, false);
			else if (preloaders[i].attachEvent) preloaders[i].attachEvent('onload', function() { imagePreloaded(); });
			preloaders[i].src = imagesToPreload[i];
		}
	}
	
	function imagePreloaded(){
		imagesLoaded++;
		if (imagesLoaded == imagesToPreload.length) animaEntrada();
	}
	
	function animaEntrada(f){
		var t = 1000;
		$("#loading").stop(true,true).animate({opacity:0},t*2,function(){
			$("#loading").hide();
			$("#logo").stop(true,true).show().css({'opacity':'0'}).show().animate({opacity: 1},t);
			$("#menu").show().css({'opacity':'0'}).show().animate({opacity: 1},t);
			$("#submenu").show().css({'opacity':'0'}).show().animate({opacity: 1},t);
			$("#credits").show().css({'opacity':'0'}).show().animate({opacity: 1},t);
			$("#otrosLogos").show().css({'opacity':'0'}).show().animate({opacity: 1},t,function() { if (f) f(); });
			if (pasaFotos) {
				if ($.browser.msie) {
					$("#pasaFotos img").show();
					//$("#pasaFotos").css({'filter':'','opacity':'1','display':'block'});
				} else {
					$("#pasaFotos").stop(true,true).css({'opacity':'0'}).show().animate({opacity: 1},t);
				}
			}
		});
		
	}
	
	function setHeader(){
		//Inicializa el Header vía CSS y JS
		$("body").append('<div id="loading"><img src="img/loading2.gif" width="36" height="36" /></div>');
		$("#loading").css({'left': '50px','top': ( 50) + 'px'});
		$("#logo").hide().css({'position': 'absolute', 'z-Index': '90', 'top': '18px'});
		$("#menu").hide().css({'position': 'absolute', 'z-Index': '95', 'top': '30px'});
		$("#credits").hide();
		$("#otrosLogos").hide();
		//Cargo los submenús y los borro
		$("#menu .mainmenu").each(function(index){
			var aux = $(this).find(".submenu");
			$(this).data("indice",index);
			if (aux.html() != null) {
				var html = "";
				urls[index] = [];
				aux.find("a").each(function(indexSubmenu){
					urls[index][indexSubmenu] = $(this).attr('href');
					$(this).attr('href','javascript:navega('+index+','+indexSubmenu+')');
					if (indexSubmenu > 0) html += ', ';
					html += '<a href="javascript:navega('+index+','+indexSubmenu+')" title="' + $(this).attr('title') + '">' + $(this).text() + '</a>';
				});
				submenus[index] = html;
				//submenus[index] = aux.html();
				aux.remove();
				$(this).bind("mouseover", menuOver);
				$(this).bind("mouseout", function(){
					clearTimeout(stoSubmenu);
					var itemMenu = $(this);
					stoSubmenu = window.setTimeout(function(){ menuOut(itemMenu); }, 400);
				});
				//$(this).bind("click", function(){ navega($(this)); return false; });
				$(this).children("a").removeAttr('href');
				$(this).children("a").attr('onclick','return false');
			} else {
				var enlace = $(this).find("a");;
				urls[index] = enlace.attr("href");
				enlace.bind("click",function(){ navega(index,null); return false; });
			}
		});
		//chiva(urls);
		//Preparo un div para meter los menús
		$("body").append('<div id="submenu" class="menu"></div>');
		$("#submenu").hide();
		$("#submenu").bind("mouseover", function() { clearTimeout(stoSubmenu); });
		$("#submenu").bind("mouseout", function(){ stoSubmenu = window.setTimeout(function(){ menuOut(null); }, 400); });
		//Preparo los cursores de navegación de fotos
		$("body").append('<div id="izqGal"></div>');
		$("body").append('<div id="derGal"></div>');
		$("#izqGal")
			.hide()
			.bind('mouseover',function(){ $(this).stop().animate({ opacity: .5 },100); })
			.bind('mouseout',function(){ $(this).stop().animate({ opacity: 1 },100); })
			.click(function(){ fotosPost(-1); });
		$("#derGal")
			.hide()
			.bind('mouseover',function(){ $(this).stop().animate({ opacity: .5 },300); })
			.bind('mouseout',function(){ $(this).stop().animate({ opacity: 1 },300);})
			.click(function(){ fotosPost(1); });
	}
	
	function chiva(a){
		var html = "[";
		for (i = 0; i< a.length; i++){
			if (isArray(urls[i])) {
				html += "\n\t[";
				for (j = 0; j< a[i].length; j++){
					html += "\n\t\t\""+a[i][j]+"\"";
				}
				html += "\n\t],"
			} else html += "\"" + a[i] + "\",";
		}
		html += "\n]";
		alert(html);
	}
	
	function setCurrentSection(hash){
		hash = "seccion.php?s=" + hash.substring(1,hash.length);
		var encontrado = false,i=0,j=0;
		while (i<urls.length && !encontrado) {
			if (!encontrado && urls[i] === hash) {
				encontrado = true;
				j = null;
			} else {
				if (isArray(urls[i])) {
					j = 0;
					while (j<urls[i].length && !encontrado) {
						if (urls[i][j] == hash) {
							encontrado = true;
						} else j++;
					}
				}
				if (!encontrado) i++;
			}
		}
		if (encontrado) {
			seccionActual = i;
			$("#menu a").each(function(index){ 
				if (index == seccionActual) { 
					$(this).addClass("activa"); 
					offsetSubmenu = oldOffsetSubmenu = $(this).parent().position().left;
					$("#submenu").css({ left: (offsetSubmenu + xSubmenu) + "px" });
				}
			});
			subseccionActual = j;
			if (subseccionActual != null) {
				$("#submenu").html(submenus[seccionActual]);
				updateSubseccion(seccionActual);
			}
		}
	}
	
	function isArray(a) { return (a.constructor.toString().indexOf("Array") != -1); }
	
	function menuOver(){
		clearTimeout(stoSubmenu);
		var i = $(this).data("indice");
		if (seccionHover != i) {
			seccionHover = i;
			//oldOffsetSubmenu = offsetSubmenu;
			offsetSubmenu = $(this).position().left;
			$("#submenu").html(submenus[i]).css({ left: (offsetSubmenu + xSubmenu) + "px" });
			updateSubseccion(seccionHover);
		}
		$("#submenu").stop().animate({opacity: 1},tMenu);
	}
	
	function menuOut(itemMenu){
		seccionHover = null;
		if (seccionActual != null && submenus[seccionActual] != null){
			offsetSubmenu = oldOffsetSubmenu;
			$("#submenu").html(submenus[seccionActual]).css({ left: (offsetSubmenu + xSubmenu) + "px" });
			updateSubseccion(seccionActual);
		} else $("#submenu").stop().animate({opacity: 0},tMenu,function(){$("#submenu").html("");});
	}
	
	function navega(i,j) {
		if (seccionActual == null || seccionActual != i) {
			seccionActual = i;
			$("#menu a").removeClass("activa");
			$("#menu a").each(function(index){ 
				if (index == seccionActual) {
					//Lo marco como actual y actualizo marcas de submenu
					$(this).addClass("activa"); 
					offsetSubmenu = oldOffsetSubmenu = $(this).parent().position().left;
				}
			});
		}
		
		if (subseccionActual == null || subseccionActual != j) {
			seccionActual = i;
			subseccionActual = j;
			if (subseccionActual == null) $("#submenu").html("");
			else updateSubseccion(seccionActual);
		}

		$("#submenu").css({ left: (offsetSubmenu + xSubmenu) + "px" });
		
		var url = (((j==null) ? urls[i] : urls[i][j]).split("?s="))[1];
		document.location.href = "http://" + basePath + "#" + url;
	}
	
	function updateSubseccion(seccionPadre){
		$("#submenu a").removeClass("activa");
		if (seccionPadre == seccionActual) $("#submenu a").each(function(index){ if (index == subseccionActual) $(this).addClass("activa"); });
	}
	
	//EMULACIÓN DE NAVEGACIÓN
	var currentAnchor = null;
	function checkAnchor() {
		if (currentAnchor != document.location.hash) {
			currentAnchor = document.location.hash;
			if (!currentAnchor) {
				//No hago nada
				//if (postIsOpened) closePost();
			} else {
				//Calculo la URL
				//var url = basePath + "seccion.php?ajax=1&s=" + (currentAnchor.substring(1,currentAnchor.length));
				isLoading = true;
				clearTimeout(stoContentReady);				
				$("#derGal").hide();
				$("#izqGal").hide();
				$("#content").stop().animate({opacity: 0},function(){
					if (seccionPrevia == "home") { 
						pasaFotos = null;
						destroyHome();
					}
					var tagSeccion = (currentAnchor.substring(1,currentAnchor.length));
					if (tagSeccion == "contacto") {
						//Excepción para contacto: desmarco menús
						seccionActual = null;
						subseccionActual = null;
						seccionHover = null;
						offsetSubmenu = oldOffsetSubmenu = $(this).parent().position().left;
						$("#menu a").removeClass("activa");
						$("#submenu").html("");
						isContactPage = true;//Ñapa para repintar el iframe de google maps
						wFotosPreContactPage = 0;
					} else {
						isContactPage = false;
					}
					$.ajax({
							type: "POST",
							url: "seccion.php",
							data: "ajax=1&s=" + tagSeccion,
							success: function(data){
								$("#content").html(data);
								if (tagSeccion == "contacto") {
									//Asigno las funcionalidades de validación de formulario
									setContactForm();
								} else {
									//Todas las secciones menos "contacto" llevan fotos
									numFotosSeccion = $("#fotos .innerData").length;
									textoFotosSeccion = "";
									fotoPostActual = 0;
									if (numFotosSeccion > 0) {
										if (numFotosSeccion > 1) {
											$("#control").data("hControl",$("#control").height());
										} else {
											$("#control").remove();
										}
										var offsetX = Math.max(0,Math.round(navWidth*39/1280)) + wTexto + 40;
										var offsetY = Math.round(navWidth*20/1280) + spHeader + 10;
										//alert(offsetY);
										if (numFotosSeccion > 1) {
											offsetY += $("#control").data("hControl");
										}
										$("#loading").stop();
										//alert(wFotos);
										$("#loading").css({'left': (offsetX + 35) + 'px','top': (10 + offsetY) + 'px'}).show().css({'opacity': '1'});
										//$("#fotos img").stop().fadeOut(1);
										textoFotosSeccion = $("#otras").text();
										$("#otras").text(textoFotosSeccion + " (1/" + numFotosSeccion + ")")
										//alert(textoFotosSeccion);
										$("#izqMini").click(function(){ fotosPost(-1); });
										$("#derMini").click(function(){ fotosPost(1); });
										$("#fotos .innerData").each(function(index){
											//Tengo que comprobar si es un vídeo o una foto
											var innerDataImages = $(this).find("img");
											if (innerDataImages.length == 0) {
												//No hay imagen, es un vídeo
												$(this).hide();
												if (index == 0) {
													//Primer vídeo: oculto preloader y lo muestro
													showVideo($(this));
												} else {
													//Los demás los dejo ocultos
												}	
											} else {
												//Esto con las imágenes
												innerDataImages.click(function(){ if (!isZooming) zoomFoto($(this)); });
												if (index == 0) {
													preload(innerDataImages,true);
												}else{
													if ($.browser.msie) {
														//$(this).hide();
													} else {
														innerDataImages.hide();
														////$(this).stop().fadeOut(0);
													}
													innerDataImages.css({'opacity':'0'});
												}
											}
										});
									}
								}
								stoContentReady = setTimeout("contentReady()",100);
							}
						});
				 });
			}
		}
	}
	
	function showVideo(div) {
		$("#loading").stop(true,true).animate({opacity: 0},function(){
			$("#loading").hide();
			div.show();
		});
	}
	
	var preloadFoto;
	function preload(foto,ocultarPreloader){
		foto.hide();
		//delete(preloadFoto);foto.css('filter','');
		preloadFoto = new Image();
		if (preloadFoto.addEventListener) preloadFoto.addEventListener('load', function() { 
			if (ocultarPreloader) {
				$("#loading").stop(true,true).animate({opacity: 0},function(){
					$("#loading").hide();
					foto
						.stop(true)
						.css({'opacity':'0'})
						.show()
						.animate({opacity: 1},tFadeIn,function(){ foto.css('filter',''); }); 
				});
			}else{
				foto.stop(true).css({'opacity':'0'}).show().animate({opacity: 1},tFadeIn,function(){ foto.css('filter',''); }); 
			}
		}, false);
		else if (preloadFoto.attachEvent) preloadFoto.attachEvent('onload', function() { 
			if (ocultarPreloader) {
				$("#loading").animate({opacity: 0},function(){
					$("#loading").hide();
					foto.stop(true).show().animate({opacity: 1},tFadeIn,function(){ foto.css('filter',''); }); 
				});
			} else {
				foto.stop(true).show().animate({opacity: 1},tFadeIn,function(){ foto.css('filter',''); }); 
			}
		});
		preloadFoto.src = foto.attr('src');
	}
	
	function contentReady(){
		clearTimeout(stoContentReady);
		isLoading = false; 
		modoZoom = false;
		checkResize();
		//fotosPost(0);
		$("#content").stop().animate({opacity: 1});
	}
	
	var textoFotosSeccion = "";
	var numFotosSeccion = 0;
	var stoContentReady = 0;
	var fotoPostActual = 0;
	
	var tFadeOut = 400;
	var tFadeIn = 400;
	function fotosPost(d){
		var nextFotoPost = fotoPostActual + d;
		if (nextFotoPost < 0) nextFotoPost = numFotosSeccion - 1;
		else if (nextFotoPost >= numFotosSeccion) nextFotoPost = 0;
		var oldFotoPost = fotoPostActual;
		fotoPostActual = nextFotoPost;
		$("#otras").text(textoFotosSeccion + " (" + (fotoPostActual + 1) + "/" + numFotosSeccion + ")")
		var f = function() {
			//Aquí se muestra el actual
			$("#fotos .innerData").each(function(index){
				if (index === fotoPostActual) {
					$(this).show(); // Muestro el div
					var innerDataImages = $(this).find("img");
					if (innerDataImages.length == 0) {
						//Muestro el vídeo
						var o = $(this).find("object");
						if (o[0] != undefined) {
							var w = o[0].width;
							var h = o[0].height;
						} else {
							var e = $(this).find("embed");
							if (e[0] != undefined) {
								var w = e[0].width;
								var h = e[0].height;
							}
						}
						$("#fotos").css({'width': w+'px', 'height': h+'px'});
					} else {
						//Hago alfa de la foto
						var w = innerDataImages.data('w');
						var h = innerDataImages.data('h');
						$("#fotos").css({'width': w+'px', 'height': h+'px'});
						if ($.browser.msie) {
							innerDataImages.css('filter','').show();
						}
						preload(innerDataImages);
					}
				}
			});
		}
		if (d == 0) f();
		else {
			//Aquí se oculta el anterior
			$("#fotos .innerData").each(function(index){
				if (index === oldFotoPost && index !== fotoPostActual) {
					var innerDataImages = $(this).find("img");
					if (innerDataImages.length == 0) {
						//Oculto el vídeo
						$(this).hide();
						if ($.browser.msie) {
							//En explorer habrá que repintar el vídeo para que pare
							$(this).html($(this).html());
						}
						f(); 
					} else {
						//Oculto la vídeo
						if ($.browser.msie) {
							//$(this).stop().hide();
							//f();
							innerDataImages.stop().animate({opacity: 0},tFadeOut,function(){ 
								innerDataImages.stop().hide().css('filter',''); 
								innerDataImages.parent().hide();
								f(); 
							});
						} else {
							//$(this).stop().fadeOut(tFadeOut,f);
							innerDataImages.stop().animate({opacity: 0},tFadeOut,function(){ 
								innerDataImages.stop().hide(); 
								innerDataImages.parent().hide();
								f(); 
							});
						}
					}
				}
			});
		}
	}
	
	function destroyHome(){
		$("#content").html("");
		seccionPrevia = "noHome";
	}
	
	var stoFormulario = 0;
	function setContactForm(){
		clearTimeout(stoFormulario);
		//$(".formulario").fadeOut(1);
		$("#respuestaFormulario").fadeOut(1);
		$(".formulario .withDefaultText").each(function(index){
			$(this).data("defaultText",$(this).val());
			$(this).focus(function(){ 
				clearTimeout(stoFormulario);
				var defaultText = $(this).data("defaultText");
				if ($(this).val() == defaultText) {
					$(this).val("");
					$(this).css({ 'color': '#000000', 'border-color': '#cdcdcd' });
				}
			});
			$(this).blur(function(){
				var defaultText = $(this).data("defaultText");
				if ($(this).val() == "") {
					$(this).val(defaultText);
					$(this).css({ 'color': '#838383' });
				}
			});
		});
		$(".formulario").submit(function(){
			var valido = true;
			var rojo = "ce4b4b";
			var nombre = $("#nombre").val();
			var email = $("#email").val();
			var tfn = $("#tfn").val();
			var consulta = $("#consulta").val();
			if (!isString(nombre) || nombre == $("#nombre").data("defaultText")) {
				valido = false;
				$("#nombre").css({ 'border-color': '#'+rojo });
			}
			if (!isMail(email)) {
				valido = false;
				$("#email").css({ 'border-color': '#'+rojo });
			}
			if (!isTelephone(tfn)) {
				valido = false;
				$("#tfn").css({ 'border-color': '#'+rojo });
			}
			if (!isString(consulta) || consulta == $("#consulta").data("defaultText")) {
				valido = false;
				$("#consulta").css({ 'border-color': '#'+rojo });
			}
			if (valido) {
				var data = $(".formulario form").serialize();
				//alert(data);
				var respuesta = $.ajax({
								url: "contacto.php",
								type: "POST",
								data: data,
								async: false
							}).responseText;
				if (respuesta == "OK") {
					avisoFormulario("Tu mensaje se ha enviado correctamente. Gracias por contactar.",true);
					$("#nombre").val($("#nombre").data("defaultText"));
					$("#email").val($("#email").data("defaultText"));
					$("#tfn").val($("#tfn").data("defaultText"));
					$("#consulta").val($("#consulta").data("defaultText"));
				} else {
					avisoFormulario("¡Opps! No se ha podido enviar ["+respuesta+"]. Revisa los datos.",false);
				}
			} else { 
				avisoFormulario("Hay errores en el formulario. Por favor, revisa los campos indicados.",false);
			}
			return false;	
		});
	}
	
	function avisoFormulario(msg,ocultar){
		$("#respuestaFormulario").html(msg).fadeIn(400).delay(4000).fadeOut(400);
	}
	
	function setResize(){
		//Inicializa el resize
		checkResize();
		$(window).resize(function(){ 
			clearTimeout(stoUpdate);
			stoUpdate = window.setTimeout("checkResize(true)",150);
		});
	}
	
	var wTexto = 357;//Math.round(navWidth*357/1280);
	
	function checkResize(fromResizeEvent){
		clearTimeout(stoUpdate);
		if (!isLoading) {
			if (isZooming) {
				//Lo pongo en espera
				stoUpdate = window.setTimeout("checkResize()",300);
			} else {
				navWidth = $(window).width();
				navHeight = $(window).height();
				if (navWidth != oldNavWidth || navHeight != oldNavHeight) {
					xMenu = Math.round(navWidth*50/1280); //El 50 antes era 140
					$("#menu").css({'left': xMenu + 'px'});
					xSubmenu = Math.round(navWidth*65/1280);
					var leftLogo = navWidth - Math.round(navWidth*50/1280) - 108;
					var wSubmenu = leftLogo - xSubmenu - 10;					$("#logo").css({'left': leftLogo + 'px'});
					//$("#submenu").css({'left': (xSubmenu + offsetSubmenu) + 'px', 'width': wSubmenu + 'px'});
					$("#submenu").css({'left': (xSubmenu + offsetSubmenu) + 'px'});
					$("#credits").css({'left': Math.round(navWidth*70/1280) + 'px'});
					$("#otrosLogos").css({'padding-right': Math.round(navWidth*50/1280) + 'px'});
					if (pasaFotos) pasaFotos.resizePasaFotos(navWidth,navHeight);
					else {
						if (modoZoom) {
							var wFotoWide = Math.round(navWidth*985/1280);
							var margin_left = Math.round(((navWidth*1184/1280)-wFotoWide) / 2);
							$("#derecha").css({ 'margin-left': margin_left+'px' });
							if (numFotosSeccion > 0) resizeSeccionImgs(wFotoWide);
							var wContent = Math.round(navWidth*1184/1280);
							var xContent = Math.max(0,Math.floor((navWidth-wContent)/2));
							$("#content").css({ 'margin-left': xContent + 'px' });
							//Y los botones
							var wBoton = 55;
							var yBotones = Math.round((navHeight - 75) / 2);
							var xBoton1 = margin_left + xContent - wBoton;
							var xBoton2 = margin_left + wFotoWide + xContent;
							$("#izqGal").css({ 'left': xBoton1 + 'px', 'top': yBotones });
							$("#derGal").css({ 'left': xBoton2 + 'px', 'top': yBotones });
						} else {
							var wContent = Math.max(wTexto,Math.round(navWidth*1184/1280));
							var marginDer = Math.max(0,Math.round(navWidth*39/1280));
							var xContent = Math.max(0,Math.floor((navWidth-wContent)/2));
							wFotos = Math.max(0,wContent-wTexto-marginDer);
							var margenSup = Math.round(navWidth*20/1280);
							var margenInf = Math.round(navWidth*33/1280);
							$("#derecha").css({ 'width': wFotos + 'px','margin-left': marginDer + 'px', 'padding': margenSup + 'px 0 ' + margenInf + 'px' });
							$("#texto").css({ 'width': wTexto + 'px','padding': margenSup + 'px 0 ' + margenInf + 'px' });
							$("#content").css({ 'margin-left': xContent + 'px' });
							if (isContactPage && wFotosPreContactPage != wFotos) {
								wFotosPreContactPage = wFotos; //Con esto evito dobles escrituras del iframe
								var wGoogleMaps = wFotos - 4;
								var hGoogleMaps = Math.round(wGoogleMaps / 1.4);
								var gMaps = '<iframe width="'+wGoogleMaps+'" height="'+hGoogleMaps+'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.es/maps?f=q&amp;source=s_q&amp;hl=&amp;geocode=&amp;q=calle+ram%C3%B3n+y+cajal,+18.+deluz&amp;aq=&amp;sll=43.469156,-3.780692&amp;sspn=0.004905,0.009044&amp;g=calle+ram%C3%B3n+y+cajal,+18.+39005&amp;ie=UTF8&amp;ll=43.469156,-3.780692&amp;spn=0.004905,0.009044&amp;iwloc=lyrftr:starred_items:107444984924702483455:,9213740282538912891,43.469148,-3.780756&amp;output=embed"></iframe>';
								$("#derecha").html('<div id="gmaps">'+gMaps+'</div>');
							} else {
								//Sólo las que no son contacto tienen fotos
								if (numFotosSeccion > 0) resizeSeccionImgs(wFotos);
							}
						}
					}
					$("#content").css({
						'min-height': Math.round(navHeight - spHeader - spFooter) + 'px'
					});
					
					//oldNavWidth = navWidth;
					//oldNavHeight = navHeight;
				}
			}
		}
	}
	
	function resizeSeccionImgs(w){
		//Redimensiona todas las fotos y los vídeos
		$("#fotos .innerData").each(function(index){			 
			//Tengo que comprobar si es un vídeo o una foto
			var innerDataImages = $(this).find("img");
			if (innerDataImages.length == 0) {
				//No hay imagen, es un vídeo
				var h = Math.round(0.75 * w);
				var o = $(this).find("object");
				if (o[0] != undefined) {
					o[0].width = w;
					o[0].height = h;
				}
				var e = $(this).find("embed");
				if (e[0] != undefined) {
					e[0].width = w;
					e[0].height = h;
				}
			} else {
				if (innerDataImages.attr('width') != 0 && innerDataImages.attr('height') != 0) {
					//alert(innerDataImages.attr('height'));
					var ratio = innerDataImages.attr('width') / innerDataImages.attr('height');
					var h = Math.round(w / ratio);
					//alert("Disculpen, estamos haciendo unas pruebas de rendimiento:" + w + "," + h + "," + ratio);
					innerDataImages.data("w",w);
					innerDataImages.data("h",h);
					//$(this).attr({'width': w+'', 'height': h+''});
					innerDataImages.css({'width': w+'px', 'height': h+'px'});
				}
			}
			if (index == fotoPostActual) $("#fotos").css({'width': w+'px', 'height': h+'px'});
		});
	}
	
	function zoomFoto(foto){
		var time = 500;
		isZooming = true;
		var ratio = foto.attr('width') / foto.attr('height');
		if (modoZoom) {
			var wContent = Math.max(wTexto,Math.round(navWidth*1184/1280));
			var marginDer = Math.max(0,Math.round(navWidth*39/1280));
			var xContent = Math.max(0,Math.floor((navWidth-wContent)/2));
			wFotos = Math.max(0,wContent-wTexto-marginDer);
			var h = Math.round(wFotos / ratio);
			$("#fotos").animate({ width: wFotos, height: h },time);
			foto.animate({ width: wFotos, height: h },time);
			$("#derecha").animate({ marginLeft: marginDer,paddingTop: Math.round(navWidth*20/1280),paddingBottom: Math.round(navWidth*33/1280)},time);
			if (numFotosSeccion > 1) {
				$("#derGal").hide();
				$("#izqGal").hide();
				var hControl = $("#control").data("hControl");
				$("#control").animate({ height: hControl },time,function(){ $("#control").animate({ opacity: 1 }); });
			}
			$("#texto").show().animate({ width: wTexto },time,function(){ 
				$("#texto *").show(); 
				$("#texto").animate({ opacity: 1 });
				isZooming = false; 
				checkResize();
			});
		} else {
			var wFotoWide = Math.round(navWidth*985/1280);
			var h = Math.round(wFotoWide / ratio);
			var margin_left = Math.round(((navWidth*1184/1280)-wFotoWide) / 2);
			if (numFotosSeccion > 1) $("#control").stop().animate({opacity: 0 });
			$("#texto").stop().animate({opacity: 0 },function(){
				$("#texto *").hide();
				if (numFotosSeccion > 1) $("#control").animate({ height: 0 },time);
				$("#texto").animate({ width: 0 },time,function(){ $("#texto").hide(); });
				$("#derecha").stop().animate({ marginLeft: margin_left, paddingTop: 0, paddingBottom: 0 },time);
				$("#fotos").stop().animate({ width: wFotoWide, height: h },time);
				foto.stop().animate({ width: wFotoWide, height: h },time,function(){ 
					isZooming = false; 
					checkResize(); 
					if (numFotosSeccion > 1) {
						$("#izqGal").fadeIn(time);
						$("#derGal").fadeIn(time);
					}
				});
			});
		}
		modoZoom = !modoZoom;
	}
